Understanding Linux Process States: Running, Blocking, Zombie & Orphan
This article explains Linux process states—including running, sleeping, disk sleep, stopped, dead, zombie, and orphan—detailing their meanings, kernel definitions, how to observe them with code examples, and the implications for system resource management.
Linux Process States Overview
New (created) : Process has just been created, PCB and resources allocated but not yet in the ready queue.
Ready (runnable) : All resources except CPU are allocated; the process will run as soon as it gets CPU time.
Sleeping (blocked) : Process waits for an event (e.g., I/O) and cannot run even if CPU is assigned.
Running : Process currently holds the CPU and is executing.
Terminated (dead) : Process has finished execution or been killed and is exiting.
Running State Details
When many processes compete for a single CPU, the scheduler uses a per‑CPU runqueue to store processes ready to run. Each process has a task_struct containing its attributes; the runqueue maintains head and tail pointers to the queue.
The scheduler selects a process from the runqueue, removes it, and places it on the CPU. To prevent a single process from monopolising the CPU, the OS assigns a time slice; when the slice expires, the process is pre‑empted and returned to the tail of the runqueue.
Blocking (Sleep) State
When a process needs a device, it is placed in the device’s wait queue. If the device is not ready, the process’s PCB is added to the wait queue until the device becomes readable, at which point the process moves to the ready state.
Suspended (Stopped) State
A process can be stopped by sending SIGSTOP (e.g., kill -19 <pid>) and resumed with SIGCONT (e.g., kill -18 <pid>). While stopped, the process appears as T in ps output.
Linux Kernel Definition of States
/* The task state array is a strange "bitmap" of
* reasons to sleep. Thus "running" is zero, and
* you can test for combinations of others with
* simple bit tests.
*/
static const char * const task_state_array[] = {
"R (running)", /* 0 */
"S (sleeping)", /* 1 */
"D (disk sleep)",/* 2 */
"T (stopped)", /* 4 */
"t (tracing stop)",/* 8 */
"X (dead)", /* 16 */
"Z (zombie)", /* 32 */
};R (running) : Process is either executing or in the runqueue.
S (sleeping) : Process is waiting for an event (interruptible sleep).
D (disk sleep) : Uninterruptible sleep, usually waiting for I/O.
T (stopped) : Process stopped by a signal; can be continued with SIGCONT.
X (dead) : Process has exited; not shown in the task list.
Z (zombie) : Process has terminated but its exit status has not been collected by the parent.
Observing Process States
Example program:
int main(){
while(1){
printf("hello linux
");
}
return 0;
}Running this program shows the process in S state because it spends most of its time waiting for I/O (the terminal). Removing the printf call yields a CPU‑bound loop that appears in R state.
int main(){
while(1);
return 0;
}When the process is stopped ( kill -19 <pid>) it appears as T . Resuming it with kill -18 <pid> returns it to S or R depending on its workload.
Zombie Process
A child that exits without its parent calling wait() remains in Z state, holding its task_struct until the parent reaps it. If the parent never reaps, the zombie occupies memory.
Orphan Process
If a parent exits before its child, the child becomes an orphan and is adopted by PID 1 (the init process). Orphans are later reaped by init.
Summary
The Linux kernel classifies processes into several states to manage scheduling, I/O waiting, and termination. Understanding these states—running, sleeping, disk sleep, stopped, dead, zombie, and orphan—helps developers write efficient programs and diagnose system performance issues.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
