What are the states of a process, and what is a PCB?
EasyConceptProcesses & Threads
Answer
A process moves through five states: New (being created), Ready (in memory, waiting for the CPU), Running (executing on the CPU), Waiting or Blocked (waiting for I/O or another event) and Terminated (finished). The OS keeps everything it knows about a process in a Process Control Block (PCB).
- Ready → Running when the scheduler picks the process (dispatch); Running → Ready when its time slice ends or a higher-priority process arrives.
- Running → Waiting when it requests I/O; Waiting → Ready when the I/O completes. It never goes from Waiting straight to Running, because it must be scheduled again.
- The PCB holds the process ID (PID), state, saved program counter and registers, scheduling priority, memory information (such as a pointer to its page table) and the list of open files.
Example: a program that reads a file and prints its size moves like this:
New → Ready → Running → (calls read) Waiting → (disk done) Ready → Running → Terminated
While it is Waiting, its PCB keeps the saved registers, so the process later continues exactly where it stopped.
More in Processes & Threads
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | What is the difference between a process and a thread? | Concept | Easy | Read the answer to What is the difference between a process and a thread? | |||
| 2 | What are the states of a process, and what is a PCB? | Concept | Easy | Read the answer to What are the states of a process, and what is a PCB? | |||
| 3 | What is a context switch, and why is it considered overhead? | Concept | Medium | Read the answer to What is a context switch, and why is it considered overhead? | |||
| 4 | What does fork() do, and what does it return? | Concept | Medium | Read the answer to What does fork() do, and what does it return? | |||
| 5 | What are zombie and orphan processes? | Concept | Medium | Read the answer to What are zombie and orphan processes? |