views:

98

answers:

1

Hi,

I need to execute and terminate/abort different shell scripts from inside Java (>= 1.5; ProcessBuilder). With the standard java mechanisms I am only able to kill the main process used for the shell script execution. When this shell script starts other processes (for instance ./foo.sh &; ./bar.sh &) then there processes are still running when I terminate/abort the main shell script process inside Java.

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

Thanks, Thomas

+1  A: 

If you have control of the different scripts, you can pass the PID of their children (use $! to find the PID of the last run background process) back to the main Java program. That seems like a fairly clean way of giving you what you need.

Otherwise, this seems rather promising.

hollaburoo