Skip to content

Latest commit

 

History

History
15 lines (12 loc) · 1.59 KB

File metadata and controls

15 lines (12 loc) · 1.59 KB

Shortest Remaining Time First (SRTF) is a CPU scheduling algorithm that is similar to SJF, but with preemption. In this algorithm, the process with the shortest remaining burst time is executed first. If a new process arrives with a shorter burst time than the currently executing process, the currently executing process is preempted and the new process is executed first.

Here is a high-level overview of how the SRTF algorithm works:

  • When a process arrives, its length is determined (either by its burst time or an estimate based on past behavior).
  • The process is added to the ready queue.
  • The CPU is assigned to the process with the shortest remaining burst time 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 shorter burst time 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 shortest remaining burst time in the ready queue.
  • When a blocked process becomes unblocked (e.g., I/O completes), its remaining burst time is updated and it is moved back to the ready queue.
  • Steps 3-8 are repeated until all processes have completed.

The SRTF algorithm can be implemented using a priority queue, which maintains the order of processes based on their remaining burst time. Processes with shorter remaining burst times have higher priority and are executed first.