What is the difference between an orphan process and a zombie process in Linux, and how do you get rid of both of them?
An orphan process is a process whose parent process (Parent Process) has died while it is still running, and the system's first processor PID 1 immediately adopts it and cleans it up when it finishes without any damage. As for the ghost process (Zombie - Z state), it is a process that has already ended and cleared its memory, but its parent process did not read its exit code by calling wait(); and the zombie cannot be killed with the kill -9 command because it is already dead, and it is resolved by sending either SIGCHLD to the parent or terminate the parent process so that PID 1 cleans up the process table entries.
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
Technical comparison between the two cases:
-
Orphan Process:
- Status: The mother died, and the son is still working.
- Processing: The kernel moves the process dependency to
PID 1(Systemd) in a process called Re-parenting. - Risk: Zero; The system runs normally.
-
Zombie / Defunct Process):
- Status: The child finished (called
exit()), but the mother did not callwait()orwaitpid(). - Resource Consumed: It does not consume CPU or RAM, but holds PID in the kernel process table.
- How to get rid of it:
#1. Know the stealth process and its parent ps -eo pid,ppid,stat,cmd | grep '[Zz]' #2. Sending an alert signal to the father to read about the children's departure kill -s SIGCHLD <PPID> #3. If the father does not respond, the father must terminate himself so that PID 1 adopts the ghosts and cleans them kill -15 <PPID>
- Status: The child finished (called
- Attempting to execute kill -9 on a process in Zombie state; the ghost process is already dead and does not consume processor or memory, but only occupies an entry in the Process Table Entry.
- Thousands of ghost processes accumulate due to a software bug in the parent application, leading to the running out of available PIDs and preventing the server from running any new process.
- How do you find the parent identifier (PPID) of a specific ghost process in the terminal?
- What is the maximum number of process IDs in the system and where are they set in the kernel?
Compare the SIGTERM(15) flag and the SIGKILL(9) flag in Linux, and why is it not recommended to use kill -9 as the first action?
SIGTERM (signal 15) is the default shutdown request. An application can catch or block it to finish work, save state, and close file descriptors and connections cleanly. SIGKILL (signal 9) cannot be caught or blocked: the kernel stops the process immediately, without an opportunity to save data, which can corrupt databases or open files.
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
The most commonly used flags table in DevOps environments:
| Signal number | Name | Meaning and behavior | Can the app pick it up? |
|---|---|---|---|
1 |
SIGHUP |
Disconnecting from the terminal / re-reading the configuration files (Reload) | Yes (Catchable) |
2 |
SIGINT |
Manual interruption from the keyboard via Ctrl+C |
Yes (Catchable) |
9 |
SIGKILL |
Forced immediate termination executed directly by the kernel No (Uncatchable) | |
15 |
SIGTERM |
Request a graceful termination Yes (Catchable) | |
17 / 18 |
SIGCHLD |
Notice from the departed son to the father Yes (Catchable) |
Recommended professional practice:
Send SIGTERM first, wait for a time limit (such as 15 or 30 seconds), and if the process continues to hang, use SIGKILL as a last resort:
kill -15 <PID>
# Wait for clean shutdown
sleep 10
kill -0 <PID> 2>/dev/null && kill -9 <PID>- Using kill -9 directly in automation and reboot scripts leaves dead lock files such as .pid that prevent the service from starting again.
- Belief that SIGKILL can terminate a process in D-State (Uninterruptible Sleep); the kernel delays handing over any signal to the process until the failed disk read/write request is complete.
- What is the SIGHUP signal (Signal 1) and how do web servers like NGINX use it to reload the configuration without stopping the service?
- Why can't a normal user kill a process owned by another user without sudo privileges?