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

Process Scheduling Algorithm

The document is a C program that simulates the First-Come, First-Served (FCFS) scheduling algorithm for process management. It prompts the user to input the number of processes, their IDs, and burst times, then calculates and displays the waiting time and turnaround time for each process. Finally, it computes and prints the average waiting time and average turnaround time.

Uploaded by

Jagadish Poudel
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)
3 views2 pages

Process Scheduling Algorithm

The document is a C program that simulates the First-Come, First-Served (FCFS) scheduling algorithm for process management. It prompts the user to input the number of processes, their IDs, and burst times, then calculates and displays the waiting time and turnaround time for each process. Finally, it computes and prints the average waiting time and average turnaround time.

Uploaded by

Jagadish Poudel
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
You are on page 1/ 2

//FCFS scheduling algorithm simulation.

#include <stdio.h>
int main()
{
int pid[15];
int bt[15];
int i,n;
printf("Enter the number of processes: ");
scanf("%d",&n);

printf("Enter process id of all the processes: ");


for(i=0;i<n;i++)
{
scanf("%d",&pid[i]);
}

printf("Enter burst time of all the processes: ");


for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}

int wt[n];
wt[0]=0;

//for calculating waiting time of each process


for(i=1; i<n; i++)
{
wt[i]= bt[i-1]+ wt[i-1];
}
printf("Process ID Burst Time Waiting Time TurnAround Time\n");
float twt=0.0;
float tat= 0.0;
for(i=0; i<n; i++)
{
printf("%d\t\t", pid[i]);
printf("%d\t\t", bt[i]);
printf("%d\t\t", wt[i]);

//calculating and printing turnaround time of each process


printf("%d\t\t", bt[i]+wt[i]);
printf("\n");

//for calculating total waiting time


twt += wt[i];

//for calculating total turnaround time


tat += (wt[i]+bt[i]);
}
float att,awt;

//for calculating average waiting time


awt = twt/n;

//for calculating average turnaround time


att = tat/n;
printf("Avg. waiting time= %f\n",awt);
printf("Avg. turnaround time= %f",att);
}

You might also like