ps-tree1.2.0 • Public • Published
Sometimes you cannot kill child processes like you would expect, this a feature of UNIX.
in UNIX, a process may terminate by using the exit call, and it's parent process may wait for that event by using the wait system call. the wait system call returns the process identifier of a terminated child, so that the parent tell which of the possibly many children has terminated. If the parent terminates, however, all it's children have assigned as their new parent the init process. Thus, the children still have a parent to collect their status and execution statistics. (from "operating system concepts")
ps-tree to get all processes that a
child_process may have started, so that they may all be terminated.
var cp =psTree = ;var child = cp;// This will not actually kill the child it will kill the `sh` process.child;
wtf? it's because exec actually works like this:
sh starts parses the command string and starts processes, and waits for them to terminate, but
exec returns a process object with the pid of the
However, since it is in
wait mode killing it does not kill the children.
ps-tree like this:
var cp =psTree = ;var child = cp;;
If you prefer to run psTree from the command line, use:
Cross Platform support
ps-tree module behaves differently on *nix vs. Windows by spawning different programs and parsing their output. This is based on
process.platform and not on checking to see if a
ps compatible program exists on the system.
- " " need to be striped
$ ps -A -o comm,ppid,pid,statCOMMAND PPID PID STATbbsd 2899 16958 Sswatch <defunct> 1914 16964 Zps 20688 16965 R+
wmic PROCESS WHERE ParentProcessId=4604 GET Name,ParentProcessId,ProcessId,Status)
- The order of head columns is fixed
> wmic PROCESS GET Name,ProcessId,ParentProcessId,StatusName ParentProcessId ProcessId StatusSystem Idle Process 0 0System 0 4smss.exe 4 228