i)
a) Draw the process state diagram indicating clearly the transitions between states.
+-------+ +-------+ +---------+
| New | --> | Ready | <-> | Running | --> | Terminated |
+-------+ +-------+ +---------+
^ |
| v
+-------------+
| Blocked |
+---------+
- New: The process is being created.
- Ready: The process is waiting to be assigned to a processor.
- Running: Instructions are being executed.
- Blocked (Waiting): The process is waiting for some event to occur (e.g., I/O completion, signal).
- Terminated: The process has finished execution.
b) Describe the transition from the Running state to the Blocked (Waiting) state. Give an example of an event that would cause this transition.
A process transitions from the Running state to the Blocked (Waiting) state when it requires an event to occur that it cannot immediately satisfy. This typically involves waiting for an I/O operation to complete or for a resource to become available. The CPU is then relinquished by the process.
Example: A process requests to read data from a hard disk. Since disk I/O is much slower than CPU operations, the process enters the Blocked state until the data is read and available.
ii)
Given processes arriving at time 0:
| Process | Burst Time (ms) | Priority |
| :------ | :-------------- | :------- |
| P1 | 10 | 3 |
| P2 | 1 | 1 |
| P3 | 2 | 4 |
| P4 | 1 | 5 |
| P5 | 5 | 2 |
A smaller priority number implies a higher priority.
a) Draw a Gantt chart illustrating the execution of these processes using a Preemptive Priority scheduling algorithm.
At time t=0, all processes arrive. We sort them by priority (1 is highest, 5 is lowest):
- P2 (Priority 1, Burst 1)
- P5 (Priority 2, Burst 5)
- P1 (Priority 3, Burst 10)
- P3 (Priority 4, Burst 2)
- P4 (Priority 5, Burst 1)
Since all processes arrive at t=0 and no new processes arrive later, the preemptive priority scheduling behaves like non-preemptive in this specific scenario.
Gantt Chart:
P2P5P1P3P4
016161819
b) Calculate the average waiting time for the processes using the scheduling algorithm in part (a).
First, calculate the completion time for each process:
- P2 completes at 1 ms
- P5 completes at 6 ms
- P1 completes at 16 ms
- P3 completes at 18 ms
- P4 completes at 19 ms
Waiting Time = Completion Time - Burst Time - Arrival Time
Since all arrival times are 0 ms:
Waiting Time = Completion Time - Burst Time
- P2 Waiting Time: 1ms−1ms−0ms=0 ms
- P5 Waiting Time: 6ms−5ms−0ms=1 ms
- P1 Waiting Time: 16ms−10ms−0ms=6 ms
- P3 Waiting Time: 18ms−2ms−0ms=16 ms
- P4 Waiting Time: 19ms−1ms−0ms=18 ms
Total Waiting Time = 0+1+6+16+18=41 ms
Number of processes = 5
Average Waiting Time = NumberofProcessesTotalWaitingTime
Average Waiting Time = 541ms=8.2 ms
The average waiting time for the processes is 8.2ms.
c) Explain one disadvantage of priority-based scheduling.
One significant disadvantage of priority-based scheduling is starvation (or indefinite blocking). Low-priority processes may never get to execute if there is a continuous stream of higher-priority processes entering the ready queue. This can lead to a situation where a process waits indefinitely for the CPU.