0% found this document useful (0 votes)
14 views

Final 2

Uploaded by

papa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Final 2

Uploaded by

papa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

K R I S HN A ENGINEERING COLLEGE

(Approved by AICTE & Affiliated to Dr. APJ Abdul Kalam Technical University (Formerly UPTU), Lucknow)

Department of Computer Science and Engineering

Subject name:-

Subject Code:-

Student Name:- Roll no:- Semester :-

Branch & section :-

Faculty Incharge :-

Mohan Nagar, Near Air Force Station- Hindon, Ghaziabad – 201007 (U.P.)
Tel: 0120-2657731, 2657732, TeleFax : 0120-2659513
Email: [email protected], Website : www.krishnacollege.ac.in
INDEX
S.NO TITLE DATE SIGNATURE

1 HARDWARE AND SOFTWARE REQUIREMENTS OF DIFFERENT OS

2 COMMANDS OF DIFFERENT OS

3 FCFS

4 SJF

5 SRTF

6 ROUND ROBIN

7 BANKERS ALGORITHM

8 PRODUCER CONSUMER

9 STORAGE ALLOCATION TECHNIQUES

:-FIRST FIT

:-BEST FIT

:-WORST FIT

10 FCFS

LRU
Experiment No. 06
( ROUND ROBIN )

void main()
{
int i, NOP, sum=0,count=0, y, quant, wt=0, tat=0, at[10], bt[10], temp[10];
float avg_wt, avg_tat;
printf(" Total number of process in the system: ");
scanf("%d", &NOP);
y = NOP;
for(i=0; i<NOP; i++)
{
printf("\n Enter the Arrival and Burst time of the Process[%d]\n", i+1);
printf(" Arrival time is: \t");
scanf("%d", &at[i]);
printf(" \nBurst time is: \t");
scanf("%d", &bt[i]);
temp[i] = bt[i];
}
printf("Enter the Time Quantum for the process: \t");
scanf("%d", &quant);
printf("\n Process No \t\t Burst Time \t\t TAT \t\t Waiting Time ");
for(sum=0, i = 0; y!=0; )
{
if(temp[i] <= quant && temp[i] > 0)
{
sum = sum + temp[i];
temp[i] = 0;
count=1;
}
else if(temp[i] > 0)
{
temp[i] = temp[i] - quant;
sum = sum + quant;
}
if(temp[i]==0 &&
count==1)
{
y--;
printf("\nProcess No[%d] \t\t %d\t\t\t\t %d\t\t\t %d", i+1, bt[i], sum-at[i], sum-at[i]-bt[i]);
wt = wt+sum-at[i]-bt[i];
tat = tat+sum-at[i];
count =0;
}
if(i==NOP-1)
{
i=0;
}
else if(at[i+1]<=sum)
{
i++;
}
else
{
i=0;
}
}
avg_wt = wt * 1.0/NOP;
avg_tat = tat *
1.0/NOP;
printf("\n Average Turn
Around Time: \t%f",
avg_wt);
printf("\n Average Waiting Time: \t%f", avg_tat);
getch();
}
PN BT WT TAT
1OUTPUT-11 13 23
2 5 15 5
3 8 13 21
Average waiting time = 17
Average turn around time = 15.6667
Experiment No. 07
(BANKER’S ALGORITHM)

