Skip to content

Latest commit

 

History

History
15 lines (12 loc) · 1.62 KB

5.1 Priority_preemtive.md

File metadata and controls

15 lines (12 loc) · 1.62 KB

Priority scheduling is a CPU scheduling algorithm where each process is assigned a priority and the process with the highest priority is executed first. In preemptive priority scheduling, a process that is currently running can be preempted by a process with a higher priority.

Here is a high-level overview of how the priority preemptive scheduling algorithm works:

  • When a process arrives, its priority is determined (either by the system or by the user).
  • The process is added to the ready queue based on its priority.
  • The CPU is assigned to the process with the highest priority in the ready queue.
  • The process is executed for a quantum (a fixed amount of time) or until it completes or is preempted.
  • If the process completes, it is removed from the queue.
  • If a new process arrives with a higher priority than the currently executing process, the currently executing process is preempted and moved back to the ready queue.
  • If the current process is blocked, it is moved to a blocked queue and the CPU is assigned to the process with the highest priority in the ready queue.
  • When a blocked process becomes unblocked (e.g., I/O completes), its priority is checked and it may be moved to the ready queue.
  • Steps 3-8 are repeated until all processes have completed.

Priority scheduling can be implemented using a variety of data structures, such as a priority queue or a linked list sorted by priority. In preemptive priority scheduling, the priority queue is updated whenever a new process arrives or when a blocked process becomes unblocked, and also when a process with a higher priority arrives and preempts the currently executing process.