0% found this document useful (0 votes)
3K views4 pages

FCFS (First Come, First Served) Scheduling Algorithm in CPP

Realization of FCFS scheduling algorithm in C++(Department of Computer Science ,Manipal Institute Of Technology ,Manipal -576104 India)

Uploaded by

mitprasoon
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views4 pages

FCFS (First Come, First Served) Scheduling Algorithm in CPP

Realization of FCFS scheduling algorithm in C++(Department of Computer Science ,Manipal Institute Of Technology ,Manipal -576104 India)

Uploaded by

mitprasoon
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<iostream.

h>
#include<conio.h>
#include<stdio.h>
#include<alloc.h>
#include<string.h>
#include<process.h>
//node declaration
struct node0
{
int arrTime;
int procNo;
int burstTime;
int waitTime;
int cpuTime;
struct node0 *next;
};

typedef struct node0 *node;

node getnode()
{
node x=(node)malloc(sizeof(struct node0));
if(x==NULL)
{
printf("Memory not allocated\n");
return NULL;
}
x->next=NULL;
x->arrTime=0;
x->procNo=0;
x->burstTime=0;
x->waitTime=0;
x->cpuTime=0;

return x;
}

node insert(node head,node obj)


{

if(head==NULL)
{
head=obj;
return head;
}

node cur=head;

while(cur->next!=NULL)
cur=cur->next;

cur->next=obj;
return head;
}
node getCurrProcess(node head)
{
node cur=head;
while(cur->burstTime==0)
cur=cur->next;

return cur;
}

void incrementWaitTime(node head,node currProcess,int currtime)


{
node cur=head;
while(cur!=NULL)
{
if(cur!=currProcess&&cur->burstTime!=0&&cur->arrTime<=currtime)
cur->waitTime++;
cur=cur->next;
}
}

void display(node head)


{
while(head!=NULL)
{

cout<<"\nArrival Time= "<<head->arrTime;


cout<<"\nProcedure Number= "<<head->procNo;
cout<<"\nBurst Time= "<<head->burstTime;
cout<<"\nWait Time= "<<head->waitTime;
cout<<"\nCPU Time= "<<head->cpuTime;
head=head->next;
}
}

void main()
{
clrscr();
node head=getnode(),obj,currProcess;
int input,totalTime=0,currTime=0;

int arr[10];
int iarr=0;

obj=getnode();

cout<<"\nDo you have any process (1/0)";


cin>>input;

if(input==1)
{
cout<<"\nArrival time is 0";
head->arrTime=0;

cout<<"\nEnter process number ";


cin>>input;
head->procNo=input;

cout<<"Enter burst Time ";


cin>>input;
head->burstTime=input;
totalTime=totalTime+input;
}
else
{
cout<<"\nNo process initiated";
getch();
exit(0);
}
while(totalTime!=-1)
{
cout<<"\n\nDo you have any other process (1/0)";
cin>>input;

if(input==0)
{
currTime++;
cout<<"\nArrival Time is:->"<<currTime;
currProcess=getCurrProcess(head);
arr[iarr]=currProcess->procNo;
iarr++;
cout<<"\nProcess currently executing is:->"<<currProcess->procNo;
currProcess->burstTime--;
cout<<"\nTime left in completion of this process:-
>"<<currProcess->burstTime;
currProcess->cpuTime++;

incrementWaitTime(head,currProcess,currTime);
totalTime--;
}

else
{
if(input==1)
{
obj=getnode();
cout<<"\nArrival Time is:->"<<currTime;
obj->arrTime=currTime;

cout<<"\nEnter process number";


cin>>input;
obj->procNo=input;

cout<<"Enter burst Time";


cin>>input;
obj->burstTime=input;
totalTime=totalTime+input;
insert(head,obj);
}
}
}

cout<<"\n\n";
clrscr();

cout<<endl<<"Gauntt Chart\n\n";
cout<<endl<<"0";
int d=1;
for(int k=0;k<iarr-1;k++)
{ textcolor(d);
cprintf("%c%c",char(219),char(219));
if(arr[k]!=arr[k+1]&&k!=iarr-1)
{
cout<<k+1;//<<arr[k+1];
d+=1;
}
}
cout<<endl;
d=1;
for( k=0;k<iarr-1;k++)
{ textcolor(d);
cprintf(" ");
if(arr[k]!=arr[k+1]&&k!=iarr-1)
{
cprintf("P%d",arr[k]);//<<arr[k+1];
d+=1;
}
}

cout<<endl;
/*
for( k=0;k<iarr-1;k++)
{
if(arr[k]!=arr[k+1])
cout<<"P"<<arr[k];//<<arr[k+1];
cout<<" ";
}
*/

cout<<endl<<endl<<endl;

node cur=head;
float count=0,avgwait=0,avgtat=0;
while(cur!=NULL)
{
cout<<"\nProcess no:->"<<cur->procNo<<"\t"<<"Waiting time:->"<<cur-
>waitTime<<"\t"<<"tat Time:->"<<cur->waitTime+cur->cpuTime;
cout<<"\n";
avgwait+=cur->waitTime;//-cur->arrTime;
avgtat+=cur->waitTime+cur->cpuTime;//-cur->arrTime;
count++;
cur=cur->next;
}

cout<<"\nAverage waiting time:->"<<(avgwait/count)<<" ms";


cout<<"\nAverage turnsround time:->"<<(avgtat/count)<<" ms";

getch();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy