0% found this document useful (0 votes)
24 views5 pages

1 AIM: Fcfs Scheduling Program

os

Uploaded by

ksai.mb
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)
24 views5 pages

1 AIM: Fcfs Scheduling Program

os

Uploaded by

ksai.mb
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/ 5

1 AIM: Fcfs Scheduling program

#include<stdio.h>

int main(){

int n,i,pid[10],bt[10],wt[10],tat[10];

float twt=0,Tat=0,att,awt;

printf("enter the processors");

scanf("%d",&n);

for(i=0;i<n;i++){

printf("enter processor id of %d:",i+1);

scanf("%d",&pid[i]);

for(i=0;i<n;i++){

printf("enter brust time of %d:",i+1);

scanf("%d",&bt[i]);

wt[0]=0;

for(i=1;i<n;i++){

wt[i]=bt[i-1]+wt[i-1];

printf("processid bt wt tat\n");

for(i=0;i<n;i++)
{

printf("%d\t\t",pid[i]);

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

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

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

printf("\n");

twt+=wt[i];

Tat+=(wt[i]+bt[i]);

awt=twt/n;

att=Tat/n;

printf("%f",awt);

printf("%f",att);

Output:

enter the processors2

enter processor id of 1:3

enter processor id of 2:6

enter brust time of 1:4

enter brust time of 2:5

processid bt wt tat

3 4 0 4
6 5 4 9

2.0000006.500000

2 AIM:Sjf Scheduling program

#include<stdio.h>

int main()

int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,totalT=0,pos,temp;

float avg_wt,avg_tat;

printf("Enter number of process:");

scanf("%d",&n);

printf("\nEnter Burst Time:\n");

for(i=0;i<n;i++){

printf("p%d:",i+1);

scanf("%d",&bt[i]);

p[i]=i+1;

for(i=0;i<n;i++)

pos=i;

for(j=i+1;j<n;j++)

{
if(bt[j]<bt[pos])

pos=j;

temp=bt[i];

bt[i]=bt[pos];

bt[pos]=temp;

temp=p[i];

p[i]=p[pos];

p[pos]=temp;

wt[0]=0;

for(i=1;i<n;i++){

wt[i]=0;

for(j=0;j<i;j++)

wt[i]+=bt[j];

total+=wt[i];

avg_wt=(float)total/n;

printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");

for(i=0;i<n;i++){

tat[i]=bt[i]+wt[i];

totalT+=tat[i];
printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);

avg_tat=(float)totalT/n;

printf("\n\nAverage Waiting Time=%f",avg_wt);

printf("\nAverage Turnaround Time=%f",avg_tat);

Output:

Enter number of process:2

Enter Burst Time:

p1:5

p2:7

Process Burst Time Waiting Time Turnaround Time

p1 5 0 5

p2 7 5 12

Average Waiting Time=2.500000

Average Turnaround Time=8.500000

You might also like