SRTF:最短剩余时间优先调度算法

SRTF, Which Stands for Shortest Remaining Time First is a scheduling algorithm used in Operating Systems, which can also be called as the preemptive version of the SJF scheduling algorithm. The process which has the least processing time remaining is executed first. As it is a preemptive type of schedule, it is claimed to be better than SJF scheduling Algorithm.

SRTF ,它是最短的剩余时间优先 ,它是操作系统中使用的调度算法,也可以称为SJF调度算法的抢先版本。 首先执行剩余处理时间最少的过程。 由于它是调度的优先类型,因此它比SJF调度算法要好。

Let's understand this with the help of an example. Suppose we have the following 3 processes with process ID's P1, P2, and P3 and they arrive into the CPU in the following manner:

让我们借助示例来理解这一点。 假设我们有以下三个进程,进程ID为P1P2P3 ,它们以以下方式到达CPU:

SRTF:最短剩余时间优先调度算法_第1张图片

Gant Chart:

甘特图:

SRJF algorithm

Explanation:

说明:

  • At the 0th unit of the CPU, we have only process P1, so it gets executed for the 1-time unit.

    在CPU的 0 单元中,我们只有进程P1 ,因此它以1次单元执行。

  • At the 1st unit of the CPU, the Process P2 also arrives. Now, the P1 needs 7 more units more to be executed, and P2 needs only 2 units. So, P2 is executed by preempting P1.

    在CPU的第一个单元上,过程P2也到达。 现在, P1需要多执行7个单元,而P2仅需要2个单元。 因此,P2被抢占P1执行。

  • P2 gets completed at time unit 3, and unit now no new process has arrived. So, after the completion of P2, again P1 is sent for execution.

    P2在第3单元的时间完成,并且现在没有新的进程到达。 因此,在P2完成之后,再次发送P1以便执行。

  • Now, P1 has been executed for one unit only, and we have an arrival of new process P3 at time unit 4. Now, the P1 needs 6-time units more and P3 needs only 3-time units. So, P3 is executed by preempting P1.

    现在,仅以一个单位执行P1 ,并且新的过程P3以时间单位4到达。现在, P1需要更多的6倍时间单位,而P3仅需要3倍时间单位。 因此,通过抢占P1来执行P3

  • P1 gets completed at time unit 7, and after that, we have the arrival of no other process. So again, P1 is sent for execution, and it gets completed at 13th unit.

    P1在时间单位7处完成,此后,我们没有其他进程到达。 因此,再次发送P1来执行,它以 13 单位完成。

SRTF:最短剩余时间优先调度算法_第2张图片
    Total Turn Around Time = 13 + 2 + 3
                = 18 milliseconds
    Average Turn Around Time= Total Turn Around Time / Total No. of Processes
                = 18 / 3
                = 6 milliseconds

    Total Waiting Time = 5 + 0 + 0
                = 5 milliseconds
    Average Waiting Time = Total Waiting Time / Total No. of Processes
                = 5 / 3
                = 1.67 milliseconds


翻译自: https://www.includehelp.com/operating-systems/srtf-shortest-remaining-time-first-scheduling-algorithm.aspx

你可能感兴趣的:(算法,java,python,操作系统,linux)