ECHILD
Linux / POSIXERRORCommonProcessHIGH confidence

No Child Processes

Production Risk

A double-wait bug or mis-tracked child PIDs can cause ECHILD in process supervisors, hiding crashed workers.

What this means

ECHILD (errno 10) is returned by wait(), waitpid(), and waitid() when the calling process has no children to wait for, or the specified child process does not exist.

Why it happens
  1. 1Calling wait() when the process has no child processes
  2. 2The child was already waited for and cleaned up (double-wait)
  3. 3SIGCHLD was set to SIG_IGN, causing child exit status to be discarded automatically
  4. 4Specifying a PID in waitpid() that is not a child of the current process
How to reproduce

Calling wait() after all children have already been reaped.

trigger — this will error
trigger — this will error
#include <sys/wait.h>
pid_t pid = fork();
if (pid == 0) { exit(0); }
waitpid(pid, NULL, 0);  // reaps the child
waitpid(pid, NULL, 0);  // ECHILD — already gone

expected output

waitpid: No child processes (ECHILD)

Fix 1

Track child PIDs and avoid double-waiting

WHEN When managing multiple child processes

Track child PIDs and avoid double-waiting
// Use a set/map of child PIDs
// Remove the PID when waitpid returns it
// Use waitpid(-1, ...) to reap any child

Why this works

Keep a data structure of live child PIDs. Remove each PID after successful waitpid. Never call wait on a PID that has already been reaped.

Fix 2

Use waitpid with WNOHANG to non-blockingly poll

WHEN When unsure if children are still running

Use waitpid with WNOHANG to non-blockingly poll
pid_t r = waitpid(-1, &status, WNOHANG);
if (r == -1 && errno == ECHILD) {
  // no children left
} else if (r == 0) {
  // children exist but none exited yet
}

Why this works

WNOHANG returns immediately. ECHILD means no children at all; 0 means children exist but are still running.

What not to do

Set SIGCHLD to SIG_IGN to avoid zombies without tracking exit codes

SIG_IGN discards all child exit statuses silently — you lose crash detection and cannot distinguish normal from abnormal child termination.

Sources
Official documentation ↗

Linux Programmer Manual waitpid(2)

wait(2)

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

← All Linux / POSIX errors