-2

Have question on priority scheduling both in preemptive and nonpreemptive and wanted to make sure understand it correctly. (Higher the number highest priority)

Process   Arrival Time  Burst Time  Priority
P1             0          5            5
P2             0          12           7  

Since these processes come in at the same time in preemptive P2 would run first for 12 and then P1, but in nonpreemptive would FCFS be used and P1 would run first and then P2?

Erik Eidt
  • 33,282
  • 5
  • 57
  • 91
TOD
  • 1

2 Answers2

1

in preemptive P2 would run first for 12 and then P1

Possibly — it would make sense for the higher priority job to finish before starting a lower priority job.  But this is an aspect of priority scheduling not an aspect of preemptive scheduling: with the word preemptive we would expect interruptibility: a process to be interrupted (suspended and resumed later) in order to service a higher priority job that comes in while a lower priority job is running — but that isn't demonstrated in this scenario.

(Some preemptive systems may hand out slices of time (e.g. 1 or 2 units) and may rotate to a lower priority job for some notion of fairness (so, for example, giving more time slices to the 7 and less but still some to the 5).)

nonpreemptive would FCFS be used and P1 would run first and then P2

Since they both arrive at the same time, there is no "1st" and "2nd" — they are tied.  Don't let names or labels "P1" and "P2" fool you.

FCFS mixes with priority scheduling as follows: when 2 processes/jobs have the same priority FCFS can be used as the deciding factor in who runs first.  If both arrive at the same time, then something else must be the deciding factor.

Nonpreemptive simply means that the currently running job must finish since there is no mechanism to suspend it (and resume it later).

Erik Eidt
  • 33,282
  • 5
  • 57
  • 91
1

The difference between preemptive and non-preemptive scheduling can best be demonstrated if the processes have a different arrival time:

Process   Arrival Time  Burst Time  Priority
P1             0          5            5
P2             1          12           7  

Here, the higher priority process (P2) comes slightly after the lower priority one (P1), but it follows close enough that P1 did not have time to complete yet.

At t=0, only one process (P1) is ready to run so that process will be scheduled and executed.
At t=1, the higher priority process (P2) also wants to run.

If you have a preemptive scheduler, then the scheduler will interrupt (preempt) P1 and give P2 the chance to run, as that has a higher priority.

If you have a non-preemptive scheduler, the scheduler is not able to stop an already running process, so P1 will be allowed to run to completion and P2 will only be executed afterward.

Bart van Ingen Schenau
  • 71,712
  • 20
  • 110
  • 179