The PID 1 Problem & Using Init Systems (tini, --init)
Fix zombie reaping and signal forwarding with tini or docker --init.
In plain words
Use an init when the process tree needs signal forwarding and orphan reaping, or adopt an exec-form entrypoint application that deliberately handles both.
Think of it like…
PID 1 is the daycare supervisor: if it stops collecting finished children and passes dismissal notices incorrectly, the room fills and no one hears closing time.
Where you’ve seen it
In practice, docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"] is the concrete move for this job: fix zombie reaping and signal forwarding with tini or docker --init. The release is not accepted until start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker confirms the result.
Words you’ll hear
- PID 1
- The implementation control in
docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]for fix zombie reaping and signal forwarding with tini or docker --init. - tini
- The result to observe with
start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker, rather than infer from a successful command alone. - --init
- The production boundary exposed when adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.
Visual diagram
Theory & deep dive
PID 1 control path
The concrete mechanism is docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]. The observable result is start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker; if those disagree, inspect the runtime evidence before changing unrelated settings.
Fix zombie reaping and signal forwarding with tini or docker --init. Keep PID 1, tini and --init in the same deployment record so the intent and the observed state cannot drift apart.
docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]
start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker, not with command success alone.--init failure boundary
Zombies do not consume CPU but exhaust PIDs and resource limits; a wrapper shell with a background worker is a common cause. tini itself must receive the correct stop signal and exec the intended child. The narrow failure to design for is adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.
Accept this compromise explicitly: Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity. The controlled check-start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker-also identifies the point where a different design is safer.
Exercise this failure safely: adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: Zombies do not consume CPU but exhaust PIDs and resource limits; a wrapper shell with a background worker is a common cause. tini itself must receive the correct stop signal and exec the intended child.
- Intent
- PID 1
When to use it & trade-offs
What it is
PID 1 in Linux has special signal and child-reaping semantics. A non-init application as PID 1 can ignore forwarded/default signals and fail to reap orphaned grandchildren; tini is a tiny init that forwards signals and reaps zombies, and Docker --init wires it into container startup.
Why it matters: Zombies do not consume CPU but exhaust PIDs and resource limits; a wrapper shell with a background worker is a common cause. tini itself must receive the correct stop signal and exec the intended child.
When to reach for it
- The fit is strongest for this job: fix zombie reaping and signal forwarding with tini or docker --init. Pair it with
start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches workerin the runbook. - Production PID 1 changes should make tini observable through
docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"], rather than trusting the runtime default. - Keep a rollback example for the case where adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.
When to avoid or be careful
- Do not accept command success while the system can still fail by adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.
- Avoid erasing --init protection merely to dodge this cost: “Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity”.
- Do not replace the evidence path-
start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker-with a screenshot or a mutable tag.
docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]: practical choices
Strengths: PID 1 in Linux has special signal and child-reaping semantics. A non-init application as PID 1 can ignore forwarded/default signals and fail to reap orphaned grandchildren; tini is a tiny init that forwards signals and reaps zombies, and Docker --init wires it into container startup.
Watch out: Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity.
Strengths: It can begin with docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"] and fewer surrounding controls.
Watch out: It silently accepts adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction, which makes the result hard to reproduce after promotion.
Strengths: Zombies do not consume CPU but exhaust PIDs and resource limits; a wrapper shell with a background worker is a common cause. tini itself must receive the correct stop signal and exec the intended child.
Watch out: The platform adds an ownership and debugging layer; retain start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]
- start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker
- Failure signature: adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction
- Trade-off: Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity.
Benchmarks & rules of thumb
- 1 PID
- tini becomes container PID 1
- 0 zombie accumulation
- required after a reaping test
- SIGTERM + SIGINT
- must reach the real service process
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]as proof and skippingstart/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker. - Adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction
- Optimizing PID 1 without accepting that docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity.
Likely interviewer follow-ups
- Why does
docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]address PID 1 here rather than through application code? - How would you distinguish healthy tini from the failure “adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction” using
start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker? - When would this trade-off-“Docker --init is nearly zero-friction; a language runtime or supervisor may provide richer lifecycle behavior at more complexity”-justify a different --init design?
docker run --init --rm ghcr.io/acme/worker:2.1; ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/worker"]-and one proof-start/terminate a child process, run ps -ef and confirm no defunct state plus SIGTERM reaches worker. Then name the boundary: adding tini but still wrapping the child without exec, or believing tini fixes an application’s long shutdown transaction.Knowledge check
Put it into practice
Practice related interview Q&A
Apply The PID 1 Problem & Using Init Systems (tini, --init) with generative AI interview Q&A and hands-on practice.