//IMPLEMENTATION OF FCFS SCHEDULING
#include<stdio.h>
#include<malloc.h>
struct node
{
char name[15];
int btime,atime;
struct node *next;
};
int main()
{
struct node *head,*temp,*tp,*p;
int d,ch,n=0;
head=NULL;
do
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the name of the process:");
scanf("%s",&temp->name);
printf("\nEnter the arrival time:");
scanf("%d",&temp->atime);
printf("\nEnter the burst time:");
scanf("%d",&temp->btime);
temp->next=NULL;
if(temp==NULL)
printf("\nNode is not created..");
if(head==NULL)
head=temp;
else
{
if(temp->atime<head->atime)
{
temp->next=head;//swapping head and temp
head=temp;
}
else if(temp->atime>head->atime)
{
tp=head;
while((tp!=NULL) && (temp->atime>tp->atime))
{
p=tp;
tp=tp->next;
}
p->next=temp;
temp->next=tp;
}
}
printf("\nPress '1' to continue:");
scanf("%d",&ch);
}while(ch==1);
printf("\nGantt chart:");
if(head==NULL)
printf("\nList is empty...! ");
else
{
tp=head;
printf("\n");
printf("\t%s",tp->name);
tp=tp->next;
while(tp!=NULL)
{
printf("\t%s",tp->name);
tp=tp->next;
}
printf("\t%s",tp->name);
printf("\n");
tp=head;
printf("\n");
printf("0");
while(tp->next!=NULL)
{
n=n+tp->btime;
printf("\t%d",n);
tp=tp->next;
}
n=n+tp->btime;
printf("\t%d",n);
}
}
OUTPUT:
Enter the name of the process:P1
Enter the arrival time:0
Enter the burst time:4
Press '1' to continue:1
Enter the name of the process:P2
Enter the arrival time:3
Enter the burst time:1
Press '1' to continue:1
Enter the name of the process:P3
Enter the arrival time:4
Enter the burst time:2
Press '1' to continue:1
Enter the name of the process:P4
Enter the arrival time:6
Enter the burst time:3
Press '1' to continue:1
Enter the name of the process:P5
Enter the arrival time:8
Enter the burst time:2
Press '1' to continue:0
Gantt chart:
P1 P2
0
4
5
P3
7
P4
10
P5
12
(null)
// IMPLEMENTATION OF SJF SCHEDULING
#include<stdio.h>
#include<malloc.h>
struct node
{
char name[15];
int btime,atime;
struct node *next;
};
int main()
{
struct node *head,*temp,*tp,*p;
int d,ch,n=0;
head=NULL;
do
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the name of the process:");
scanf("%s",&temp->name);
printf("\nEnter the burst time:");
scanf("%d",&temp->btime);
temp->next=NULL;
if(temp==NULL)
printf("\nNode is not created..");
if(head==NULL)
head=temp;
else
{
if(temp->btime<head->btime)
{
temp->next=head;//swapping head and temp
head=temp;
}
}
if(temp->btime>head->btime)
{
tp=head;
while((tp!=NULL) && (temp->btime>tp->btime))
{
p=tp;
tp=tp->next;
}
p->next=temp;
temp->next=tp;
}
printf("\nPress '1' to continue:");
scanf("%d",&ch);
}while(ch==1);
printf("\nGantt chart:");
if(head==NULL)
printf("\nList is empty...! ");
else
{
tp=head;
printf("\n");
printf("\t%s",tp->name);
tp=tp->next;
while(tp!=NULL)
{
printf("\t%s",tp->name);
tp=tp->next;
}
printf("\t%s",tp->name);
printf("\n");
tp=head;
printf("\n");
printf("0");
while(tp->next!=NULL)
{
n=n+tp->btime;
printf("\t%d",n);
tp=tp->next;
}
n=n+tp->btime;
printf("\t%d",n);
}
}
OUTPUT:
Enter the name of the process:P1
Enter the burst time:5
Press '1' to continue:1
Enter the name of the process:P2
Enter the burst time:9
Press '1' to continue:1
Enter the name of the process:P3
Enter the burst time:2
Press '1' to continue:1
Enter the name of the process:P4
Enter the burst time:6
Press '1' to continue:1
Enter the name of the process:P5
Enter the burst time:12
Press '1' to continue:0
Gantt chart:
P3 P1
0
2
7
P4
13
P2
22
P5
34
(null)
//IMPLEMENTATION OF PRIORITY SCHEDULING
#include<stdio.h>
#include<malloc.h>
struct node
{
char name[15];
int btime,priority;
struct node *next;
};
int main()
{
struct node *head,*temp,*tp,*p;
int d,ch,n=0;
head=NULL;
do
{
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the name of the process:");
scanf("%s",&temp->name);
printf("\nEnter the priority:");
scanf("%d",&temp-> priority);
printf("\nEnter the burst time:");
scanf("%d",&temp->btime);
temp->next=NULL;
if(temp==NULL)
printf("\nNode is not created..");
if(head==NULL)
head=temp;
else
{
if(temp-> priority <head-> priority)
{
temp->next=head;//swapping head and temp
head=temp;
}
else if(temp-> priority >head-> priority)
{
tp=head;
while((tp!=NULL) && (temp-> priority >tp-> priority))
{
p=tp;
tp=tp->next;
}
p->next=temp;
temp->next=tp;
}
}
printf("\nPress '1' to continue:");
scanf("%d",&ch);
}while(ch==1);
printf("\nGantt chart:");
if(head==NULL)
printf("\nList is empty...! ");
else
{
tp=head;
printf("\n");
printf("\t%s",tp->name);
tp=tp->next;
while(tp!=NULL)
{
printf("\t%s",tp->name);
tp=tp->next;
}
printf("\t%s",tp->name);
printf("\n");
tp=head;
printf("\n");
printf("0");
while(tp->next!=NULL)
{
n=n+tp->btime;
printf("\t%d",n);
tp=tp->next;
}
n=n+tp->btime;
printf("\t%d",n);
}
}
OUTPUT:
Enter the name of the process:P1
Enter the priority:7
Enter the burst time:5
Press '1' to continue:1
Enter the name of the process:P2
Enter the priority:4
Enter the burst time:2
Press '1' to continue:1
Enter the name of the process:P3
Enter the priority:0
Enter the burst time:10
Press '1' to continue:1
Gantt chart:
P3
P2
0
10
12
P1
17
(null)
No comments:
Post a Comment