Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #22 #25

Merged
merged 6 commits into from
Jul 28, 2015
Merged

fix for #22 #25

merged 6 commits into from
Jul 28, 2015

Conversation

paulpflug
Copy link
Collaborator

works for me in linux

needs to be tested on unix and windows

works for me in linux

needs to be tested on unix and windows
@paulpflug paulpflug closed this Jul 2, 2015
@paulpflug paulpflug deleted the fix-for-#22 branch July 2, 2015 22:14
@paulpflug paulpflug restored the fix-for-#22 branch July 2, 2015 22:16
@paulpflug paulpflug reopened this Jul 2, 2015
@paulpflug
Copy link
Collaborator Author

sometimes I hate git >_<

@paulpflug
Copy link
Collaborator Author

I have now tested it on windows. Works as expected 😄

@andrenarchy
Copy link

Is there any reason why this can't be merged?

@keithamus
Copy link
Collaborator

I'm a little dubious to merge - it feels a bit like a side effect. I wanted to do some proper research on this before deciding on what to do - which I realise now has been nearly a month, so not very fair to @paulpflug.

The nodejs/node#2098 doesn't fill me with confidence about this patch. I'm not sure which way to go with it. Advice would be helpful 😄

@paulpflug
Copy link
Collaborator Author

I can fully understand that..

The underlying problem is, that sh decides to ignore kill orders and the node people say thats the way it is and should be ;)
So there are two options:

  1. Go away from sh
  2. Kill it with the process group ID (PGID) (which has to be obtained somehow)

@andrenarchy
Copy link

The problem is that sh (which is dash on my Ubuntu system!) spawns a new process for the provided command, so sh -c "node ..." results in the process hierarchy

+ parent
  + sh
    + node ...

Since dash (like bash) does not forward signals to children by default, the node process will still run after killing sh. The node process is reparented.

Note: if bash is used, the command replaces the current shell and the process hierarchy is

+parent
  + node ...

Then, killing the bash process will kill node.

So option 3 is: invoke processes with sh -c "exec node ..." instead of sh -c "node ...". Then, the sh process is replaced (see also here) and all kills should work as expected.

What do you think?

@paulpflug
Copy link
Collaborator Author

@andrenarchy that was very helpful, I implemented the exec way.. very clean, thank you 😄
@keithamus in my eyes it can be merged now

keithamus added a commit that referenced this pull request Jul 28, 2015
@keithamus keithamus merged commit c39d0f7 into darkguy2008:master Jul 28, 2015
@keithamus
Copy link
Collaborator

👍

@keithamus
Copy link
Collaborator

Glad we got to the bottom of this 😄

@paulpflug paulpflug deleted the fix-for-#22 branch July 28, 2015 10:19
@keithamus
Copy link
Collaborator

@paulpflug you've got push access on here, and pub access on npm now. Feel free to add improvements as you see fit, but please avoid committing directly to master (unless its a release commit) - keep stuff to PRs for visibility.

@paulpflug
Copy link
Collaborator Author

sounds reasonable 😄
thanks

@andrenarchy
Copy link

Unfortunately, using exec breaks chained commands. 😦

For example, running parallelshell "echo test1 && echo test2" only prints test1. The shell obviously is replaced with the first command.

@paulpflug
Copy link
Collaborator Author

We could catch && and handle it like parallelshell "echo test1" "echo test", what do you think?

@andrenarchy
Copy link

Probably not a good idea. You'd have to catch all kinds of shell commands (||, ;) and do variable substitution. In the end, you'd write a full shell. ;)

I'm also investigating if there's another way...

@estk
Copy link

estk commented Sep 19, 2015

Yeah this broke command chaining.
There is a workaround which I think re-breaks #22:
parallelshell "sh -c 'echo first && echo second'" "echo third"

@keithamus
Copy link
Collaborator

@estk could you try testing out #30 and see if the code in that PR works for your use cases?

estk pushed a commit to estk/parallelshell that referenced this pull request Sep 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants