Killing a java.lang.Process and its children
Posted on 2004-03-22
This is a general question about java.lang.Process and the semantics of java.lang.Process.destroy( ) - particularly under *nix (Solaris + Linux). Windows-related knowledge is also welcome but I am primarily concerned about the signals sent to the process when destroy( ) is called.
I have done a relatively quick google on the matter but could not find what the signal sent to the process is -- so I assume it's SIGTERM (and not SIGKILL). Is there a way to specify a signal that I want, or is this not in the standard Java distribution because this is platform-dependent? Anyone who could point answer this and point me to an "official" resource where this is described stands a good chance of getting the points :-)
However, for complete glory, I would also like to know how to kill (i.e. the equivalent of "kill -9" -- sending SIGKILL) a process spawned from a Java program _and_ all of its children. I am not sure whether sending SIGKILL also ensures that all the child processes will die too. I would like to avoid having to shell out to a script that would ps or pstree the situation, perform some awking and then kill -9 the children. Is there a way to kill the children, do I need to do it or does this happen automatically?