AIM:
To write a C program in Linux operating systems for implementing the first come first serve scheduling algorithm.
ALGORITHM:
Step 1: Start the program.
Step 2: Read the needed variables and the number of process.
Step 3: Read the burst time for all process.
Step 4: Read the arrival time (AT).
Step 5: Calculate the waiting time and turn around time and display it.
Step 6: Calculate the average waiting time and average total turnaround time and display it.
Step 7: Stop the program.
PROGRAM:
#include
#include
typedef struct pcb
{
int pid, bt, bt_bal, tat, wt;
} PCB;
int main()
{
PCB pr[10];
int i,j,k,n,tq;
int sum_bt=0,sum_tat=0,sum_wt=0;
int gantt[3][50];
printf("\n\nFCFS Scheduling \n");
printf("\nEnter the no. of process : ");
scanf("%d",&n);
for(i=0;i
{
printf("\nEnter burst time of the process %d: ",i+1);
pr[i].pid = i+1;
scanf("%d", &pr[i].bt);
}
k=0;
for( i=0;i
{
sum_bt += pr[i].bt;
pr[i].tat = sum_bt;
pr[i].wt = pr[i].tat - pr[i].bt;
sum_wt += pr[i].wt;
sum_tat += pr[i].tat;
gantt[0][k] = pr[i].pid;
gantt[1][k] = sum_bt;
gantt[2][k] = sum_bt - pr[i].bt;
k++;
}
printf("\n\nFCFS Scheduling \n");
printf("PID: ");
for( i=0; i
printf("%4d",gantt[0][i]);
printf("\nBTime:");
for( i=0; i
printf("%4d",pr[i].bt);
printf("\n\nGANTT Chart\n\n");
printf("PID: ");
for( i=0; i
printf("%4d",gantt[0][i]);
printf("\nTime: ");
for( i=0; i
printf("%4d",gantt[1][i]);
printf("\n\nWTime:");
for( i=0; i
printf("%4d",gantt[2][i]);
printf("\n\nTotal waiting time = %d\n",sum_wt);
printf("Average waiting time = %.2f\n",(float)sum_wt/n);
printf("\nTotal turn around time = %d\n",sum_tat);
printf("Average turn around time = %.2f\n\n",(float)sum_tat/n);
return 0;
}
SAMPLE OUTPUT:
[it65@AntiViruS ~]$ cc fcfs.c
[it65@AntiViruS ~]$ ./a.out
FCFS Scheduling
Enter the no. of process : 3
Enter burst time of the process 1: 24
Enter burst time of the process 2: 3
Enter burst time of the process 3: 3
FCFS Scheduling
PID: 1 2 3
BTime: 24 3 3
GANTT Chart-
PID: 1 2 3
Time: 24 27 30
WTime: 0 24 27
Total waiting time = 51
Average waiting time = 17.00
Total turn around time = 81
Average turn around time = 27.00
RESULT:
Thus the Linux program for implementing first come first serve scheduling algorithm has been executed and the output is verified successfully.
No comments:
Post a Comment