Skip to main content
InterviewHubPRO
Section Overview
Q33

Question 33 of 50

Part 3: Advanced Internals, Scale & Production Security (Senior / Lead)

66%
Docker & Containers (50 Qs)•Part 3: Advanced Internals, Scale & Production Security (Senior / Lead)

Debugging Crashing Containers: PID 1 Zombie Reaping and Signal Handling (`tini` / `dumb-init`).

senior LevelCode ExampleSignalsSecurity & AuthDocker & Containers

In Simple Words: In Unix, Process ID 1 (PID 1) has special kernel duties:

  1. Signal Handling: By default, the Linux kernel ignores SIGTERM for PID 1 unless the process explicitly registers a signal handler. If your Node.js or Python app is PID 1 and doesn't handle SIGTERM, docker stop hangs for 10 seconds and kills it with SIGKILL, corrupting database transactions!
  2. Zombie Reaping: When child processes terminate, they become zombies until their parent reaps them with wait(). If the parent process dies, orphaned children are reparented to PID 1. If PID 1 does not reap them, the system exhausts PID limits.

Solution: Minimal Init System (--init or tini)

dockerfile
# Option A: In Dockerfile
RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "server.js"]

Or run with docker run --init my-app. tini runs as PID 1, forwards signals properly, and reaps zombie processes.