You are on page 1of 6

Ex No: 01 07-06-2012 AIM:

FIRST IN FIRST OUT SCHEDULING (WITHOUT ARRIVAL TIME)

To write a C program to implement First in First out scheduling with arrival time zero. ALGORITHM: Step 1: START Step 2: Declare the variables. Step 3: Get the Total number of processes(n). Step 4: Get n burst time using loop. Step 5: Calculate Waiting Time and Turn Around Time. Step 6: Calculate Total Waiting time and Total Turn Around Time. Step 7: Print all the details. Step 8: STOP CODING:
#include<stdio.h> main() { int i,n,BT[10],WT[10],TAT[10]; float twt=0, ttat=0; printf("\n Enter The Total processes : "); scanf("%d",&n); printf("\nEnter the Burst Time for %d processes...\n",n); WT[0]=0; for(i=0;i<n;i++) { scanf("%d",&BT[i]); WT[i+1]=WT[i]+BT[i]; TAT[i]=WT[i]+BT[i]; ttat+=TAT[i]; twt+=WT[i]; } printf("\nProcess\tBT\tWT\tTAT\n"); for(i=0;i<n;i++) printf("\nP[%d]\t%d\t%d\t%d\t",i,BT[i],WT[i],TAT[i]); printf("\n\nAverage Waiting Time : %.2f Milli Seconds",twt/n); printf("\nAverage Turn Around Time : %.2f Milli seconds",ttat/n); printf("\n\n"); }

OUTPUT:
Enter The Total processes : 3 Enter the Burst Time for 3 processes... 24 3 3 Process BT WT TAT P1 24 0 24 P2 3 24 27 P3 3 27 30 Average Waiting Time: 17.00 Milli Seconds Average Turn Around Time: 27.00 Milli Seconds

RESULT:
Thus a program to implement First In First Out scheduling algorithm without arrival time was coded and verified.

Ex No : 02 21-06-2012 AIM:

FIRST IN FIRST OUT SCHEDULING WITH ARRIVAL TIME

To write a C program to implement First In First Out scheduling with Arrival Time.

ALGORITHM: Step 1: START Step 2: Declare the variables. Step 3: Get the Total number of processes. Step 4: Get the Burst Time and Arrival Time for processes using loop. Step 5: Calculate Start time, End time, Waiting time, Turn Around time. Step 6: Calculate Total Waiting Time and Total Turn Around time. Step 7: Print all the details. Step 8: STOP CODING:
#include<stdio.h> main() { int i,n,AT[20], BT[20], ST[20], ET[20], WT[20], TAT[20]; float twt=0,ttat=0; printf("\nEnter Total Number of Processes : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\n Process-%d",i+1); printf("\nEnter the burst time : "); scanf("%d",&BT[i]); printf("\n Enter the arrival time : "); scanf("%d",&AT[i]); } ST[0]=AT[0]; printf("\nProcess AT\tBT\tST\tET\tWT\tTAT\n"); for(i=0;i<n;i++) { ET[i]=ST[i]+BT[i]; ST[i+1]=ET[i]; WT[i]=ST[i]-AT[i]; TAT[i]=BT[i]+WT[i]; twt+=WT[i]; ttat+=TAT[i]; printf("\nP[%d]\t%d\t%d\t%d\t%d\t%d\t%d",i+1,AT[i],BT[i],ST[i] ,ET[i],WT[i],TAT[i]); }

printf("\n\nAverage Waiting Time : %.2f Milli Seconds",twt/n); printf("\nAverage Turn Around Time : %.2f Milli Seconds",ttat/n); printf("\n\n"); }

OUTPUT:
Process-1 Enter the burst time : 24 Enter the arrival time : 0 Process-2 Enter the burst time : 3 Enter the arrival time : 0 Process-3 Enter the burst time : 3 Enter the arrival time : 1 Process AT P[1] P[2] P[3] 0 0 1 BT 24 3 3 ST 0 24 27 ET 24 27 30 WT 0 24 26 TAT 24 27 29

Average Waiting Time : 16.67 Milli Seconds Average Turn Around Time : 26.67 Milli Seconds

RESULT:
Thus a program to implement FIFO with arrival time was coded and verified.

Ex No : 03 05-07-2012 AIM:

SHORTEST JOB FIRST SCHEDULING

To write a C program to implement Shortest Job First Scheduling algorithm.

ALGORITHM:
Step 1: START Step 2: Declare the variables. Step 3: Get the Total number of processes. Step 4: Get the Burst Time for Processes Step 5: Calculate Waiting time, Start and End Time, Turn Around Time. Step 6: Calculate Total Waiting Time and Total Turn Around Time. Step 7: Print All the Details. Step 8: STOP

CODING:
#include<stdio.h> main() { int i,j,n,BT[10],WT[10],TAT[10],AT[10],ST[10],ET[10],P[10]; float avg_wt=0,avg_tat=0,temp; printf("\n Enter Total Processes : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nEnter the BT for P[%d] : ",i+1); scanf("%d",&BT[i]); P[i]=i+1; } WT[0]=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(BT[i]>BT[j]) { temp=BT[i]; BT[i]=BT[j]; BT[j]=temp; temp=P[i]; P[i]=P[j]; P[j]=temp; }

} WT[i+1]=WT[i]+BT[i]; TAT[i]=BT[i]+WT[i]; } printf("\nProcess\tBT\tWT\tTAT\n"); for(i=0;i<n;i++) { printf("\nP[%d]\t%d\t%d\t%d",P[i],BT[i],WT[i],TAT[i]); avg_wt+=WT[i]; avg_tat+=TAT[i]; } printf("\n\nAverage Waiting Time : %.2f Milli Seconds",avg_wt/n); printf("\n\Average Turn Around Time : %.2f Milli Seconds",avg_tat/n); printf("\n\n"); }

OUTPUT:

Enter Total Processes : 5 Enter the BT for P[1] : 5 Enter the BT for P[2] : 9 Enter the BT for P[3] : 4 Enter the BT for P[4] : 2 Enter the BT for P[5] : 15 Process BT P[4] P[3] P[1] P[2] P[5] 2 4 5 9 15 WT 0 2 6 11 20 TAT 2 6 11 20 35

Average Waiting Time : 7.80 Milli Seconds Average Turn Around Time : 14.80 Milli Seconds

RESULT:
Thus a program to implement Shortest Job First scheduling algorithm was coded and verified.

You might also like