GithubHelp home page GithubHelp logo

Comments (12)

keithamus avatar keithamus commented on August 17, 2024

Thanks for the issue @alicoding, it's definitely a bug; Ctrl+C should kill all three.

They should be registered as children of the process and my understanding of unix is that killing a parent kills all children. Maybe this assumption is wrong.

I guess the brute-force(ish) way to do this is listen for the TERM signal and manually dispatch it to all other processes. Maybe we should be generically doing this anyway (i.e. for any kill signal, like SIGHUP or SIGUSR*)?

from parallelshell.

jbuck avatar jbuck commented on August 17, 2024

I was digging into this with @alicoding and we found that the problem was actually when you have a parallelshell child process exit with non-zero status code. It doesn't kill the other parallelshell child processes. Here's an example with a dummy sleep script:

Jons-MacBook-Pro:nsleep jbuck$ ./node_modules/.bin/parallelshell "node index.js 1000 1" "node index.js 10000 0"
nsleep.pid = 13373, sleeping for 10000ms
nsleep.pid = 13372, sleeping for 1000ms
nsleep.pid = 13372, slept for 1000ms
`node index.js 1000 1` failed with exit code 1
Jons-MacBook-Pro:nsleep jbuck$ ps
  PID TTY           TIME CMD
13006 ttys003    0:00.06 -bash
13373 ttys003    0:00.08 node index.js 10000 0
Jons-MacBook-Pro:nsleep jbuck$ nsleep.pid = 13373, slept for 10000ms
ps
  PID TTY           TIME CMD
13006 ttys003    0:00.06 -bash
Jons-MacBook-Pro:nsleep jbuck$

I also thought that if the parent process dies the child processes die so I'm not sure why it's continuing to run in the background

from parallelshell.

jbuck avatar jbuck commented on August 17, 2024

Also, this exactly matches the behaviour of the & operator.

If you use the wait command, then you have to wait for all processes to exit before getting the terminal prompt which is more intuitive:

node index.js 1000 1 & node index.js 5000 0 & wait

from parallelshell.

jbuck avatar jbuck commented on August 17, 2024

Should parallelshell kill all child processes when one of them exits with a non-zero error code? Or atleast make sure the terminal prompt doesn't come up when one of them dies? I think it's more intuitive, but it is a different behaviour. Maybe put it behind some sort of a flag, -w/--wait so it kinda acts like the bash wait built-in?

from parallelshell.

keithamus avatar keithamus commented on August 17, 2024

The original design intention was for parallelshell to close all child processes every time if either one of the processes died, or you killed the parallelshell task. This is primarily because if you're killing it, or another process died - things have probably gotten messed up and you're going to re-run it all anyway. Most stuff behind parallelshell will either be build scripts or something like nodemon - so making it kill everything doesn't end the world, as you can get back to where you were by just re-running the command.

However, if you have a better idea (which it sounds like you do with -w) then I'd love to see a PR. I guess what I'd like to see is: default behaviour kills all processes on crash or kill, adding -w will wait until all processes finish or crash, ctrl+c kills all regardless of -w.

from parallelshell.

paulpflug avatar paulpflug commented on August 17, 2024

hey, I could build something, but if it comes to parsing args - you mind the use of commander or similar helpers?

from parallelshell.

keithamus avatar keithamus commented on August 17, 2024

I'd rather keep this to 0 dependencies, but if you absolutely need to - go for it.

from parallelshell.

anler avatar anler commented on August 17, 2024

Hi all, any plan on merging the fix? I need this! πŸ˜„

from parallelshell.

radekskrabal avatar radekskrabal commented on August 17, 2024

Hi guys, I love using parallelshell on Windows. I would really appreciate if you could merge the PR.

from parallelshell.

keithamus avatar keithamus commented on August 17, 2024

PR can be merged when notes are addressed. Feel free to take the contents of the PR and make the changes yourself, then submit a new PR.

from parallelshell.

chaines avatar chaines commented on August 17, 2024

It appears a pull request was merged to fix this issue, issue should be closed?

from parallelshell.

keithamus avatar keithamus commented on August 17, 2024

πŸ‘

from parallelshell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.