Priority scheduling

The most important ready process runs first. You choose whether a new arrival can interrupt. Press play and watch every decision.

Processes

Name Arrival Burst Priority Remove
The running process always finishes first.
Highest priority1 is the highest priority.
Why this happened

P2 has the best priority (1), so it runs next.

Ready queue, next in line first
    Decision log

    Every moment something was decided. Choose a line to move the playhead there.

      Keyboard shortcuts
      Space
      Play or pause
      Left Right
      Step back or forward one unit
      Home End
      Jump to the start or the end
      R
      Reset
      [ ]
      Slower or faster
      T
      Switch light or dark theme

      Shortcuts are off while you type in a field.

      Results

      Process Arrival Burst Finished Turnaround Waiting Response
      Average

       

      Turnaround is finished - arrival. Waiting is turnaround - burst. Response is first run - arrival. CPU utilization is total burst / last finish.

      How Priority scheduling works

      In Priority scheduling every process carries a priority number, and the scheduler runs the ready process with the best one. What counts as best is a convention, and it differs between textbooks and systems. Trace uses lower number means higher priority by default, so priority 1 beats priority 3. The "Highest priority" switch flips this when your question uses the opposite convention.

      The algorithm comes in two forms. Non-preemptive Priority decides only when the CPU becomes free, and the chosen process then runs to the end. Preemptive Priority also checks every arrival: a newcomer with a strictly better priority takes the CPU at once, and the interrupted process goes back to wait. A newcomer with the same priority does not interrupt. In both forms, ties between waiting processes go to the earlier arrival and then to the lower process number.

      The weakness of strict priority is starvation. A low-priority process can wait indefinitely while higher-priority work keeps arriving. The usual remedy is aging, which slowly improves the priority of a process the longer it waits. Trace does not apply aging, so the schedules here show plain priority exactly as defined.

      Priority scheduling is also a general frame for other algorithms. If you use the burst length as the priority, non-preemptive Priority becomes Shortest Job First, which is a useful way to check your understanding of both.

      Worked example

      Five processes arrive at time 0 with bursts 10, 1, 2, 1 and 5 and priorities 3, 1, 4, 5 and 2. With everyone ready together, non-preemptive Priority simply runs them from best to worst: P2 (1), P5 (2), P1 (3), P3 (4), P4 (5).

      Priority (non-preemptive, lower number means higher priority). Order of execution: P2 0 to 1, P5 1 to 6, P1 6 to 16, P3 16 to 18, P4 18 to 19.

      Priority worked example results
      ProcessArrivalBurstPriorityFinishedTurnaroundWaitingResponse
      P10103161666
      P20111100
      P302418181616
      P401519191818
      P50526611
      Average128.20 (41/5)8.20 (41/5)

      Open this example in the simulator

      The average waiting time is (6 + 0 + 16 + 18 + 1) / 5 = 8.2. Priority does not try to minimize waiting time: the same processes under SJF would average 3.2. It optimizes for importance, not speed, and that trade-off is the point of the algorithm.

      With preemption turned on

      Try a case where arrivals happen while something runs: P1 (burst 7, priority 3) at time 0, P2 (4, priority 1) at 2, P3 (2, priority 2) at 3 and P4 (3, priority 1) at 5. At time 2, P2 preempts P1. At time 5, P4 arrives with the same priority as P2, so P2 keeps the CPU and finishes at 6. Then P4, P3 and finally the rest of P1 run, for an average waiting time of 4. Open this case in the simulator.

      Formulas

      • Turnaround time = finished - arrival
      • Waiting time = turnaround - burst
      • Response time = first run - arrival

      The priority number never appears in these formulas; it only decides the order. P4 in the first example has the worst priority, so it runs last: it finishes at 19, its turnaround is 19 and it waits 19 - 1 = 18 units for a job that needs just 1.

      Strengths and weaknesses

      Strengths

      • Lets important work go first, which arrival order and burst length cannot express.
      • The preemptive form reacts at once to urgent arrivals.
      • A general scheme: other policies, like SJF, are special cases of it.

      Weaknesses

      • Low-priority processes can starve without aging.
      • Average waiting time can be poor, since importance and length are unrelated.
      • The meaning of the numbers is a convention that must be agreed first.

      Common exam mistakes

      1. Assuming the bigger number wins. Read the question for the convention. Many exercises use 1 as the highest priority, but not all of them do.
      2. Ignoring arrival times. A priority 1 process that arrives at time 6 cannot run at time 2, no matter how important it is.
      3. Forgetting to check arrivals in the preemptive form. Every arrival is a possible preemption point, not only the moments when a process finishes.
      4. Preempting on equal priority. An arrival with the same priority as the running process waits. Trace follows this rule; check that your course does too.

      Spotted a mistake?

      If the order or a number looks wrong, mention which priority convention and which form (preemptive or not) you expected, plus the link from "Copy link".

      Email: abdul at abmans dot com