A cross-platform library of utilities for dealing with system processes.
npm install tinypsimport { killTree, getProcessTree } from 'tinyps';
// kill a process and everything it spawned
await killTree(child.pid);
// or inspect the tree first
const tree = await getProcessTree(child.pid);
console.log(tree.get(child.pid)); // [ 1234, 1235 ]pid(number) - process to kill, along with all of its descendantssignal(NodeJS.Signals, optional) - signal to send, defaults toSIGTERM- Returns
Promise<void>
Note that signal is not supported on Windows, and will be ignored.
pid(number) - process to build the tree from- Returns
Promise<ProcessTree>
pid(number) - process to check- Returns
boolean
A zombie process is still in the process table, so this returns true for a
process which has exited but has not yet been released by its parent.
pid(number) - process to collect descendants of- Returns
Promise<number[]>
- Returns
Promise<ProcessInfo[]>
pid(number) - process to look up- Returns
Promise<ProcessInfo | undefined>
name(string) - name to match againstoptions.loose(boolean, optional) - match any name containingname, ignoring case- Returns
Promise<ProcessInfo[]>
Names come from the process' argv[0], so a process which has renamed itself
(e.g. via process.title) matches its new name rather than its executable.
port(number) - local port to match againstoptions.protocol('tcp' | 'udp', optional) - only match sockets of this protocol, defaults to matching both- Returns
Promise<ProcessInfo[]>
Matches any process holding a socket bound to port locally, whether it is
listening or connected.
MIT