Track id processes of child processes?

I need to execute and terminate / terminate various shell scripts from within Java (> = 1.5; ProcessBuilder). With standard java mechanisms, I can only kill the main process used to execute the shell script. When this shell script starts other processes (e.g.. / Foo.sh &; ./ bar.sh &), then the processes are still running when I terminate / terminate the main process of the shell script inside Java.

How can I keep track of all the IDs of all new child processes from Java? Is there any way to do this? Or is it possible (in * nix- and Win-OSes) to find all processes created by one known process?

Thank you Thomas

+3
source share
1 answer

If you have control over various scenarios, you can pass the PIDs of your children (use $ !, to find the PID of the last background process) back to the main Java program. This seems like a pretty clean way to give you what you need.

Otherwise, this seems pretty promising .

+1
source

Source: https://habr.com/ru/post/1724974/


All Articles