Multi-Process Containers and Why PID 1 Matters: Signal Handling and Zombie Reaping
Understand the critical role of PID 1 in Docker containers, including zombie process reaping, signal forwarding, and init helpers like tini and dumb-init.
Published on • November 17, 2026
AI Assistant

In Linux operating systems, Process ID 1 (PID 1) is the init process (systemd, sysvinit, or openrc). PID 1 holds two special kernel responsibilities: forwarding system signals to child processes and reaping orphaned child processes (zombies).
When running application runtimes (such as Node.js, Python, Java, or custom scripts) as PID 1 inside a Docker container, missing these init semantics can cause containers to hang on docker stop or leak kernel process table entries until the host runs out of PIDs.
1. The Two Special Kernel Rules for PID 1
The Linux kernel treats PID 1 differently from every other process on the system:
Rule 1: Signal Handling Exemption
For any normal process (PID > 1), if no custom signal handler is registered for SIGTERM or SIGINT, the kernel enforces the default action (immediate termination).
For PID 1, however, the kernel ignores default signal actions unless PID 1 explicitly registers a handler for that signal. If your Node.js or Python application runs as PID 1 without an explicit signal listener, running docker stop will send SIGTERM, which PID 1 ignores. Docker will wait 10 seconds before forcibly killing the container with SIGKILL.
docker stop (Sends SIGTERM)
|
v
+-------------------+
| Container PID 1 |
| (Node.js / Python)|
+-------------------+
|
[Ignores SIGTERM - No explicit handler!]
|
(10-second timeout expires)
|
v
docker stop (Sends SIGKILL) <-- Unclean Shutdown!
Rule 2: Orphan Reaping and Zombie Accumulation
When a process creates child processes (e.g., via fork()) and those children terminate before the parent calls wait() or waitpid(), the children enter a <defunct> state known as zombies.
If the parent process exits first, the kernel re-parents the orphaned child processes to PID 1. PID 1 is expected to run an execution loop that calls wait() to clear zombie processes from the kernel process table. If PID 1 does not reap them, the process table gradually fills up with zombies:
docker exec my-container ps aux
Output showing process table leak:
PID USER TIME COMMAND
1 root 0:05 node server.js
42 root 0:00 [sh] <defunct>
43 root 0:00 [sh] <defunct>
44 root 0:00 [git] <defunct>
2. Solving PID 1 Issues with Init Executables
To solve signal forwarding and zombie reaping without modifying application source code, place a lightweight init wrapper at PID 1.
Option A: Use Built-in docker run --init
Docker includes tini directly inside the CLI. Passing the --init flag automatically injects tini as PID 1:
docker run -d --name init-demo --init node:22-alpine node server.js
Verify process structure inside the container:
docker exec init-demo ps aux
Output:
PID USER TIME COMMAND
1 root 0:00 docker-init -- node server.js
7 root 0:00 node server.js
Now, docker-init runs as PID 1:
- It intercepts
SIGTERMfromdocker stopand immediately forwards it tonode server.js(PID 7). - It continuously reaps any orphaned zombie subprocesses spawned by Node.js.
Option B: Bake tini into Dockerfile
For production images deployed across Kubernetes or container platforms where CLI flags aren’t accessible, install tini directly inside your Dockerfile:
# syntax=docker/dockerfile:1
FROM node:22-alpine
# Install tini init manager
RUN apk add --no-cache tini
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
# Use tini as the ENTRYPOINT in exec form
ENTRYPOINT ["/sbin/tini", "--"]
# Application startup command passed as arguments to tini
CMD ["node", "server.js"]
3. Comparing Init Helpers and Process Supervisors
| Init Tool / Supervisor | Architecture Type | Primary Use Case |
|---|---|---|
tini | Lightweight Init Wrapper | Minimal single-app containers (reaping & signal forwarding). Included in Docker CLI --init. |
dumb-init | Lightweight Init Wrapper | Written in C by Yelp; lightweight replacement for PID 1 signal handling. |
supervisord | Process Manager (Python) | Managing multiple long-running daemons (e.g. Nginx + PHP-FPM) in a single container. |
s6-overlay | Multi-Process Supervision Suite | Enterprise multi-process container init system with dependency ordering and logging. |
4. Single Responsibility Principle vs. Multi-Process Containers
Best practices strongly favor one main process per container. Splitting services into dedicated containers ensures independent scaling, log streaming, and lifecycle management:
# RECOMMENDED COMPOSABLE ARCHITECTURE
+-----------------------+ +-----------------------+
| Container A: Nginx | --> | Container B: PHP-FPM |
| (PID 1: Nginx) | | (PID 1: PHP-FPM) |
+-----------------------+ +-----------------------+
If a legacy application strictly requires running multiple processes in a single container, configure a process supervisor like supervisord or s6-overlay as PID 1 to monitor child process lifetimes and handle signal shutdowns gracefully.
Key Takeaway
Takeaway: Running application runtimes directly as PID 1 can lead to zombie process table leaks and hung shutdowns because default application code does not reap orphans or handle SIGTERM correctly. Using lightweight init tools like tini (via docker run --init or ENTRYPOINT ["/sbin/tini", "--"]) ensures clean signal handling, zero zombie process leaks, and instant container termination.