Added Zombie Ps Docs

This commit is contained in:
2026-04-14 18:02:10 +03:30
parent ded4f55fb8
commit edea1fe9e8
4 changed files with 196 additions and 69 deletions

View File

@@ -0,0 +1,46 @@
## Zombie Processes
### What is a Zombie Process?
In Linux/Unix operating systems, when a process ends, its execution is halted, but it leaves behind an entry in the process table. This entry contains the process's exit status, which needs to be read by its parent process.
A **zombie process** (or defunct process, indicated by the `Z` state in `ps` output) is a child process that has completed its execution, but its parent process has not yet called the `wait()` or `waitpid()` system calls to read its exit status. Because the parent hasn't acknowledged the death, the OS keeps the child's entry in the process table.
### The Effect of Zombie Processes
At first glance, a zombie process seems harmless:
* It consumes **$0$** CPU resources.
* It consumes **$0$** Memory (RAM).
**The Danger: PID Exhaustion**
The only resource a zombie consumes is an entry in the OS process table and a Process ID (PID). Operating systems have a maximum limit of PIDs available (often $32768$ by default, though tunable in `sysctl`). If a poorly written parent process continuously spawns children and never reaps them, the system will eventually run out of available PIDs.
When PID exhaustion occurs, the OS cannot create any new processes. You won't be able to SSH into the server, execute basic commands, or spawn new application threads, effectively bringing the system down.
### How to Identify Zombies
* **Using `top`:** The header will explicitly show a counter for zombie processes.
* **Using `ps`:** List the PIDs of all processes with a `Z` (Zombie) state:
```bash
ps aux | awk '{ print $8 " " $2 }' | grep -w Z
```
### How to "Kill" a Zombie Process
**Important Rule:** You cannot kill a zombie process directly. Even `kill -9 <zombie_pid>` (SIGKILL) will not work because the process is already dead. To clear a zombie, you must deal with its **parent process**.
**Step 1: Find the Parent Process ID (PPID)**
Find out which process spawned the zombie:
```bash
ps -o ppid= -p <zombie_pid>
```
**Step 2: Ask the parent to reap the child**
Send a `SIGCHLD` signal to the parent process. This acts as a gentle reminder for the parent to execute the `wait()` system call and clean up its children.
```bash
kill -s SIGCHLD <parent_pid>
```
**Step 3: Kill the Parent Process (If Step 2 fails)**
If the parent process is poorly programmed, hung, or ignoring the `SIGCHLD` signal, your only operational choice is to kill the parent process:
```bash
kill -9 <parent_pid>
```
*Note on Step 3:* When the parent dies, the zombie process becomes an "orphan". The OS kernel automatically reassigns all orphan processes to the init system (usually `systemd` or `init`, which is PID $1$). PID $1$ is specifically designed to routinely execute `wait()` and will instantly reap the zombie, finally clearing it from the process table.

View File

@@ -1,18 +1,18 @@
# ⚙️ PS Command
# PS Command
The `ps` (process status) command is used to **view running processes** on a Linux system. Its useful for monitoring and troubleshooting tasks.
---
## 🧾 Basic Usage
## Basic Usage
### 🔍 Show tasks in the current shell
### Show tasks in the current shell
```bash
ps
```
### 🔍 Show tasks in the current shell with **full info**
### Show tasks in the current shell with **full info**
```bash
ps -f
@@ -20,9 +20,9 @@ ps -f
---
## 🌍 View System-Wide Processes
## View System-Wide Processes
### 📋 Show **all** processes
### Show **all** processes
```bash
ps -A
@@ -32,17 +32,17 @@ ps -e
---
### 👤 Show tasks by **specific user**
### Show tasks by **specific user**
```bash
ps -u <username>
```
📌 Replace `<username>` with the actual user name.
Replace `<username>` with the actual user name.
---
### 📊 Show **detailed info for all** tasks
### Show **detailed info for all** tasks
```bash
ps aux
@@ -50,7 +50,7 @@ ps aux
---
## 📘 Output Fields Explained
## Output Fields Explained
| Column | Description |
| --------- | -------------------------------------------------- |
@@ -58,22 +58,20 @@ ps aux
| `PID` | Process ID |
| `%CPU` | CPU usage percentage |
| `%MEM` | Memory usage percentage |
| `STAT` | Process state: `R` (running), `S` (sleeping), etc. |
| `STAT` | Process state: `R` (running), `S` (sleeping), `Z` (zombie), etc. |
| `START` | Time when the process started |
| `TIME` | Total CPU time used |
| `COMMAND` | Command that started the process |
### 📑 Show List Jobs
### Show List Jobs
```bash
jobs
```
### 🔄Move Process From Background To Forground
### Move Process From Background To Foreground
```bash
fg
```