Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 542
Marco Pietro Cirillo Avatar asked Oct 26 '12 21:10

Marco Pietro Cirillo


People also ask

What is waiting time and turnaround time?

TAT refers to the time taken by a process since it enters a ready queue for the process of execution till the completion (of its execution). WT refers to the total time that a process spends while waiting in a ready queue until it gets the CPU (for the I/O completion).


1 Answers

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.

like image 136
max Avatar answered Sep 28 '22 18:09

max