简体   繁体   中英

Calculating Waiting Time and Turnaround Time in (non-preemptive) FCFS queue

I have 6 processes as follows:

-- 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

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.

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.

Is this correct: waitingTime = (systemTime - arrivalTime) ?

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?)

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!

For non-preemptive system,

waitingTime = startTime - arrivalTime

turnaroundTime = burstTime + waitingTime = finishTime- arrivalTime

startTime = Time at which the process started executing

finishTime = Time at which the process finished executing

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.

wt = tt - cpu tm.
Tt = cpu tm + wt.

Where wt is a waiting time and tt is turnaround time. Cpu time is also called burst time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM