0% found this document useful (0 votes)
19 views4 pages

HDH

The document discusses three scheduling algorithms: 1) FCFS (First Come First Serve) which schedules processes based on arrival time such that the earliest process is executed first. It calculates average waiting time and turnaround time. 2) SJF (Shortest Job First) which schedules the process with the shortest burst/runtime time to priority. It also calculates average waiting time and turnaround time. 3) Priority scheduling where processes are scheduled based on priority levels with higher priority processes executed first.
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)
19 views4 pages

HDH

The document discusses three scheduling algorithms: 1) FCFS (First Come First Serve) which schedules processes based on arrival time such that the earliest process is executed first. It calculates average waiting time and turnaround time. 2) SJF (Shortest Job First) which schedules the process with the shortest burst/runtime time to priority. It also calculates average waiting time and turnaround time. 3) Priority scheduling where processes are scheduled based on priority levels with higher priority processes executed first.
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/ 4

FCFS

#include<stdio.h>

int main()

int bt[10],at[10],wait_Time_Sum=0,turn_Time_Sum=0;

int time=0,n,i,smallest,count=0;

printf("nhap so tien trinh : ");

scanf("%d",&n);

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

printf("nhap thoi gian den P%d : ",i+1);

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

printf("nhap thoi gian xu li P%d : ",i+1);

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

printf("\n\nTien trinh|Thoi gian den| thoi gian thuc hien|Thoi gian xu ly| thoi gian doi\n\n");

at[9]=9999;

int dem = 0;

while(count!=n) //End the loop when n process finish

smallest=9; // Checking For index of Process with smallest Arrival Time

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

{
if(at[i]<at[smallest] && bt[i]>0)

smallest=i;

//Index of Smallest Arrival Time stored in `smallest`

time+=bt[smallest]; //Incrementing Current Time

wait_Time_Sum+=time-at[smallest]-bt[smallest];

turn_Time_Sum+=time-at[smallest];

printf("P[%d]\t |\t%d\t|\t%d\t |\t%d\t |\t%d|\n",smallest+1,at[dem],bt[dem],time-


at[smallest],time-at[smallest]-bt[smallest]);

dem++;

bt[smallest]=0; //Making burst time of current Process 0 so that it won't run again

count++;

printf("\n average waiting time = %f",wait_Time_Sum*1.0/n);

printf("\n average turnaround time = %f\n",turn_Time_Sum*1.0/n);

return 0;

Sjf độc quyền

#include<stdio.h>

int main()

{
int time,bt[10],at[10],sum_bt=0,smallest,n,i;

int sum_turnaround=0,sum_wait=0;

printf("nhap so tien trinh : ");

scanf("%d",&n);

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

printf("nhap thoi gian den p%d : ",i+1);

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

printf("nhap thoi gian xu li P%d : ",i+1);

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

sum_bt+=bt[i];

bt[9]=9999;

printf("\n\nTien trinh|Thoi gian den| thoi gian thuc hien|Thoi gian xu ly| thoi gian doi\n\n");

int dem = 0;

for(time=0;time<sum_bt;)

smallest=9;

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

if(at[i]<=time && bt[i]>0 && bt[i]<bt[smallest])

smallest=i;

if(smallest==9)

{
time++;

continue;

printf("P[%d]\t |\t%d\t|\t%d\t |\t%d\t |\t%d|\n",smallest+1,at[dem],bt[dem],time+bt[smallest]-


at[smallest],time-at[smallest]);

dem++;

sum_turnaround+=time+bt[smallest]-at[smallest];

sum_wait+=time-at[smallest];

time+=bt[smallest];

bt[smallest]=0;

printf("\n\n average waiting time = %f",sum_wait*1.0/n);

printf("\n\n average turnaround time = %f",sum_turnaround*1.0/n);

return 0;

Priority

https://www.youtube.com/watch?v=DrKyRrvewqw

You might also like