Master Linux Process Management: From Fork to O(1) Scheduler
This article, translated from IBM’s RedBook, explains Linux process management fundamentals—including process lifecycle, threads, priorities, context switching, interrupt handling, process states, memory layout, and the O(1) scheduler—providing clear insights into how the kernel handles processes and impacts system performance.
1.1 Linux Process Management
Process management is one of the most important operating‑system functions. Efficient management ensures a program runs smoothly and efficiently. Linux process management is similar to UNIX and includes scheduling, interrupt handling, signals, priorities, context switches, process states, and memory management.
1.1.1 What Is a Process?
A process is an instance of a program running on a processor, using any resources the Linux kernel can provide to complete its task.
All processes in Linux are represented by a task_struct descriptor (also called a process descriptor) that stores identifiers, attributes, and resources needed for execution.
Figure 1‑2 task_struct structure
1.1.2 Process Lifecycle
Each process goes through creation, execution, termination, and cleanup. These stages repeat throughout system operation, making lifecycle analysis crucial for performance.
Figure 1‑3 classic process lifecycle
When a process creates a new one, the parent calls fork(), which creates a new task_struct and assigns a new PID. The address space is not copied; parent and child share it initially.
The child then calls exec() to load a new program, triggering copy‑on‑write page faults that allocate new physical pages for the child.
When the child finishes, it calls exit(), releasing most resources and sending a signal to the parent. The child becomes a zombie until the parent calls wait() to reap it.
1.1.3 Threads
A thread is an execution unit created by a process that runs in parallel with other threads of the same process, sharing memory, address space, and open files. Threads are also called Light‑Weight Processes (LWP).
Creating a thread costs less than creating a process because resources are not duplicated. The kernel schedules threads similarly to processes.
Figure 1‑4 processes and threads
Linux supports several thread libraries, including the legacy LinuxThreads, the POSIX‑compliant Native POSIX Thread Library (NPTL), and IBM’s NGPT. NPTL, introduced in kernel 2.6, offers better performance and scalability.
1.1.4 Process Priority and Nice Value
Priority determines the order in which the CPU schedules processes. Linux uses dynamic and static priorities; users can influence static priority via the nice value (range –20 to 19, default 0). Changing to a negative nice value requires root privileges.
1.1.5 Context Switching
During execution, a process’s state (registers, cache) is saved as its context. Switching to another process restores the new process’s context. Excessive context switches degrade performance because the CPU must flush registers and caches.
Figure 1‑5 context switch
1.1.6 Interrupt Handling
Interrupts, generated by I/O devices, notify the kernel of events that require immediate attention. Handling an interrupt may cause a context switch, and many interrupts can reduce performance.
Linux distinguishes hard interrupts (device‑generated) and soft interrupts (deferred work such as TCP/IP). Information about hard interrupts is available in /proc/interrupts. Binding interrupts to specific CPUs can improve performance, especially on SMP systems.
1.1.7 Process States
Each process has a state indicating its current activity. Common states include: TASK_RUNNING: runnable or on the run queue. TASK_STOPPED: stopped by a signal (e.g., SIGSTOP). TASK_INTERRUPTIBLE: sleeping, waiting for a condition. TASK_UNINTERRUPTIBLE: sleeping, not interruptible (e.g., waiting for I/O). TASK_ZOMBIE: terminated but not yet reaped by the parent.
Figure 1‑6 process states
Zombie processes cannot be killed with kill because they are already dead; they disappear when the parent exits or reaps them.
1.1.8 Process Memory Segments
A process’s address space consists of several regions:
Text segment – stores executable code.
Data segment – includes initialized data, BSS (zero‑initialized data), and the heap (dynamic allocations via malloc()).
Stack segment – holds local variables, function parameters, and return addresses.
Figure 1‑7 process address space
1.1.9 Linux CPU Scheduling
Linux uses an O(1) scheduler (introduced in kernel 2.6) that selects a process in constant time regardless of the number of processes. It maintains two priority arrays—active and expired—and rotates them when time slices expire.
The scheduler assigns time slices based on priority and interactivity, ensuring fairness while avoiding starvation. It also supports NUMA and symmetric multithreading (e.g., Intel Hyper‑Threading).
Figure 1‑8 Linux 2.6 O(1) scheduler
Figure 1‑9 O(1) scheduler structure
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.
