CPU Scheduling Process Burst Time Priority P1 P2 P3 P4 P5 5 24 16 10 3 2 5 1 3 4 FCFS Algorithm
CPU Scheduling Process Burst Time Priority P1 P2 P3 P4 P5 5 24 16 10 3 2 5 1 3 4 FCFS Algorithm
FCFS algorithm:
Implementation
1- Input the processes along with their burst time (bt).
2- Find waiting time (wt) for all processes.
3- As first process that comes need not to wait so
waiting time for process 1 will be 0 i.e. wt[0] = 0.
4- Find waiting time for all other processes i.e. for
process i ->
wt[i] = bt[i-1] + wt[i-1] .
5- Find turnaround time = waiting_time + burst_time
for all processes.
6- Find average waiting time =
total_waiting_time / no_of_processes.
7- Similarly, find average turnaround time =
total_turn_around_time / no_of_processes.
C++ Code:
// Driver code
int main()
{
//process id's
int processes[] = { 1, 2, 3};
int n = sizeof processes / sizeof processes[0];
findavgTime(processes, n, burst_time);
return 0;
}
Output:
SJF algorithm: