Child process

subprocess.kill()

Requests delivery of a signal to an owned child. A successful return is not confirmation of exit. Wait for lifecycle events; signal support differs by operating system. Tested on Node.js 22.16.0. Example output (one line per entry): ["true", "null SIGTERM"].

Formal Syntax & Structure

nodejs syntaxnodejs
subprocess.kill([signal])

Parameters & Attributes

NameTypeDescription
signalstring | numberSignal to send.

Return Value

boolean

Whether signal delivery succeeded.

Working Example

Example Snippetnodejs
import { spawn } from 'node:child_process';import { once } from 'node:events';const c = spawn(process.execPath, ['-e', 'setInterval(()=>{},1000)'], { env: {}, stdio: 'ignore' });const done = once(c, 'close');await once(c, 'spawn');console.log(c.kill('SIGTERM'));const [code, signal] = await done;console.log(code, signal);
Node.js Reference