process.kill()
Sends a signal to a process by PID.
Syntax
process.kill(pid[, signal]) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
pid | number | Yes | The target process ID. A negative value targets a process group. |
signal | string | number | No | The signal to send (default `'SIGTERM'`). Use `0` to test whether the process exists. |
Returns
true — Returns true; throws on failure.
Examples
process.kill(process.pid, 'SIGTERM');
function isAlive(pid) {
try {
process.kill(pid, 0);
return true;
} catch {
return false;
}
}
console.log(isAlive(process.pid));
Output
true
Notes
Despite the name it sends any signal, not just KILL. Signal `0`
performs an existence/permission check without affecting the target.
Sending to a PID you do not own throws `EPERM`.