5

When using Priority Preemptive Scheduling, does a higher priority yield way to a process with a lower priority but with a shorter burst time?

For example, if I had:

    Arrival Time   Burst Time   Priority
P1       0             5           3
P2       2             6           1
P3       3             3           2

Would the Gannt chart look like this?

| P1 | P2 | P3 | P1 |
0    2    8   11   16   
Ben Kreeger
  • 6,355
  • 2
  • 38
  • 53
raphnguyen
  • 3,565
  • 18
  • 56
  • 74

3 Answers3

13

Priority Scheduling always selects the process(es) with the highest priority currently ready to run. If there is more than one process having the currently highest priority, you need a second scheduling algorithm to choose among these processes. Non-preemptive Priority Scheduling only selects a new process to run if the running process finished its work or yields (voluntarily) to the scheduler.

Preemptive Priority Scheduling is the same algorithm but if a new process having a higher priority than the currently running process arrives, it gets selected immediately. The new process has not to wait until the currently running process finishes or yields.

In your sample, the Gantt chart for Preemptive Priority Scheduling and 3 being the highest and 1 the lowest priority would look like:

|    P1   |  P3 |        P2      |
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
  • Thanks for the help. I wasn't sure if burst time was taken into account. – raphnguyen Feb 11 '12 at 20:19
  • You probably thought of *Shortest Job First* scheduling (SJF) – Johannes Weiss Feb 11 '12 at 20:24
  • could you accept the answer and possibly upvote it if you like it ;-). Thanks – Johannes Weiss Feb 11 '12 at 20:26
  • @JohannesWeiß excuse me, but does preemptive priority scheduling mean that if a thread that's waiting has a higher priority thread than another one that's already running and no other processors available the lower priority thread (that's running) will transitions to the ready state to dispatch the higher priority thread to that processor? – kzidane Jul 08 '13 at 23:01
  • 1
    @KareemMesbah , yes. Preemptive means that a thread can be taken from the running state without its willingness to do so. Therefore preemtive priority scheduling does change the running thread if there's another thread with higher priority that is only waiting for the CPU. – Johannes Weiss Jul 09 '13 at 16:14
2
| p1 | p2 | p3 | p1 |

0....2....8....11...14   

taking 1 as the highest priority.

j0k
  • 22,600
  • 28
  • 79
  • 90
Mayank
  • 21
  • 1
0
       |p1  |p2  |p3  |p1  |

       0    2    8    11   14 

because preemptive approach will preempt if the priority of the newly-arrived process is higher than the priority of currently running process..