Difficulty: Beginner
Explain the process life cycle and states. What is stored in a Process Control Block (PCB)?
Every process lives a small life: it is born, it waits for its turn, it runs, sometimes it waits for something slow like the disk, and eventually it dies. The OS models this as a state machine, and interviewers love asking you to draw it because it ties together scheduling, I/O and memory management in one picture.
The classic five-state model has New, Ready, Running, Waiting (also called Blocked) and Terminated. New means the process is being created and its PCB is being set up. Ready means the process has everything it needs except the CPU, so it sits in the ready queue. Running means its instructions are currently executing on a CPU core. Waiting means it cannot proceed until some event completes, such as an I/O operation or a signal, so it sits in a device or event queue. Terminated means it has finished and the OS is cleaning up.
The transitions are where the marks are. New to Ready happens when the long-term scheduler admits the process. Ready to Running is dispatch, when the short-term scheduler picks it. Running to Ready happens on preemption, for example when the time quantum expires or a higher priority process arrives. Running to Waiting happens when the process requests I/O or waits on a lock. Waiting to Ready happens when the I/O completes, and importantly it goes to Ready, not straight to Running. Running to Terminated happens on exit or a fatal error. A subtle point: there is no direct Waiting to Running edge and no Ready to Waiting edge; a process can only block itself while it is executing.
Real systems add two more states related to memory. Suspended Ready and Suspended Blocked represent processes swapped out of RAM to disk by the medium-term scheduler when memory is tight. Linux itself shows states such as R (running or runnable), S (interruptible sleep), D (uninterruptible sleep, usually disk I/O), T (stopped) and Z (zombie), which you can see in the ps command.
The Process Control Block is the kernel's record for a process, and it is what makes context switching possible. It contains the process ID and parent ID, the current state, the program counter and all CPU registers (the saved context), scheduling information such as priority and queue pointers, memory management information such as page table pointers or base and limit registers, accounting information like CPU time used, and I/O status information such as the open file table and allocated devices. In Linux the equivalent structure is task_struct.
When the OS switches from process A to process B, it saves A's registers and program counter into A's PCB and loads B's values from B's PCB. That is why the PCB must be stored in protected kernel memory: if a user process could edit it, it could hijack another process's execution.
Wrap up by mentioning the three schedulers: long-term (admission to memory), short-term (CPU selection, runs very frequently) and medium-term (swapping). That connects nicely to scheduling questions later in the interview.
process states, PCB, state transition, scheduler queues