1. Trang chủ
  2. » Công Nghệ Thông Tin

Name: FCFS Scheduling Algorithm

5 671 3
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 11,48 KB

Nội dung

Name: FCFS Scheduling Algorithm

//**************************************// Name: FCFS Scheduling Algorithm// Description:This code implements the First come First Served Scheduling Algorithm. It gets the number of processes and the process name, burst time and arrival time for each user from the user. It then sorts the processes depending upon the arrival time. Calculates and displays the average turn around time and waiting time.Then it will display the Gantt chart.// By: Sathya Priya//// Inputs:1. Number of processes//2. Process name//3. Burst Time//4. Arrival Time////This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=11821&lngWId=3//for details.//**************************************/* FIRST COME FIRST SERVED SCHEDULING ALGORITHM*///PREPROCESSOR DIRECTIVES#include<stdio.h>#include<conio.h>#include<string.h>//GLOBAL VARIABLES - DECLARATIONint n,Bu[20],Twt,Ttt,A[10],Wt[10],w;float Awt,Att;char pname[20][20],c[20][20];//FUNCTION DECLARATIONS void Getdata();void Gantt_chart();void Calculate();void fcfs();//GETTING THE NUMBER OF PROCESSES AND THE BURST TIME AND ARRIVAL TIME FOR EACH PROCESSvoid Getdata(){int i;printf("\n Enter the number of processes: ");scanf("%d",&n);for(i=1;i<=n;i++){fflush(stdin);printf("\n\n Enter the process name: ");scanf("%s",&pname[i]);printf("\n Enter The BurstTime for Process %s = ",pname[i]);scanf("%d",&Bu[i]);printf("\n Enter the Arrival Time for Process %s =",pname[i]);scanf("%d",&A[i]);}}//DISPLAYING THE GANTT CHARTvoid Gantt_chart(){int i; printf("\n\n\t\t\tGANTT CHART\n");printf("\n-----------------------------------------------------------\n");for(i=1;i<=n;i++)printf("|\t%s\t",pname[i]);printf("|\t\n");printf("\n-----------------------------------------------------------\n");printf("\n");for(i=1;i<=n;i++)printf("%d\t\t",Wt[i]);printf("%d",Wt[n]+Bu[n]);printf("\n-----------------------------------------------------------\n");printf("\n"); }//CALCULATING AVERAGE WAITING TIME AND AVERAGE TURN AROUND TIMEvoid Calculate(){int i;//For the 1st processWt[1]=0;for(i=2;i<=n;i++){Wt[i]=Bu[i-1]+Wt[i-1];}for(i=1;i<=n;i++){ Twt=Twt+(Wt[i]-A[i]);Ttt=Ttt+((Wt[i]+Bu[i])-A[i]);}Att=(float)Ttt/n;Awt=(float)Twt/n;printf("\n\n Average Turn around time=%3.2f ms ",Att); printf("\n\n AverageWaiting Time=%3.2f ms",Awt);}//FCFS Algorithmvoid fcfs(){int i,j,temp, temp1;Twt=0;Ttt=0;printf("\n\n FIRST COME FIRST SERVED ALGORITHM\n\n");for(i=1;i<=n;i++){for(j=i+1;j<=n;j++){if(A[i]>A[j]){temp=Bu[i];temp1=A[i];Bu[i]=Bu[j];A[i]=A[j]; Bu[j]=temp;A[j]=temp1;strcpy(c[i],pname[i]);strcpy(pname[i],pname[j]);strcpy(pname[j],c[i]);}}}Calculate();Gantt_chart();}void main(){int ch;//clrscr();Getdata();fcfs();getch();} . //**************************************// Name: FCFS Scheduling Algorithm/ / Description:This code implements the First come First Served Scheduling Algorithm. It gets the. Time=%3.2f ms",Awt);}/ /FCFS Algorithmvoid fcfs( ){int i,j,temp, temp1;Twt=0;Ttt=0;printf(" FIRST COME FIRST SERVED ALGORITHM n ");for(i=1;i<=n;i++){for(j=i+1;j<=n;j++){if(A[i]>A[j]){temp=Bu[i];temp1=A[i];Bu[i]=Bu[j];A[i]=A[j]; Bu[j]=temp;A[j]=temp1;strcpy(c[i],pname[i]);strcpy(pname[i],pname[j]);strcpy(pname[j],c[i]);}}}Calculate();Gantt_chart();}void

Ngày đăng: 12/09/2012, 16:40

TỪ KHÓA LIÊN QUAN

w