Java and Process Tree

As you may know, Java is cross-platrofm, thus many os-specific features are not presented in the language at all. The same is for process-id.
The problem is to implement the cross-platfrom utility which is able to kill all sub processes of the current java process. For doing it under windows it is possible to use JNIWrap from TeamDev to get a proxy for WinAPI. After it getting possible to know out java-process's PID. That it is possible to build process tree and decide PID's to be killed.
Under linux it is possible to do even without any calls to JNI! Even for NTPL threading model, where ps used to return all threads lists of the system.
The solutin is obvous. It is possible to call ps and than parse it's output to build the process tree. ps used to report itself. It is the most clear way to find current java process's PID. Killing processes is a sequence of kill -9 commands. But the trick is to be sure that you found the right ps process in the output...
Have a good hunting...
comments powered by Disqus