-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.c
38 lines (36 loc) · 1.18 KB
/
time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include "headers.h"
/* Calculates wait time for all processes in a Queue
* Wait time is the amount of time a process needs to wait before it is executed on the CPU
* The wait time of the first process is zero
* The wait time of a process is the sum of the wait time and burst time of the previous process
* waitTime[ i ] = waitTime[ i - 1 ] + burstTime[ i - 1 ]
*/
void calculateWaitTime(Queue *q)
{
node *ptr = q->front;
if (ptr == NULL)
return;
while (ptr->next != NULL)
{
ptr->next->waitTime = ptr->waitTime + ptr->burstTime;
ptr = ptr->next;
}
}
/* Calculates turnaround time for all processes in a Queue
* Turnaround time is the time interval from the submission of a process to the completion of the process
* The turnaround time of a process is the sum of the wait time and burst time of the process
* turnAroundTime[ i ] = waitTime[ i ] + burstTime[ i ]
*/
void calculateTurnAroundTime(Queue *q)
{
node *ptr = q->front;
if (ptr == NULL)
return;
while (ptr!= NULL)
{
ptr->turnAroundTime = ptr->burstTime + ptr->waitTime;
ptr = ptr->next;
}
}