Process states (new, ready, running, waiting, terminated) in Operating Systems - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
We want to understand how the time spent by a process changes as it moves through different states in an operating system.
How does the number of steps or transitions grow as the process runs?
Analyze the time complexity of the following process state transitions.
// Pseudocode for process state transitions
state = "new"
while state != "terminated":
if state == "new":
state = "ready"
else if state == "ready":
state = "running"
else if state == "running":
if needs_io:
state = "waiting"
else:
state = "terminated"
else if state == "waiting":
state = "ready"
// repeat until terminated
This code models how a process moves through states until it finishes.
Look for loops or repeated steps in the process state changes.
- Primary operation: The loop that changes the process state repeatedly.
- How many times: Depends on how many times the process needs CPU and I/O before termination.
The number of state transitions grows with how many CPU bursts and I/O waits the process has.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 (few I/O) | About 20 state changes |
| 100 (moderate I/O) | About 200 state changes |
| 1000 (many I/O) | About 2000 state changes |
Pattern observation: The total steps increase roughly in direct proportion to the number of CPU and I/O cycles.
Time Complexity: O(n)
This means the total number of state transitions grows linearly with the number of CPU and I/O cycles the process performs.
[X] Wrong: "The process state changes happen instantly and do not add up."
[OK] Correct: Each state change takes time and the total time depends on how many times the process switches states before finishing.
Understanding how process states change and how that affects execution time helps you explain how operating systems manage tasks efficiently.
"What if the process never needs I/O and runs straight to termination? How would the time complexity change?"
Practice
Solution
Step 1: Understand the meaning of the Ready state
The Ready state means the process has all resources except the CPU and is waiting to be assigned the CPU.Step 2: Compare with other states
Running means the process is using the CPU; Waiting means it is waiting for an event; New means it is being created.Final Answer:
Ready -> Option AQuick Check:
Ready = waiting for CPU [OK]
- Confusing Ready with Running
- Thinking Waiting means ready
- Mixing New with Ready
Solution
Step 1: Recall the typical process lifecycle
A process starts as New, then moves to Ready when prepared to run, then Running when executing.Step 2: Understand transitions to Waiting and Terminated
While running, it may wait for I/O (Waiting), then return to Ready or finish (Terminated).Final Answer:
New -> Ready -> Running -> Waiting -> Terminated -> Option AQuick Check:
Correct lifecycle order = New -> Ready -> Running -> Waiting -> Terminated [OK]
- Swapping Ready and Running order
- Putting Waiting before Ready
- Skipping New state
Solution
Step 1: Understand the Waiting state
Waiting means the process is paused, waiting for an event like I/O completion.Step 2: What happens after the event?
When the event occurs, the process becomes Ready to run but must wait for CPU scheduling.Final Answer:
It moves to the Ready state to wait for CPU allocation. -> Option DQuick Check:
Waiting ends -> Ready state [OK]
- Thinking Waiting goes directly to Running
- Assuming immediate termination
- Believing process stays Waiting forever
Solution
Step 1: Analyze the Running state behavior
Running means the process is executing instructions on the CPU.Step 2: Understand why it never leaves Running
If it never moves to Waiting or Terminated, it likely loops endlessly without I/O or exit calls.Final Answer:
The process is in an infinite loop without I/O or exit. -> Option CQuick Check:
Infinite loop causes stuck Running [OK]
- Confusing Running with Ready
- Thinking process is terminated
- Assuming process is waiting for CPU
Solution
Step 1: Understand state transitions
Moving from Running to Waiting means the process pauses for I/O or events.Step 2: Returning to Ready means it resumes waiting for CPU after I/O completes.
This cycle repeats until the process finishes and terminates.Final Answer:
The process frequently waits for I/O or external events during execution. -> Option BQuick Check:
Running -> Waiting -> Ready cycle = I/O waits [OK]
- Thinking process restarts after termination
- Assuming infinite loop
- Believing process never runs
