Kill ProcessTree in VM

Nov 10, 2010 at 7:54 AM


Currently I hit a problem that killing process in VM doesn't kill the child processes.

Immediate solution is enumerating processes and searching for parent PID. (Haven't tried yet)

But maybe there is more accurate alternative?

Thanks in advance!

Nov 10, 2010 at 12:27 PM

That's really not a capability of VMWare, nor it's actually a capability of the majority of operating systems. The first problem is that process A can create process B which, in turn, creates process C. If B terminates, there's no relationship remaining between A and C (at least as far as I know on Windows).

Windows addresses this concept with a Job Object which will track child processes. Then you can terminate the entire job, which will terminate all child processes.  Adding A to the job object causes B and C to be added to the same job object. B ends, then when the job object is terminated A and C are terminated together.

For *nix it seems to have been discussed on StackOverflow, but I suspect it suffers the same limitations.

You'll have to write a job object wrapper for Windows if you want to take advantage of this functionality and execute it in a regular command. In a past project we wrote JobObject.exe that acted as cmd.exe, created a new Job Object, added itself to it and launched child processes. Then we would terminate JobObject.exe (in our case on a Ctrl+C handler). That worked well.

Nov 10, 2010 at 4:06 PM

Thanks for clarification!