Created
October 30, 2016 12:50
-
-
Save ssavi/f72263a92402caeecc61436eb2172344 to your computer and use it in GitHub Desktop.
Operating System ( Lab Code.c )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<process.h> | |
int main() | |
{ | |
char p[10][5]; | |
int tot=0,wt[10], pt[10], i,n; | |
double avg=0; | |
printf("enter no of processes: "); | |
scanf("%d",&n); | |
for(i=0;i<n;i++) | |
{ | |
printf("enter process%d name: ",i+1); | |
scanf("%s",&p[i]); | |
printf("enter process time :"); | |
scanf("%d",&pt[i]); | |
} | |
wt[0]=0; | |
for(i=1;i<n;i++) | |
{ | |
wt[i]=wt[i-1]+pt[i-1]; | |
tot=tot+wt[i]; | |
} | |
avg=(double)tot/n; | |
printf("p_name\t P_time\t w_time\n"); | |
for(i=0;i<n;i++) | |
printf("%s\t%d\t%d\n",p[i],pt[i],wt[i]); | |
printf("total waiting time=%d\n avg waiting time=%lf",tot,avg); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main() | |
{ | |
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat; | |
printf("Enter Total Number of Process: "); | |
scanf("%d",&n); | |
printf("\nEnter Burst Time and Priority\n"); | |
for(i=0;i<n;i++) | |
{ | |
printf("\nP[%d]\n",i+1); | |
printf("Burst Time: "); | |
scanf("%d",&bt[i]); | |
printf("Priority: "); | |
scanf("%d",&pr[i]); | |
p[i]=i+1; | |
} | |
for(i=0;i<n;i++) | |
{ | |
pos=i; | |
for(j=i+1;j<n;j++) | |
{ | |
if(pr[j]<pr[pos]) | |
pos=j; | |
} | |
temp=pr[i]; | |
pr[i]=pr[pos]; | |
pr[pos]=temp; | |
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=total/n; | |
total=0; | |
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time"); | |
for(i=0;i<n;i++) | |
{ | |
tat[i]=bt[i]+wt[i]; | |
total+=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=total/n; | |
printf("\n\nAverage Waiting Time = %d",avg_wt); | |
printf("\nAverage Turnaround Time = %d\n",avg_tat); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main() | |
{ | |
int i,j,n,time,remain,flag=0,time_quantum; | |
int wait_time=0,turnaround_time=0,arr[10],bt[10],rt[10]; | |
printf("Enter Total Process:\t "); | |
scanf("%d",&n); | |
remain=n; | |
for(i=0;i<n;i++) | |
{ | |
printf("Enter Arrival Time and Burst Time for Process Number %d :",i+1); | |
scanf("%d",&arr[i]); | |
scanf("%d",&bt[i]); | |
rt[i]=bt[i]; | |
} | |
printf("Enter Time Quantum:\t"); | |
scanf("%d",&time_quantum); | |
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n"); | |
for(time=0,i=0;remain!=0;) | |
{ | |
if(rt[i]<=time_quantum && rt[i]>0) | |
{ | |
time+=rt[i]; | |
rt[i]=0; | |
flag=1; | |
} | |
else if(rt[i]>0) | |
{ | |
rt[i]-=time_quantum; | |
time+=time_quantum; | |
} | |
if(rt[i]==0 && flag==1) | |
{ | |
remain--; | |
printf("P[%d]\t|\t%d\t|\t%d\n",i+1,time-arr[i],time-arr[i]-bt[i]); | |
wait_time+=time-arr[i]-bt[i]; | |
turnaround_time+=time-arr[i]; | |
flag=0; | |
} | |
if(i==n-1) | |
i=0; | |
else if(arr[i+1]<=time) | |
i++; | |
else | |
i=0; | |
} | |
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n); | |
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main() | |
{ | |
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp; | |
double 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=(double)total/n; | |
total=0; | |
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time"); | |
for(i=0;i<n;i++) | |
{ | |
tat[i]=bt[i]+wt[i]; | |
total+=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=(double)total/n; | |
printf("\n\nAverage Waiting Time = %lf",avg_wt); | |
printf("\nAverage Turnaround Time = %lf\n",avg_tat); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment