This C program implements the First-Come, First-Served (FCFS) CPU scheduling algorithm. It prompts the user to input the number of jobs along with their arrival and service times, then calculates the start time, finish time, turnaround time, and normalized turnaround time for each job. Finally, it displays the results for each job in a formatted manner.
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 ratings0% found this document useful (0 votes)
7 views2 pages
Fcfs
This C program implements the First-Come, First-Served (FCFS) CPU scheduling algorithm. It prompts the user to input the number of jobs along with their arrival and service times, then calculates the start time, finish time, turnaround time, and normalized turnaround time for each job. Finally, it displays the results for each job in a formatted manner.
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
/* 1.
write a c program using FCFS cpu scheduling algorithm */
#include<stdio.h> #include<conio.h> #define max 20 void main() { int arrival_time[max]; int service_time[max]; int start_time[max]; int finish_time[max]; int turnaround_time[max]; float normalised_turnaround_time[max]; int num_of_jobs,j; float avg_turn=0.0; printf("enter the no of jobs:\n"); scanf("%d",&num_of_jobs); for(j=0;j<num_of_jobs;j++) { printf("enter the arrival_time of j[%d] ",j+1); scanf("%d",&arrival_time[j]); printf("enter the service_time of j[%d] ",j+1); scanf("%d",&service_time[j]); } //caluculate turnaround time ,finish time and normalised turnaround time for(j=0;j<num_of_jobs;j++) { if(0>j-1) start_time[j]=0; start_time[j]=finish_time[j-1]; finish_time[j]=start_time[j]+service_time[j]; turnaround_time[j]=finish_time[j]-arrival_time[j]; normalised_turnaround_time[j]=(float)turnaround_time[j]/service_time[j]; avg_turn+=turnaround_time[j]; } clrscr(); for(j=0;j<num_of_jobs;j++) { printf("j[%d]:\t",j+1); printf("%d\t",arrival_time[j]); printf("%d\t",service_time[j]); printf("%d\t",start_time[j]); printf("%d\t",finish_time[j]); printf("%d\t",turnaround_time[j]); printf("%f\n",normalised_turnaround_time[j]); getch(); } }