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

Destroy all child process #78

Open
MasseGuillaume opened this issue Oct 11, 2017 · 4 comments
Open

Destroy all child process #78

MasseGuillaume opened this issue Oct 11, 2017 · 4 comments

Comments

@MasseGuillaume
Copy link

it would be useful to kill all child process. Similar to what pkill -9 -P <ppid> does.

@tpasternak
Copy link

On posix systems this would require to call setsid system call at the beginning of the process and to call kill with negative value during destroy. @brettwooldridge would you accept such a change if I tried to contribute?

https://man7.org/linux/man-pages/man2/setsid.2.html
https://man7.org/linux/man-pages/man2/kill.2.html

@tpasternak
Copy link

Of course both syscalls would be called optionally, probably controlled by some flag

@thraidh
Copy link

thraidh commented Dec 3, 2020

I looked into this, but unfortunately it seems to be near impossible to implement this in NuProcess.

setsid needs to be called between fork and exec, but that part is buried in Java_java_lang_UNIXProcess_forkAndExec, which is some C code in the JDK.

Therefore the best way to achieve that is to call the process by prefixing /usr/bin/setsid -w to the original command and kill it using LibC.kill(-process.getPid(), LibC.SIGTERM).

Unfortunately /usr/bin/setsid does not support -w on platforms like RHEL6 or earlier. For those it is probably easiest to create your own implementation in C or Rust.

@thraidh
Copy link

thraidh commented Dec 3, 2020

You can also write your own setsid.pl as

#!/usr/bin/perl
use POSIX;
POSIX::setsid();
exec @ARGV;

and run your command as /path/to/setsid.pl originalcommand originalargs. Then you don't need C or Rust, because Perl should be available on any POSIXy system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants