Non-Preemptive Priority Scheduling


Non-Preemptive Priority Scheduling is another type of technique which is commonly used to schedule processes in batch operating systems. I will teach you all the concepts of Priority scheduling and at last I will give you the code to implement priority scheduling in C++. So let's get started, shall we?

In Non-Preemptive Priority Scheduling there is a priority assigned to each process and processes are executed according to their priority and since it is non-preemptive so a process can't be preempted by another process in the midst of execution of a process.

Numerical:

Given the table of processes below schedule the processes according to Non-Preemptive Priority Scheduling and draw gantt chart. Also, find the waiting time and turn around time of each process.

Non-Preemptive Priority Scheduling

It is given in the picture that 7 means highest priority and 1 means lowest priority.
1. First process to arrive in main memory is the P1 process with arrival time 0 so it will be executed first for 4ms.
2. Now, P1 has executed completely.
3. While P1 was executing P2, P3, P4, P5 arrived in the main memory to be executed.
4. Among P2, P3, P4, P5 observe that P3 has the highest priority so it will execute for 1ms.
5. Now, P3 has executed completely.
6. While P3 was executing another process P6 came into main memory.
7. In the main memory we have P2, P4, P5, P6. Observe that, P6 has the highest priority among them so P6 will be executed for 6ms.
8. Now, P6 has also executed completely.
9. While P6 was executing no new process came into main memory.
10. Now, we have P2, P4, P5 in the main memory. Observe that P2 has the highest priority among them so P2 will be executed for 5ms.
11. Now, P2 has also executed completely.
12.  Now, we have P4, P5 in the main memory. Observe that P4 has the highest priority among them so P4 will be executed for 2ms.
11. Now, P4 has also executed completely.
12. Only P5 is remaining so it will be executed for 3ms.



Gantt Chart :








Non-Preemptive Priority Scheduling

Waiting Time for each process

Waiting time is computed by the formula starting execution time - arrival time of a process.
Process                                  Starting execution time - arrival time                          Waiting time
P1                                                              4 - 4                                                                  0
P2                                                            15 - 5                                                                 10
P3                                                              3 - 1                                                                  2
P4                                                            15 - 2                                                                 13
P5                                                            17 - 3                                                                 14
P6                                                              6 - 6                                                                  0

Turn around Time for each Process

Turn around time is computed by the formula completion time - arrival time of a process.
Process                                  Completion time - arrival time                          Waiting time
P1                                                           4 - 0                                                                   4
P2                                                          16 - 1                                                                15
P3                                                            5 - 2                                                                  3
P4                                                          18 - 3                                                                15
P5                                                          21 - 4                                                                17
P6                                                          11 - 5                                                                  6

Implementation in C++









OUTPUT:


Non-Preemptive Priority Scheduling


Guys you can follow me here  and ask your doubts:





Post a Comment (0)
Previous Post Next Post