Sub topic 4
Process States and the Process Control Block
Prerequisites: basic CPU and memory concepts, C programming, interrupts, and simple queue operations. This chapter assumes that you know a process is a program in execution.
The Process Life Cycle
A process changes state as it runs. The operating system uses these states to track whether the process can use the CPU or must wait for another event.
| State | Meaning |
|---|---|
| New | The process is being created. |
| Ready | The process can run but is waiting for the CPU. |
| Running | The process currently has the CPU. |
| Waiting or blocked | The process is waiting for input, output, a signal, or another event. |
| Terminated | The process has finished or was stopped. |
A process usually moves from new to ready after creation. The scheduler selects a ready process, so it moves to running. If its time slice expires, the operating system preempts it and moves it back to ready. If it requests slow input or output, it moves to waiting. When the event finishes, it returns to ready. After completing its work, it enters terminated.
The ready and waiting states are different. A ready process needs only CPU time. A waiting process cannot continue until a particular event occurs.
The Process Control Block
A process control block, or PCB, is a kernel data structure that stores the information needed to manage one process. The operating system creates a PCB when it creates a process and removes it after the process is fully cleaned up.
A PCB commonly contains:
- Process identifier, or PID
- Current process state
- Program counter, which holds the address of the next instruction
- CPU register values
- Scheduling information, such as priority and queue links
- Memory-management information, such as page-table references
- Accounting information, such as CPU time used
- I/O status and references to open files
The exact fields depend on the operating system. The key idea is that the PCB preserves the process's execution context and management data.
Why the PCB Matters
When the kernel stops one process and later resumes it, it saves the process's registers and program counter in its PCB. It then loads the saved information from another process's PCB. This allows each process to continue as if it had not been interrupted.
A process in a ready queue has a PCB even though it is not running. The scheduler examines PCB information when choosing the next process. A blocked process also keeps its PCB while it waits.
Exam Method
For a state-transition question:
- Identify the current state.
- Identify the event, such as dispatch, I/O request, I/O completion, preemption, or exit.
- Apply the matching transition.
- Check whether the process can use the CPU immediately.
Exercise
A running process requests disk input. Which state does it enter, and what event returns it to the ready state?
Show answer
It enters the waiting or blocked state. Completion of the disk input returns it to the ready state.