A process is a dynamic abstraction describing the state required to describe a running program. It tracks 3 contexts.
- Memory context
Code, data, dynamically allocated memory. - Hardware context
Registers, program counter, stack pointer. - OS context
Process ID, process state, resources used.
Process State
Process state describes what a process is currently doing. The set of states and their transitions form a process model.
A 2-state model (Ready, Running) is insufficient to describe real systems, so a generic 5-state model is used.
- New
Process created, may still be under initialization, not yet ready. - Ready
Process waiting to run. - Running
Process being executed on the CPU. - Blocked
Process waiting for an event, cannot execute until the event occurs. - Terminated
Process finished execution, may require OS cleanup.
State Transitions
- Create
nil to New, a new process is created. - Admit
New to Ready, process is ready to be scheduled. - Switch
Ready to Running, process selected to run by the scheduler. - Switch
Running to Ready, process releases the CPU voluntarily or is preempted. - Event wait
Running to Blocked, process requests an event, resource, or service not yet available, e.g. a system call waiting for I/O. - Event occurs
Blocked to Ready, the awaited event occurs and the process can continue.
Process Control Block and Process Table
The Process Control Block (PCB), also called a Process Table Entry, is the entire execution context stored by the kernel for a single process. The kernel maintains one PCB per process, conceptually organized as a single process table.
Interesting design issues:
- Scalability
How many concurrent processes can the table support. - Efficiency
Access must be efficient with minimum space wastage.
The PCB stores the OS context (PID, process state), the hardware context (PC, stack pointer, frame pointer, general purpose registers), and memory region information pointing to the process’s text, data, heap, and stack.