Non - Preemptive Priority Scheduling
NON-PREEMPTIVE
PRIORITY SCHEDULING
(Considering Higher Number = Higher Priority)
1. AIM
To simulate the Non-Preemptive Priority Scheduling Algorithm, where higher priority value indicates higher importance, and compute:
-
Completion Time (CT)
-
Turnaround Time (TAT)
-
Waiting Time (WT)
-
Average Waiting Time
-
Gantt Chart
2. THEORY
CPU scheduling determines which process from the ready queue gets the CPU next.
In Priority Scheduling, each process is assigned a priority, and the CPU is given to the process with the highest priority.
Non-Preemptive Priority Scheduling
-
CPU is allocated to the highest priority process among those that have already arrived.
-
Once a process starts executing, it cannot be preempted, even if a process with a higher priority arrives.
-
Here we consider:
-
Used in systems where tasks with higher importance must run before others.
Performance Metrics
-
Completion Time (CT): Time at which a process completes.
-
Turnaround Time (TAT)
-
Waiting Time (WT)
-
Average Waiting Time (AWT)
Advantages
-
Simple and fast.
-
Useful when processes have different importance levels.
Disadvantages
-
Starvation of low-priority processes.
-
No fairness without aging.
3. ALGORITHM
-
Input number of processes n.
-
For each process, input:
-
Arrival Time (AT)
-
Burst Time (BT)
-
Priority
-
-
Set all processes as
not completed. -
At current time, select the process that:
-
Has arrived (AT ≤ time)
-
Has highest priority (largest priority number)
-
Is not completed
-
-
Execute it non-preemptively until completion.
-
Calculate:
-
CT = completion time
-
TAT = CT − AT
-
WT = TAT − BT
-
-
Repeat until all processes are completed.
-
Compute Average Waiting Time.
4. SAMPLE INPUT (Example)
| Process | Arrival Time | Burst Time | Priority |
|---|---|---|---|
| P1 | 0 | 4 | 2 |
| P2 | 1 | 3 | 4 |
| P3 | 2 | 1 | 1 |
| P4 | 3 | 2 | 5 |
Higher number → Higher priority
5. GANTT CHART
6. COMPUTATION TABLE
| PID | AT | BT | Priority | CT | TAT | WT |
|---|---|---|---|---|---|---|
| P1 | 0 | 4 | 2 | 4 | 4 | 0 |
| P4 | 3 | 2 | 5 | 6 | 3 | 1 |
| P2 | 1 | 3 | 4 | 9 | 8 | 5 |
| P3 | 2 | 1 | 1 | 10 | 8 | 7 |
Average Waiting Time
7. C PROGRAM – NON-PREEMPTIVE PRIORITY SCHEDULING
(Higher Number = Higher Priority)
8. SAMPLE OUTPUT
9. RESULT
The Non-Preemptive Priority Scheduling Algorithm was successfully implemented.
Considering “higher number = higher priority,” the program correctly computed:
-
Completion Time
-
Turnaround Time
-
Waiting Time
-
Average Waiting Time
and produced the execution sequence and Gantt Chart.
Comments
Post a Comment