#include <stdio.h>
int main()
{
int n, m, i, j, k;
n = 5;
m = 3;
int alloc[5][3]
= {{0, 1, 0},
{2, 0, 0},{3, 0,
2},{2, 1, 1},
{0, 0, 2}};
int max[5][3]
= {{7, 5, 3},
{3, 2, 2},{9, 0,
2},{2, 2, 2},
{4, 3, 3}};
int avail[3] =
{3, 3, 2};
int f[n], ans[n], ind = 0;
for (k = 0; k < n; k++)
{
f[k] = 0;
}
int need[n][m];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
need[i][j] = max[i]
[j] - alloc[i][j];
}
int y = 0;
for (k = 0; k < 5; k++)
{
for (i = 0; i < n; i++)
{
if (f[i] == 0)
{
int flag = 0;
for (j = 0; j <
m; j++)
{
if (need[i][j]
> avail[j])
{
flag = 1;
if (flag == 0)
{
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
int flag = 1;
for (int i = 0; i < n; i++)
{
if (f[i] == 0)
{
flag = 0;
printf("The following system is not safe");
break;
}
}
if (flag == 1)
{
printf("Following is the SAFE Sequence\n");
for (i = 0; i < n - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[n - 1]);
}
return (0);
}
Output-

Following is the safe sequence-


P1-->P3-->P4--P0-->P2
Experiment No. 08

(PRODUCER-CONSUMER)

#include <stdio.h>
#include <stdlib.h>
int mutex = 1;
int full = 0;
int empty = 10, x = 0;
void producer()
{
--mutex;
++full;
--empty;
x++;
printf("\
nProduc
er
produce
s item:
%d", x);
+
+mutex;
}
void
consumer()
{
--mutex;
--full;
+
+empty;
printf("\nConsumer consumes " "item %d",x);
x--;
++mutex;
}
int main()
{
int n, i;
printf( "\n1. Press 1 for Producer"
"\n2. Press 2 for Consumer"
"\n3. Press 3 for Exit");
for (i = 1; i > 0; i++)
{
printf("\nEnter your choice:");
scanf("%d", &n);
switch (n) {
case 1:
if ((mutex == 1)&& (empty != 0))
{
producer();
}
else {
printf("Buffer is full!");
}
break;
case 2:

if ((mutex == 1)&& (full != 0))


{
consumer();
}
else {
printf("Buffer is empty!");
}
break;

case 3:
exit(0);
break;
}
}
}

Output:

Producer produced-0
Producer produced-1
Consumer consumed-0
Consumer consumed-1
Producer produced-2
Experiment No. 09
(FIRST FIT)

#include<stdio.h>
void main()
{
int bsize[10], psize[10], bno, pno, flags[10], allocation[10], i, j;
for(i = 0; i < 10; i++)
{
flags[i] = 0;
allocation[i] = -1;
}
printf("Enter no. of blocks: ");
scanf("%d", &bno);
printf("\nEnter size of each block: ");
for(i = 0; i < bno; i++)
scanf("%d", &bsize[i]); printf("\
nEnter no. of processes: ");
scanf("%d", &pno);
printf("\nEnter size of each process: ");
for(i = 0; i < pno; i++)
scanf("%d", &psize[i]);
for(i = 0; i < pno; i++)
for(j = 0; j < bno; j++)
if(flags[j] == 0 &&
bsize[j] >= psize[i])
{
allocation[j] = i;
flags[j] = 1;
break;
}
printf("\nBlock no.\tsize\t\tprocess no.\t\tsize");
for(i = 0; i < bno; i++)
{
printf("\n%d\t\t%d\t\t", i+1, bsize[i]);
if(flags[i] == 1)
printf("%d\t\t\t%d",allocation[i]+1,psize[allocation[i]]);
else
printf("Not allocated");
}
}
Output-
Process No. Process Size Block no.
1 212 2
2 417 5
3 112 2
4 426 Not Allocated
(BEST FIT)

#include<stdio.h>
void main()
{
int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
static int barray[20],parray[20];
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of processes:");
scanf("%d",&np);
printf("\nEnter the size of the blocks:-\
n");
for(i=1;i<=nb;i++)
{
printf("Block no.%d:",i);
scanf("%d",&b[i]);
}
printf("\nEnter the size of the processes :-\n");
for(i=1;i<=np;i++)
{
printf("Process no.%d:",i);
scanf("%d",&p[i]);
}
for(i=1;i<=np;i++)
{
for(j=1;j<=nb;j++)
{
if(barray[j]!=1)
{
temp=b[j]-p[i];
if(temp>=0)
if(lowest>temp
)
{
parray[i]=j;
lowest=temp;
}
}
}
fragment[i]=lowest;
barray[parray[i]]=1;
lowest=10000;
}
printf("\nProcess_no\tProcess_size\tBlock_no\tBlock_size\tFragment");
for(i=1;i<=np && parray[i]!=0;i++) printf("\n%d\t\t%d\t\t%d\t\t%d\t\t
%d",i,p[i],parray[i],b[parray[i]],fragment[i]);
}

Input : blockSize[] = {100, 500, 200, 300, 600};


processSize[] = {212, 417, 112, 426};

OUTPUT-

Process No. Process Size Block no.


1 213 4
2 413 4
3 110 3
4 423 5
(WORST FIT)

#include<stdio.h>
int main()
{
int n,n1,i;
printf("enter the number of processes:");
scanf("%d",&n);
int process[n];
printf("\n enter the size of processes:\n");
for(i=0;i<n;i++)
{
scanf("%d",&process[i]);
}
printf("enter the no of memoryblocks:");
scanf("%d",&n1);
int blocks[n1];
printf("\n enter the size of blocks:\n");
int total=0;
for(i=0;i<n1;i++)
{
scanf("%d",&blocks[i]);
total=total+blocks[i];
}
int process1[n1];
int job[n1];
int frag[n1];
int check[n1];
for(i=0;i<n1;i
++)
{
check[i]=0;
}
int j,used=0;
i=0;
while(i<n)
{
int max=-1,j1=-1,k=-1,max1;
for(j=0;j<n1;j++)
{
max1=blocks[j];
if(max1>=max&&check[j]==0&&max1>=process[i])
{
max=max1;
j1=j;
}
else
{
if(check[j]=
=0)
{
process1[j]=0;
job[j]=0;
frag[j]=blocks
[j];
}
}
}
if(k!=j1)
{
process1[j1]=process[i];
job[j1]=i+1;
frag[j1]=blocks[j1]-process[i];
used=used+process[i];
check[j1]=1;
int l;
}
i++;
}
printf("blocksize\tprocess size\tprocessno\tfragmentation\n");
for(i=0;i<n1;i++)
{
printf("%d\t\t%d\t\t%d\t\t%d\
n",blocks[i],process1[i],job[i],frag[i]);
}
printf("totalmemoryallocation:%d\n",total);
printf("memoryused:%d\n",used);
INPUT/OUTPUT:- ------------
Enter}the number of blocks: 4
Enter the number of files: 3
Enter the size of the blocks
Block 1: 4
Block 2: 4
Block 3:

Enter the size of the files:-


File 1: 2
File 2: 5

File No File Size Block No Block Size Fragment


1 1 1 2 4
2 4 3 5 3
Experiment No. 10
(FCFS PAGE REPLACEMENT ALGORITHM)

#include<stdio.h>
int fsize;
int frm[15];
void display();
void main()
{
int pg[100],nPage,i,j,pf=0,top=-1,temp,flag=0;
printf("\n Enter frame size:");
scanf("%d",&fsize);
printf("\n Enter number of pages:");
scanf("%d",&nPage);
for(i=0;i< nPage;i++)
{
printf("\n Enter page[%d]:",i+1);
scanf("%d",&pg[i]);
}
for(i=0;i< fsize;i++)
frm[i]=-1;
printf("\n page | \t Frame content ");
printf("\n
"); for(j=0;j< nPage;j++)
{
flag=0;
for(i=0;i< fsize;i++)
{
if(frm[i]==pg[j])
{
flag=1;
break;
}
}
if(flag==
0)
{
if(top==
fsize-1)
{
top=-1;
}
pf++;
top++;
frm[to
p]=pg[
j];
printf("\n %d |",pg[j]);
}display();
}
printf("\n "); printf("\n total page fault:
%d",pf);
}
void display()
{
int i;
for(i=0;i< fsize;i++)
printf("\t %d",frm[i]);
}

OUTPUT:

Processes Burst time Waiting time Turn around time


1 10 8 10
2 5 10 15
3 5 15 25
Average waiting time = 7.33333
Average turn around time = 19
(LRU PAGE REPLACEMENT ALGORITHM)

#include <stdio.h>
int findLRU(int time[], int n)
{
int i, minimum = time[0], pos = 0;
for (i = 1; i < n; ++i)
{
if (time[i] < minimum)
{
minimum = time[i];
pos = i;
}
}
return pos;
}
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j,
pos, faults = 0;
printf("Enter number of frames:
"); scanf("%d", &no_of_frames);
printf("Enter number of pages: ");
scanf("%d", &no_of_pages);
printf("Enter reference string: ");
for (i = 0; i < no_of_pages; ++i)
{
scanf("%d", &pages[i]);
}
for (i = 0; i < no_of_frames; +
+i)
{
frames[i] = -1;
}
for (i = 0; i < no_of_pages; +
+i)
{
flag1 = flag2 = 0;
for (j = 0; j < no_of_frames;
++j)
{
if (frames[j] == pages[i])
{
counter++;
time[j] = counter;
flag1 = flag2 = 1;
break;
}
}
if (flag1 == 0)
{
for (j = 0; j <
no_of_frames; ++j)
{

if (flag2 == 0)
{
pos = findLRU(time, no_of_frames);
counter++;
faults++;
frames[pos] = pages[i];
time[pos] = counter;
}
printf("\n");
for (j = 0; j <
no_of_frames; ++j)
{
printf("%d\t",
frames[j]);
}
}
printf("\nTotal Page Faults = %d", faults);
Enter
return 0;the Reference String: 6
} 0
1
5 OUTPUT-
0
3
6
Enter the Number of frames: 2
66 -1 -1
0 6 0 -1
1701
66 0 1
0
3203
0
5403
Page faults: 5
OUTPUT:

You might also like