Linux Curriculum
Processes Overview
1. What is a Process?
In Linux, a process is an instance of an executing program in memory, along with all the system resources allocated to it by the kernel (CPU time, memory address space, file descriptors, network sockets, environment variables, and security security contexts).
A program stored on a solid-state disk or hard drive is merely a static file containing executable machine code. When that program is executed, the kernel loads the binary into virtual memory, allocates process data structures, and schedules its execution threads across CPU cores.
2. Process Identification and Hierarchy
Every process in a Linux system is uniquely identified by numeric integers managed by the kernel:
The Process Tree (Inheritance)
Processes do not exist in isolation; they form an inverted tree structure originating from a single root ancestor: PID 1 (systemd or legacy init).
When a process creates a child, it invokes the fork() or clone() system call, which duplicates the parent's memory pages using Copy-on-Write (CoW), followed by execve() to load the new binary.
3. Process Lifecycle and States
A Linux process transitions through well-defined lifecycle states between initialization and termination:
State Indicators:
R(Running / Runnable): Either currently executing on a CPU core or waiting in the kernel runqueue.S(Interruptible Sleep): Waiting for an external event (network socket data, timer, keyboard input). Can be awakened by OS signals.D(Uninterruptible Sleep): Blocked waiting for synchronous hardware/disk I/O. Cannot be killed withkill -9until hardware responds.T(Stopped / Traced): Suspended via user signal (SIGSTOP,Ctrl+Z) or under gdb debugger tracing.Z(Zombie / Defunct): Process has completed execution (exit()), but its entry remains in the process table because the parent process has not yet read its exit status code viawait()orwaitpid().
4. Special Process Conditions: Zombies and Orphans
Zombie Processes (Z)
A zombie consumes zero CPU and zero memory address space, but it occupies an entry in the kernel's finite process table (/proc/sys/kernel/pid_max). If a buggy parent process continuously spawns child processes that exit without calling wait(), the PID table can become exhausted, preventing any new processes (including administrative shells) from launching!
[!TIP] You cannot kill a zombie with
kill -9because it is already dead. To clear a zombie, sendSIGHUPorSIGTERMto the parent process (PPID), or terminate the parent. When the parent dies, the zombie is adopted bysystemd(PID 1), which immediately harvests its exit code.
Orphan Processes
When a parent process terminates before its children, the children become orphans. The Linux kernel automatically reparents orphan processes to systemd (PID 1), which assumes responsibility for reaping them upon completion.
5. Summary Takeaways
- A process is an active, executing program instance managed via a unique Process ID (PID).
- All processes descend from PID 1 (
systemd). - Process states include Running (
R), Interruptible Sleep (S), Uninterruptible Disk Sleep (D), Stopped (T), and Zombie (Z). - Uninterruptible sleep (
D) processes cannot be terminated by signals until I/O concludes. - Zombie processes consume no memory, but hoard kernel PIDs; resolve them by terminating the parent process.