1. Key Concepts
👶 Child Process
A child process is created by a parent process using fork() or similar system calls.
Example:
🧟 Zombie Process
A zombie process is a child that has terminated, but its parent hasn’t read its exit status via wait() or waitpid().
It still has a PID and entry in the process table.
Shows up as <defunct> in ps.
👻 Orphan Process
An orphan process is a child whose parent has exited before the child. It is adopted by init (PID 1) or systemd.
🔧 2. Essential Linux Commands
🧠3. 20 FAANG-Level Debugging Scenarios
🔸 Process Relationships & Lifecycle
How can you confirm if a process has become a zombie?
Use:
ps -eo pid,ppid,stat,cmd | grep Z
How can you identify if a process is an orphan?
Check if the parent PID is 1:
Simulate a zombie process in C and verify via shell.
C code:
Shell:
How can you reparent an orphaned process?
Let the parent exit before the child:
setsid ./long_running_child.sh
What does the STAT column in ps output mean for zombies?
Z = zombie
🔸 Monitoring & Debugging Tools
Trace a running process to monitor its system calls.
strace -p <pid>
How do you detect file descriptors leakage in child processes?
- How can you monitor orphan/zombie processes over time?
watch "ps -eo pid,ppid,stat,cmd | egrep 'Z|^[0-9]+ +1 '"
Check if a parent process is cleaning up zombies.
Use:
ps -eo pid,ppid,stat,cmd
Forcefully kill a zombie process.
You can't. You must kill its parent or let it wait().
🔸 Advanced Debugging Scenarios
You observe many <defunct> processes in production. What could be the cause?
Parent not handling SIGCHLD or not calling wait().
Why do orphan processes not create resource issues like zombies?
Because init or systemd reaps them properly.
Write a shell script that checks for zombie processes and alerts.
A child exits immediately but ps still shows it—why?
It’s a zombie; parent hasn’t reaped it.
How do you make sure zombies are cleaned in C?
Use:
🔸 System Design + Debugging
How do large-scale daemons prevent zombie processes?
Use SIGCHLD handler + waitpid(-1, ...)
During a fork bomb attack, what behavior do you expect in the process tree?
Many zombie/defunct or orphaned processes. System will slow.
How does systemd handle orphaned processes differently than init?
It tracks child services and can impose cgroups-level resource limits.
What issue occurs if you fork but never exec or wait?
Memory usage spikes; system can hit PID limits (e.g. 32768).
Design a resilient background service that doesn't leave zombie children.
Use fork() with waitpid() + double-fork + SIGCHLD handling.