0% found this document useful (0 votes)
5 views2 pages

CPU Scheduling Algorithms in C

The document contains two programs for CPU scheduling algorithms: FCFS (First-Come, First-Served) and Round Robin. The FCFS program calculates and displays the waiting time and turnaround time for a given number of processes based on their burst times. The Round Robin program computes the total waiting time for processes using a specified time quantum.

Uploaded by

harshitraj1324ha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

CPU Scheduling Algorithms in C

The document contains two programs for CPU scheduling algorithms: FCFS (First-Come, First-Served) and Round Robin. The FCFS program calculates and displays the waiting time and turnaround time for a given number of processes based on their burst times. The Round Robin program computes the total waiting time for processes using a specified time quantum.

Uploaded by

harshitraj1324ha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Operating Systems Laboratory Programs with Output

FCFS Scheduling
Program Code:

// FCFS CPU Scheduling


#include <stdio.h>
int main() {
int n, i;
int bt[10], wt[10]={0}, tat[10]={0};
printf("Enter number of processes: ");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("Enter burst time of P%d: ", i+1);
scanf("%d",&bt[i]);
}
for(i=1;i<n;i++)
wt[i] = wt[i-1] + bt[i-1];
for(i=0;i<n;i++)
tat[i] = wt[i] + bt[i];
printf("\nProcess\tWT\tTAT\n");
for(i=0;i<n;i++)
printf("P%d\t%d\t%d\n", i+1, wt[i], tat[i]);
return 0;
}

Output:

Sample Output:
Enter number of processes: 3
Enter burst time of P1: 5
Enter burst time of P2: 3
Enter burst time of P3: 8

Process WT TAT
P1 0 5
P2 5 8
P3 8 16

Round Robin Scheduling


Program Code:
// Round Robin Scheduling
#include <stdio.h>
int main() {
int n, tq, bt[10], rt[10], wt=0, t=0;
printf("Enter number of processes: ");
scanf("%d",&n);
printf("Enter time quantum: ");
scanf("%d",&tq);
for(int i=0;i<n;i++){
printf("Enter burst time of P%d: ",i+1);
scanf("%d",&bt[i]);
rt[i]=bt[i];
}
while(1){
int done=1;
for(int i=0;i<n;i++){
if(rt[i]>0){
done=0;
if(rt[i]>tq){
t+=tq;
rt[i]-=tq;
} else {
t+=rt[i];
wt+=t-bt[i];
rt[i]=0;
}
}
}
if(done) break;
}
printf("Total Waiting Time = %d", wt);
return 0;
}

Output:

Sample Output:
Enter number of processes: 2
Enter time quantum: 2
Enter burst time of P1: 5
Enter burst time of P2: 4
Total Waiting Time = 7

You might also like