0% found this document useful (0 votes)
32 views

Implement CPU Scheduling Policies

The document discusses the First Come First Serve (FCFO) CPU scheduling algorithm. FCFS is the simplest algorithm that processes tasks in the order that they arrive in the ready queue. Newly arrived tasks are added to the end of the queue. The waiting time is calculated as the turnaround time minus the arrival time. Code is provided to calculate the waiting time, turnaround time, average waiting time, and average turnaround time for a sample input of processes.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Implement CPU Scheduling Policies

The document discusses the First Come First Serve (FCFO) CPU scheduling algorithm. FCFS is the simplest algorithm that processes tasks in the order that they arrive in the ready queue. Newly arrived tasks are added to the end of the queue. The waiting time is calculated as the turnaround time minus the arrival time. Code is provided to calculate the waiting time, turnaround time, average waiting time, and average turnaround time for a sample input of processes.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Implement CPU Scheduling Policies:-

1.FCFS :- (FIRST COME FIRST SERVE) is an operating system


scheduling algorithm that automatically executes queued requests and
processes in order of their arrival. It is the easiest and simplest CPU scheduling
algorithm. In this type of algorithm, processes which requests the CPU first get
the CPU allocation first. This is managed with a FIFO queue.

Waiting time = Turnaround Time – Arrival Time.


Turnaround time = Burst Time – Waiting Time.
Now, code of FCFS:-
#include <stdio.h>
int waitingtime(int proc[], int n,
int burst_time[], int wait_time[]) {
wait_time[0] = 0;
for (int i = 1; i < n ; i++ )
wait_time[i] = burst_time[i-1] + wait_time[i-1] ;
return 0;
}
int turnaroundtime( int proc[], int n,
int burst_time[], int wait_time[], int tat[]) {
int i;
for ( i = 0; i < n ; i++)
tat[i] = burst_time[i] + wait_time[i];
return 0;
}
int avgtime( int proc[], int n, int burst_time[]) {
int wait_time[n], tat[n], total_wt = 0, total_tat = 0;
int i;
waitingtime(proc, n, burst_time, wait_time);
turnaroundtime(proc, n, burst_time, wait_time, tat);
printf("Processes Arrival Bust Turn around \n");
for ( i=0; i<n; i++) {
total_wt = total_wt + wait_time[i];
total_tat = total_tat + tat[i];
printf(" %d\t \t\t%d\t\t%d \t\t\t%d\n", i+1, burst_time[i], wait_time[i],
tat[i]);
}
printf("Average waiting time = %f\n", (float)total_wt / (float)n);
printf("Average turn around time = %f\n", (float)total_tat / (float)n);
return 0;
}
int main() {
int proc[] = { 1, 2,3};
int n = sizeof proc / sizeof proc[0];
int burst_time[] = {1, 2, 3};
avgtime(proc, n, burst_time);
return 0;
}

You might also like