This library ends all child processes spawned by the current process, including nested child processes. The current process itself remains unaffected.
npm install --save end-child-processes
import { endChildProcesses } from "end-child-processes"
// spawn a long-running subprocess
import * as childProcess from "child_process"
childProcess.exec("node -e 'while (true) {}'")
// end all running subprocesses spawned by this program
await endChildProcesses()
On Windows, this library does not attempt to end the WMIC.exe
process since it
terminates on its own.
Dependent on your use case, these other libraries that might also be a good fit for you:
- ps-tree: displays information about all running subprocesses
- tree-kill: ends all processes in the process tree, including the current process
- @jub3i/tree-kill: ends all processes in the process tree, including the current process