Skip to main content
ChildProcess.prototype.kill - node__child_process.d.ts - Node documentation
method ChildProcess.prototype.kill

Usage in Deno

```typescript import { ChildProcess } from "node:node__child_process.d.ts"; ```
ChildProcess.prototype.kill(signal?: Signals | number): boolean
The `subprocess.kill()` method sends a signal to the child process. If no argument is given, the process will be sent the `'SIGTERM'` signal. See [`signal(7)`](http://man7.org/linux/man-pages/man7/signal.7.html) for a list of available signals. This function returns `true` if [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) succeeds, and `false` otherwise. ```js import { spawn } from 'node:child_process'; const grep = spawn('grep', ['ssh']); grep.on('close', (code, signal) => { console.log( `child process terminated due to receipt of signal ${signal}`); }); // Send SIGHUP to process. grep.kill('SIGHUP'); ``` The `ChildProcess` object may emit an `'error'` event if the signal cannot be delivered. Sending a signal to a child process that has already exited is not an error but may have unforeseen consequences. Specifically, if the process identifier (PID) has been reassigned to another process, the signal will be delivered to that process instead which can have unexpected results. While the function is called `kill`, the signal delivered to the child process may not actually terminate the process. See [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) for reference. On Windows, where POSIX signals do not exist, the `signal` argument will be ignored, and the process will be killed forcefully and abruptly (similar to `'SIGKILL'`). See `Signal Events` for more details. On Linux, child processes of child processes will not be terminated when attempting to kill their parent. This is likely to happen when running a new process in a shell or with the use of the `shell` option of `ChildProcess`: ```js 'use strict'; import { spawn } from 'node:child_process'; const subprocess = spawn( 'sh', [ '-c', `node -e "setInterval(() => { console.log(process.pid, 'is alive') }, 500);"`, ], { stdio: ['inherit', 'inherit', 'inherit'], }, ); setTimeout(() => { subprocess.kill(); // Does not terminate the Node.js process in the shell. }, 2000); ```

Parameters

optional
signal: Signals | number

Return Type

boolean