No Child Processes
Production Risk
A double-wait bug or mis-tracked child PIDs can cause ECHILD in process supervisors, hiding crashed workers.
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.
- 1Calling wait() when the process has no child processes
- 2The child was already waited for and cleaned up (double-wait)
- 3SIGCHLD was set to SIG_IGN, causing child exit status to be discarded automatically
- 4Specifying a PID in waitpid() that is not a child of the current process
Calling wait() after all children have already been reaped.
#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 goneexpected output
waitpid: No child processes (ECHILD)
Fix 1
Track child PIDs and avoid double-waiting
WHEN When managing multiple child processes
// 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
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.
✕ 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.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev