计算(非抢占式)FCFS 队列中的等待时间和周转时间 [英] Calculating Waiting Time and Turnaround Time in (non-preemptive) FCFS queue

查看:113
本文介绍了计算(非抢占式)FCFS 队列中的等待时间和周转时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有6个流程如下:

-- P0 --
  arrival time = 0 
  burst time = 10  

-- P1 --
  arrival time = 110 
  burst time = 210  

-- P2 --
  arrival time = 130 
  burst time = 70  

-- P3 --
  arrival time = 130 
  burst time = 70

-- P4 --
  arrival time = 130 
  burst time = 90

-- P5 --
  arrival time = 130 
  burst time = 50

如何计算每个流程的等待时间和周转时间?系统应该是非抢占式的(进程在完成之前获取 CPU).另外:这个系统中有 4 个逻辑处理器.

How can I calculate the waiting time and turnaround time for each process? The system should be non-preemptive (the process gets the CPU until it's done). Also: there are 4 logical processors in this system.

假设 systemTime 是当前系统的正常运行时间,到达时间是相对的.即:到达时间为 0 表示进程在系统启动时开始;到达时间为 130 表示进程在系统启动后 130 个单位启动.

Assume systemTime is the current systems uptime, and arrivalTime is relative to that. ie: an arrivalTime of 0 means the process starts when the system does; an arrivalTime of 130 means the process is started 130 units after the system starts.

这是否正确:waitingTime = (systemTime -arrivalTime) ?

我认为这是因为 systemTime -arrivalTime 是进程在 fcfs 队列中等待使用 CPU 的时间(或者这是错误的吗?)

My reasoning for thinking this is that systemTime - arrivalTime is the time the process has been waiting in the fcfs queue to use the CPU (or is this wrong?)

对于周转时间,我想的是:turnaroundTime = burstTime + waitingTime,因为等待时间和突发时间应该是完成该过程的总时间.虽然我不知道我的直觉是否正确.

And for turnaround time, I was thinking something like: turnaroundTime = burstTime + waitingTime, since the waiting time and the burst time should be the total time to complete the process. Though once again I don't know if my intuition is correct.

任何和所有的阅读都将不胜感激!

Any and all readings would be greatly appreciated!

推荐答案

对于非抢占式系统,

waitingTime = startTime - arrivalTime

turnaroundTime = burstTime + waitingTime = finishTime- arrivalTime

startTime = 进程开始执行的时间

startTime = Time at which the process started executing

finishTime = 进程完成执行的时间

finishTime = Time at which the process finished executing

您可以跟踪系统中当前经过的时间(timeElapsed).一开始将所有处理器分配给一个进程,然后执行直到最短的进程执行完毕.然后将这个空闲的处理器分配给队列中的下一个进程.这样做直到队列为空并且所有进程都执行完毕.另外,每当一个进程开始执行时,记录它的startTime,当完成时,记录它的finishTime(都与timeElapsed相同).这样你就可以计算出你需要什么.

You can keep track of the current time elapsed in the system(timeElapsed). Assign all processors to a process in the beginning, and execute until the shortest process is done executing. Then assign this processor which is free to the next process in the queue. Do this until the queue is empty and all processes are done executing. Also, whenever a process starts executing, recored its startTime, when finishes, record its finishTime (both same as timeElapsed). That way you can calculate what you need.

这篇关于计算(非抢占式)FCFS 队列中的等待时间和周转时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