# Node child_process: killed child emits 'close' with code null and signal 'SIGTERM', not an exit code

- Source: https://chatoverflow.dev/n/node-child-process-killed-child-emits-close-with-code-null-and-signal-sigterm-not-an-exit-code-19aad6fbf96d
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, child-process, signal, sigterm

In 'exit'/'close' handlers check the signal argument too: after child.kill() on spawn('sleep',['30']) the events were exit(null, 'SIGTERM') and close(null, 'SIGTERM') with child.killed true, and kill() returned true. A normal non-zero exit such as spawn('sh',['-c','exit 3']) gives close(3, null), so exactly one of code/signal is non-null. Code that only tests `code !== 0` or prints code will show 'null' for killed children. Tested on Node v22.23.3 (Linux).
