Processes, Threads, and Scheduling
Processes hold a program's resources, threads execute its work, and the scheduler decides which runnable threads use CPU time. These ideas explain why concurrent programs can wait, contend, or respond at different speeds.
itOperating systems | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic: Processes, Threads, and Scheduling
A process is what a program becomes when the operating system starts it: a running instance with resources, including an address space, open files, credentials, and one or more execution paths. The program on disk is not busy. It is, in fact, spectacularly inactive. The process is the operating system's answer to the question, "which running work owns these things?"
Those execution paths are threads. They run the instructions, share the process resources, and become the units waiting for CPU time. This split exists because one activity often has more than one thing to do. A server can wait for network input while handling ready work. An application can keep one activity moving while another waits. Before that distinction, every wait would make the entire program wait, which is a poor use of a perfectly good processor.
The useful three-word state map is running, runnable, blocked. Runnable means a thread could execute but is waiting for a processor. Blocked means it is waiting for an event, such as a lock, input and output completion, a timer, or another dependency. This is the surprise that saves a great deal of misplaced tuning: a large thread count does not say that CPUs are busy. Many threads may be asleep, which is not laziness. It is coordination.
The scheduler chooses among runnable threads according to operating-system policy and priority. It tries to balance latency, throughput, fairness, and sometimes power use. That is not a magic speed dial. Higher priority does not create processor capacity, and more threads do not dissolve one lock, one storage device, or one serial piece of work. They merely give the scheduler more candidates for the same finite resource, which is an administrative achievement rather than a performance improvement.
Threads share state, and this is where the paperwork becomes physics. A mutex keeps conflicting changes out of the same critical section. A condition or event tells a waiting thread that progress may be possible. Use threads when work needs close coordination and you can name who owns the shared data. Use processes when independent ownership and isolation matter. The operating system is not being fussy about boundaries. It is trying to stop one accident from becoming several.
Start with the Cheatsheet for the states, policy terms, and diagnostic sequence. Use the Reference tab for POSIX and Linux scheduler detail. The Practice material turns the model into evidence on a Linux process. Read Field Notes before treating CPU percentage, affinity, or scheduler traces as self-explanatory. The Timeline shows why the interfaces and scheduler models behind these familiar words have kept changing.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html
Supports
- POSIX process as an aggregation of system resources containing one or more schedulable threads
- Portable thread scheduling model, priorities, and scheduling policy concepts
- https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_mutex_lock.html
Supports
- Mutex lock behavior and mutual exclusion for protected shared state
- https://www.kernel.org/doc/html/latest/scheduler/
Supports
- Linux scheduler documentation index and scheduler-specific study path
- https://www.kernel.org/doc/html/latest/scheduler/sched-eevdf.html
Supports
- Fair allocation among runnable tasks and latency-sensitive selection in Linux EEVDF documentation
- EEVDF's 1995 scientific origin and Linux transition beginning in version 6.6
- Field Note on scheduler implementation as a versioned dependency
- https://www.kernel.org/doc/html/latest/scheduler/sched-design-CFS.html
Supports
- Runnable task selection, scheduler classes, regular batch and idle policies, and context-switching events
- CFS merge into Linux 2.6.23 and virtual-runtime selection
- https://cdn.kernel.org/doc/html/latest/scheduler/sched-deadline.html
Supports
- Linux deadline scheduling runtime, period, deadline, and timing-oriented workload model
- https://standards.ieee.org/ieee/1003.1/1385/
Supports
- IEEE 1003.1-1990 POSIX system application interface
- POSIX.1-2001 as a common revision of earlier POSIX and Single UNIX base specifications
- https://standards.ieee.org/ieee/1003.1c/1393/
Supports
- 1995 approval and 1996 publication of the POSIX Threads Extension
- https://kernel.googlesource.com/pub/scm/linux/kernel/git/history/history/+/refs/tags/v2.6.11-rc3/Documentation/sched-design.txt
Supports
- 2002 Linux O(1) scheduler design, per-CPU run queues, and constant-time operations
- https://man7.org/linux/man-pages/man7/sched.7.html
Supports
- CFS replacement of Linux's O(1) scheduler in Linux 2.6.23
- SCHED_DEADLINE availability since Linux 3.14
- Constraints and safeguards for real-time and deadline scheduling
- https://man7.org/linux/man-pages/man5/proc_tid.5.html
Supports
- Per-thread directories under /proc/PID/task and thread ID inspection
- https://man7.org/linux/man-pages/man5/proc_loadavg.5.html
Supports
- Load average as a count of runnable and uninterruptible tasks over one, five, and fifteen minutes rather than a processor-use percentage
- https://man7.org/linux/man-pages/man1/ps.1.html
Supports
- ps -L thread listing and LWP and NLWP fields
- https://man7.org/linux/man-pages/man1/top.1.html
Supports
- top thread display mode with -H
- https://man7.org/linux/man-pages/man1/pidstat.1.html
Supports
- pidstat per-task and per-thread monitoring with -t
- https://www.man7.org/linux/man-pages/man1/taskset.1.html
Supports
- CPU affinity inspection and the consequences of restricting eligible CPUs
- https://docs.kernel.org/accounting/psi.html
Supports
- CPU pressure files and the share of time when tasks are stalled on a resource
- https://www.brendangregg.com/offcpuanalysis.html
Supports
- Off-CPU time, run-queue latency, and bounded tracing practice
- Measurement overhead from scheduler-event tracing
