Process Concept & States
A program on disk is passive. A process is that program in motion, with a stack, a heap, registers, and an identity the OS can schedule.
In plain English
A process is a recipe being cooked. It can be ready, running, waiting, or finished.
By the end you will be able to
- Distinguish a program from a process.
- Draw and explain the five process states.
- Describe the transitions between ready, running, and waiting.
- Know what the ready queue and waiting queue contain.
Program versus process
A program is an executable file: code and static data on disk. A process is an instance of that program with its own address space, program counter, registers, stack, heap, and open resources. Two processes can run the same executable without sharing variables or file offsets. The kernel gives each process a process ID and tracks it in the process table.
The five states
A process moves through new, ready, running, waiting, and terminated. New means it is being created. Ready means it could run but is waiting for the CPU. Running means it currently has the CPU. Waiting means it is blocked on I/O or an event. Terminated means it has finished or been killed. The scheduler moves processes between ready and running; an I/O request or event moves it to waiting; completion of that event moves it back to ready.
new -> ready -> running -> terminated
| ^
v |
waitingQueues and transitions
The ready queue holds processes that can run. The waiting queue holds processes blocked on a specific event, such as disk I/O or a semaphore. A timer interrupt can move the running process back to ready, which is preemption. A blocked process does not consume CPU time. When the event completes, the kernel moves it to ready, not directly to running.
Creation and termination
UNIX creates a process with fork(), which duplicates the caller, and exec(), which replaces the image with a new program. Windows uses CreateProcess. A process terminates normally by returning from main or calling exit, or abnormally when it crashes or is killed. The parent may wait for the child to collect its exit status.
Watch it happen
Step through the worked example. Play it, pause it, or move one step at a time.
step-by-step
Step 1 of 7
P1 is created
The kernel allocates a PCB, a process ID, and an address space. The process is not yet ready to run.
Key takeaways
- A process is a program in execution with its own state and address space.
- The five states are new, ready, running, waiting, and terminated.
- A waiting process is blocked and is not on the ready queue.
- A timer interrupt can move running back to ready.
- fork creates, exec replaces, and exit terminates.
Common pitfalls
- Confusing a program with a process.
- Thinking a waiting process is using the CPU.
- Assuming a blocked process moves directly to running when I/O finishes.
Kernel notes
- Draw the state diagram and label every transition.
- Explain why ready and waiting are different queues.
- Know what fork and exec do.
Quick check
1. Which state is a process in while waiting for disk I/O?
2. When a waiting process's I/O completes, which state does it enter next?