ERR_PROCESS_ALREADY_EXITED
Node.jsERRORNotableProcessHIGH confidence

Child process has already exited

Production Risk

Low — track child process lifecycle state before attempting to kill.

What this means

Thrown when process.kill() or child.kill() is called on a process that has already exited. Since the process no longer exists, signals cannot be delivered to it.

Why it happens
  1. 1Calling process.kill(pid) with the PID of a process that has already terminated
  2. 2Sending a signal to a child process after its exit event has fired
  3. 3Race condition between exit detection and signal sending
How to reproduce

Triggered when kill() is called with the PID of a process that no longer exists.

trigger — this will error
trigger — this will error
const { spawn } = require('child_process');
const child = spawn('sleep', ['0.1']);
child.on('exit', () => {
  child.kill('SIGTERM'); // process already exited — throws
});

expected output

Error [ERR_PROCESS_ALREADY_EXITED]: Process has exited

Fix

Check process state before sending signals

WHEN When killing child processes in async contexts

Check process state before sending signals
let exited = false;
child.on('exit', () => { exited = true; });

function killIfRunning(signal = 'SIGTERM') {
  if (!exited) child.kill(signal);
}

Why this works

Tracking the exit state prevents kill() from being called after the process terminates.

Code examples
Triggerjs
const { spawn } = require('child_process');
const child = spawn('sleep', ['0.1']);
child.on('exit', () => {
  child.kill('SIGTERM'); // process already exited — throws
});  // this triggers ERR_PROCESS_ALREADY_EXITED
Handle in try/catchjs
try {
  // operation that may throw ERR_PROCESS_ALREADY_EXITED
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_PROCESS_ALREADY_EXITED') {
    console.error('ERR_PROCESS_ALREADY_EXITED:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_process_already_exited(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Send signals to child processes in their exit handlers

The process is already gone at that point; the signal cannot be delivered.

Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors