Week 9 OS Task
Week 9 OS Task
SCHEDULING ALGORITHMS:
The FCFS scheduling algorithm is non-preemptive. Once the CPU has been
allocated to a process, that process keeps the CPU until it releases the CPU,
either by terminating or by requesting i/o.
PROGRAM:
USING POINTERS:
#include<stdio.h> //HEADER FILES
#include<malloc.h>
#include<string.h>
typedefstruct node //STRUCTURE
{
char prss[3];
int burst;
int arrival;
struct node *next;
}node;
node *front=NULL; //GLOBAL VARIABLES
node *rear=NULL;
void insert(); //FUNCTION DECLARATION
void display(int);
void main() //MAIN FUNCTION
{
int i ,n;
printf("\nEnter number of processes : ");
scanf("%d",&n);
for(i=0;i<n;i++) //LOOP
insert(); //FUNCTION CALL
printf("\n\nExecuting processes : \n");
display(n); //FUNCTION CALL
printf("\n");
} //END OF MAIN
p->burst=b; p-
>arrival=a; p-
>next=NULL;
if(front==NULL)
{
front=p;
rear=p;
}
else
{
rear->next=p;
rear=p;
}
}
void display(int n) //FUNCTION DEFINITION
{
node *temp=front;
intwttime=0,c=0;
float turn=0.0;
if(front!=NULL)
{
printf("\n---------------------------------------------------------------
\n\t");
while(temp!=NULL)
{
printf("|\t%s\t",temp->prss);
temp=temp->next;
}
printf("|\n-------------------------------------------------------------
--\n\t");
temp=front;
while(temp!=NULL)
{
printf(" \t%d\t ",temp->burst);
temp=temp->next;
}
printf("\n---------------------------------------------------------------
--\n\t");
temp=front;
printf("0\t");
while(temp!=NULL)
{
wttime+=c;
turn+=c+temp->burst;
c=c+temp->burst;
printf(" \t%d\t ",c);
temp=temp->next;
}
printf("\n---------------------------------------------------------------
--\n");
printf("\n\nAveragewt time = %d ",wttime/n);
printf("\nTurnaround time = %f\n",turn/n);
}
}
PROGRAM:
USINGARRAYS:
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char p[10][5],temp[5]; int
c=0,pt[10],i,j,n,temp1; float
bst=0.0,turn=0.0; clrscr();
printf("enter no of processes:");
scanf("%d",&n); for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
printf("\n.....................................................\n");
for(i=0;i<n;i++)
{
printf("|\t %s\t",p[i]);
}
printf("|\n.....................................................\n");
for(i=0;i<n;i++)
{
printf("\t\t%d",pt[i]);
}
printf("\n.....................................................\n");
printf("0");
for(i=0;i<n;i++)
{
bst+=c;
turn+=c+pt[i];
c=c+pt[i];
printf("\t\t%d",c);
}
printf("\nAverage time is %f: ",bst/n);
printf("\nTurn around time is %f", turn/n);
getch();
}
OUTPUT:
------------------------------------------------------------------------------------------
| P1 | P2 | P3 |
------------------------------------------------------------------------------------------
24 3 3
------------------------------------------------------------------------------------------
0 24 27 30
Average wt time = 17
Turnaround time = 27.000000