Vemu Institute of Technology: Department of Computer Science & Engineering
Vemu Institute of Technology: Department of Computer Science & Engineering
LAB MANUAL
5 30-32
Simulate Banker‟s Algorithm for Dead Lock Avoidance and Dead Lock Prevention.
8 48-49
Simulate how parent and child processes use shared memory and address space
10 53-55
Simulate dining philosopher„s problem
11 Simulate producer and consumer problem using threads (use java) 56-58
12 59-60
Develop a code to detect a cycle in wait-for graph
13 61-63
Develop a code to convert virtual address to physical address
15 Simulate the prediction of deadlock in operating system when all the processes announce their 67-69
resource requirement in advance
Additional Programs:
16 70-75
1. Optimal Page Replacement Algorithm.
2. Dekker‟s Algorithm.
3.
4.
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR
0 0 4 2
Course Objectives:
4. Simulate all File Organization Techniques a) Single level directory b) Two level c)
Hierarchical d) DAG
9. Control the number of ports opened by the operating system with a) Semaphore b) monitors
10. Simulate how parent and child processes use shared memory and address space
13. Simulate producer and consumer problem using threads (use java)
14. Simulate little„s formula to predict next burst time of a process for SJF scheduling
Algorithm.
1.1.1 OBJECTIVE:
1.1.3 PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int ts,need[10],wt[10],tat[10],i,j,n,n1;
int bt[10],flag[10],ttat=0,twt=0;
float awt,atat;
clrscr();
printf("\n Round Robbin Scheduling \n");
printf(" Enter the number of processes ");
scanf("%d",&n);
n1=n;
printf(" Enter the time slice ");
scanf("%d",&ts);
for(i=1;i<=n;i++)
{
printf("Enter the burst time for process %d ",i);
scanf("%d",&bt[i]);
need[i]=bt[i];
}
for(i=1;i<=n;i++)
{
flag[i]=1;
wt[i]=0;
}
while(n!=0)
{
for(i=1;i<=n;i++)
{
if(need[i]>=ts)
{
for(j=1;j<=n;j++)
1.2.1 OBJECTIVE
1.2.3 PROGRAM :
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,n,k,h;
int b[10],w[10],t[10],br[10],pr[10];
char p[10];
temp=0;
clrscr();
printf("enter the number of processes");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i]=0;
b[i]=0;
w[i]=0;
t[i]=0;
br[i]=0;
pr[i]=0;
}
for(i=0;i<n;i++)
{
printf("Enter the process name %d \n",i);
scanf("%s",&p[i]);
printf("Enter the burst time of process %d \n",i);
scanf("%d",&b[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
t[i]=p[i];
}
EXPERIMENT-1.3
1.3.1 OBJECTIVE
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,n,k,h;
int b[10],w[10];
char p[10];
temp=0;
clrscr();
printf("enter the number of processes");
scanf("%d",&n);
for(i=0;i<n;i++)
EXPERIMENT-1.4
1.4.1 OBJECTIVE
1.4.3 PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,temp,n,k,h;
int b[10],w[10],pr[10];
char p[10];
temp=0;
clrscr();
printf("enter the number of processes");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i]=0;
b[i]=0;
w[i]=0;
}
for(i=0;i<n;i++)
{
printf("Enter the process name %d \n",i);
scanf("%s",&p[i]);
printf("Enter the burst time of process %d \n",i);
scanf("%d",&b[i]);
printf("Enter the priority of process %d \n",i);
scanf("%d",&pr[i]);
}
for(j=0;j<n;j++)
{
2. Write a collection of processes p1, p2, p3 which execute with same PID.
2.1.1 OBJECTIVE
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],s[10],l[10],n,m,c,i,j,k;
clrscr();
printf("Enter the total memory you want");
scanf("%d",&m);
printf("Enter the Total number of files");
scanf("%d",&n);
for(i=0;i<=m;i++)
a[i]=-1;
for(i=0;i<n;i++)
{
printf("Enter the starting block of file %d\n ",(i+1));
scanf("%d",&s[i]);
printf("Enter the length of the file %d\n",(i+1));
scanf("%d",&l[i]);
}
for(i=0;i<n;i++)
{
for(k=s[i],j=0;j<l[i];j++,k++)
{
if(a[k]==-1)
c=0;
else
{
c=1;
break;
}
}
if(c==1)
printf("This block was already filled by file %d\n",(a[k]+1));
if(c==0)
{
for(k=s[i],j=0;j<l[i];j++,k++)
EXPERIMENT-2.2
2.2.1 OBJECTIVE
2.2.3 PROGRAM
#include<conio.h>
EXPERIMENT-2.3
2.3.1 OBJECTIVE
Step 1: Start.
Step 2: Let n be the size of the buffer
Step 3: check if there are any producer
Step 4: if yes check whether the buffer is full
2.3.3 PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],b[99],m,n,i;
int *p;
for(i=0;i<100;i++)
a[i]=-1;
printf("enter the starting address of file");
scanf("%d",&n);
printf("enter the number of nodes");
scanf("%d",&m);
L1: for(i=0;i<m;i++)
{
printf("enter index %d \n ",(i+1));
scanf("%d",&b[i]);
}
p=&b[0];
a[n]=1;
printf("\n\nfile 1 starting address is: %d\n Your indexed locations are\n",n);
for(i=0;i<m;i++)
{
if(a[b[i]]==-1)
{
a[b[i]]=1;
printf("%d\n",*p);
p=p+1;
}
else
{
printf("same block already allocated %d\n",b[i]);
for(i=0;i<m;i++)
a[b[i]]=-1;
printf("sorry, no vacancy try again!");
goto L1;
}
}
getch();
}
1. Write a collection of sufficient no. of processes which carry out the following different types of tasks
independently:
Only computation
Only printf s
Low computation, heavy console output (printfs)
Heavy File I/O
1. File systems can support sparse files, what does this mean?
2. Give an example of a scenario that might benefit from a file system supporting an append-only access write.
3. Give a scenario where choosing a large file system block size might be a benefit
4. What file access pattern is particularly suited to chained file allocation on disk
3.1.1 OBJECTIVE
Simulate Multi programming with fixed number of tasks and Multi programming with variable number of tasks.
MFT
#include<stdio.h>
#include<conio.h>
main()
{
int ms,i,ps[20],n,size,p[20],s,intr=0;
clrscr();
printf("Enter size of memory:");
scanf("%d",&ms);
printf("Enter memory for OS:");
scanf("%d",&s);
ms-=s;
printf("Enter no.of partitions to be divided:");
scanf("%d",&n);
size=ms/n;
for(i=0;i<n;i++)
{
printf("Enter process and process size");
scanf("%d%d",&p[i],&ps[i]);
if(ps[i]<=size)
{
intr=intr+size-ps[i];
printf("process%d is allocated\n",p[i]);
}
else
printf("process%d is blocked",p[i]);
}
printf("total fragmentation is %d",intr);
getch();
}
EXPERIMENT-3.2
3.2.1 OBJECTIVE
Simulate Multi programming with fixed number of tasks and Multi programming with variable number of tasks
MVT
3.2.3 PROGRAM
#include<stdio.h>
#include<conio.h>
main()
{
int i,m,n,tot,s[20];
clrscr();
printf("Enter total memory size:");
scanf("%d",&tot);
printf("Enter no. of pages:");
scanf("%d",&n);
printf("Enter memory for OS:");
scanf("%d",&m);
for(i=0;i<n;i++)
{
printf("Enter size of page%d:",i+1);
scanf("%d",&s[i]);
}
tot=tot-m;
for(i=0;i<n;i++)
{
if(tot>=s[i])
{
printf("Allocate page %d\n",i+1);
tot=tot-s[i];
}
else
printf("process p%d is blocked\n",i+1);
}
printf("External Fragmentation is=%d",tot);
getch();
}
(a) Worst-Fit
(b) Best-Fit
(c) First-Fit
EXPERIMENT-4.1
4.1.1 OBJECTIVE
4.1.3 PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,count,i,j,mid,cir_x;
char fname[10][20];
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
setbkcolor(GREEN);
puts("Enter no of files do u have?");
scanf("%d",&count);
for(i=0;i<count;i++)
{
cleardevice(); setbkcolor(GREEN);
printf("Enter file %d name",i+1);
scanf("%s",fname[i]);
setfillstyle(1,MAGENTA);
mid=640/count;
cir_x=mid/3;
bar3d(270,100,370,150,0,0);
settextstyle(2,0,4);
settextjustify(1,1);
outtextxy(320,125,"Root Directory");
setcolor(BLUE);
for(j=0;j<=i;j++,cir_x+=mid)
{
line(320,150,cir_x,250);
fillellipse(cir_x,250,30,30);
outtextxy(cir_x,250,fname[j]);
}
getch();
}
}
4.2.1 OBJECTIVE
4.2.3 PROGRAM
#include<stdio.h>
#include<graphics.h>
struct tree_element
{
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element *link[5];
};
typedef struct tree_element node;
void main()
{
int gd=DETECT,gm;
node *root;
root=NULL;
clrscr();
create(&root,0,"null",0,639,320);
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
display(root);
EXPERIMENT-4.3
4.3.1 OBJECTIVE
4.3.3 PROGRAM
#include<stdio.h>
#include<graphics.h>
struct tree_element
EXPERIMENT-4.4
4.4.1 OBJECTIVE
4.4.3 PROGRAM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<string.h>
struct tree_element
{
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element *link[5];
};
typedef struct tree_element
node;
typedef struct
{
char from[20];
char to[20];
}link;
Link L[10];
Int nofl;
node * root;
void main()
{
int gd=DETECT,gm;
root=NULL;
clrscr();
create(&root,0,"root",0,639,320);
read_links();
clrscr();
initgraph(&gd,&gm,"c:\\tc\\BGI");
draw_link_lines();
display(root);
getch();
closegraph();
}
read_links()
{
int i;
printf("how many links");
scanf("%d",&nofl);
for(i=0;i<nofl;i++)
{
printf("File/dir:");
fflush(stdin);
gets(L[i].from);
printf("user name:");
5.1 OBJECTIVE
Program for Bankers algorithm for deadlock avoidance and deadlock prevention.
5.3 PROGRAM
#include<stdio.h>
#include<conio.h>
#define s 15
void main()
{
int n,m,a[5],e[5],c[5][5],r[5][5];
int i,j,k,cou,l,flag,count;
cou=flag=count=0;
printf("enter no of processes");
scanf("%d",&n);
printf("enter no of resource classes");
scanf("%d",&m);
for(i=0;i<m;i++)
{
printf("\n enter instances of resources class %d "i+1);
scanf("%d",&e[i]);
printf("\n enter free vectors of resources class %d (resources available):",i+1);
scanf("%d",&a[i]);
}
printf("\n enter the current allocation matrix \n");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&c[i][j]);
printf("\n enter the request matrix \n");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&r[i][j]);
for(l=0;l<n;l++)
{
cou=0;flag=0;
for(i=0;i<n;i++)
{
cou=0;flag=0;
for(j=0;j<m;j++)
enter no of processes5
enter no of resource classes3
enter instances of resources class 1 10
enter free vectors of resources class 1 (resources available):3
enter instances of resources class 2 5
enter free vectors of resources class 2 (resources available):3
enter instances of resources class 3 7
enter free vectors of resources class 3 (resources available):2
enter the current allocation matrix
010
200
302
211
002
enter the request matrix
743
122
600
011
431
process 2 is satisfied
a[0]=5
a[1]=3
a[2]=2
process 4 is satisfied
a[0]=7
a[1]=4
a[2]=3
process 5 is satisfied
a[0]=7
6.1.1 OBJECTIVE
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,n,k,m,r,pagef;
int a[100],b[100];
k=0,pagef=0;
clrscr();
printf("enter the number of pages\n");
scanf("%d",&n);
printf("enter the number of frames in main memory\n");
scanf("%d",&m);
for(i=0;i<m;i++)
b[i]=-1;
for(i=0;i<n;i++)
{
printf("enter the element %d\n",i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(b[j]==a[i])
{
printf("the page %d is already present in main memory\n",a[i]);
break;
}
}
if(j==m)
{
b[k]=a[i];
k++;
if(k==m)
k=0;
for(r=0;r<m;r++)
printf("%d ",b[r]);
printf("\n");
pagef++;
}
}
printf("number of page faults: %d",pagef);
EXPERIMENT-6.2
6.2.1 OBJECTIVE
#include<conio.h>
#include<stdio.h>
int lrupage(int w[],int m);
void main()
{
int i,j,n,m,r,pagef,l,h,p;
int a[100],b[100],w[10];
pagef=0;
clrscr();
printf("enter the number of pages\n");
scanf("%d",&n);
printf("enter the number of frames in main memory\n");
scanf("%d",&m);
for(i=0;i<m;i++)
b[i]=-1;
for(i=0;i<n;i++)
{
printf("enter the element %d\n",i);
scanf("%d",&a[i]);
}
for(i=0;i<m;i++)
{
b[i]=a[i];
for(r=0;r<m;r++)
EXPERIMENT-6.3
6.3.1 OBJECTIVE
6.4.2 PROGRAM
#include<stdio.h>
int main()
{
int f,p;
int pages[50],frame[10],hit=0,count[50],time[50];
int i,j,page,flag,least,minTime,temp;
for(i=0;i<f;i++)
{
frame[i]=-1;
}
for(i=0;i<50;i++)
{
count[i]=0;
}
printf("Enter page no : \n");
for(i=0;i<p;i++)
{
scanf("%d",&pages[i]);
}
EXPERIMENT-7.1
7.1.3 PROGRAM
#include <stdio.h>
#include <conio.h>
struct pstruct
{
int fno;
int pbit;
}ptable[10];
int pmsize,lmsize,psize,frame,page,ftable[20],frameno;
void info()
{
printf("\n\nMEMORY MANAGEMENT USING PAGING\n\n");
printf("\n\nEnter the Size of Physical memory: ");
scanf("%d",&pmsize);
printf("\n\nEnter the size of Logical memory: ");
scanf("%d",&lmsize);
printf("\n\nEnter the partition size: ");
scanf("%d",&psize);
frame = (int) pmsize/psize;
page = (int) lmsize/psize;
printf("\nThe physical memory is divided into %d no.of frames\n",frame);
printf("\nThe Logical memory is divided into %d no.of pages",page);
}
void assign()
{
int i;
for (i=0;i<page;i++)
{
ptable[i].fno = -1;
ptable[i].pbit= -1;
}
for(i=0; i<frame;i++)
ftable[i] = 32555;
for (i=0;i<page;i++)
{
printf("\n\nEnter the Frame number where page %d must be placed: ",i);
scanf("%d",&frameno);
EXPERIMENT-7.2
7.2.1 OBJECTIVE
#include <stdio.h>
#include <conio.h>
#include <math.h>
int sost;
void gstinfo();
void ptladdr();
struct segtab
{
int sno;
int baddr;
int limit;
int val[10];
}st[10];
void gstinfo()
{
int i,j;
printf("\n\tEnter the size of the segment table: ");
scanf("%d",&sost);
for(i=1;i<=sost;i++)
{
void ptladdr()
{
int i,swd,d=0,n,s,disp,paddr;
clrscr();
printf("\n\n\t\t\t SEGMENT TABLE \n\n");
printf("\n\t SEG.NO\tBASE ADDRESS\t LIMIT \n\n");
for(i=1;i<=sost;i++)
printf("\t\t%d \t\t%d\t\t%d\n\n",st[i].sno,st[i].baddr,st[i].limit);
printf("\n\nEnter the logical Address: ");
scanf("%d",&swd);
n=swd;
while (n != 0)
{
n=n/10;
d++;
}
s = swd/pow(10,d-1);
disp = swd%(int)pow(10,d-1);
if(s<=sost)
{
if(disp < st[s].limit)
{
paddr = st[s].baddr + disp;
printf("\n\t\tLogical Address is: %d",swd);
printf("\n\t\tMapped Physical address is: %d",paddr);
printf("\n\tThe value is: %d",( st[s].val[disp] ) );
}
else
printf("\n\t\tLimit of segment %d is high\n\n",s);
}
else
printf("\n\t\tInvalid Segment Address \n");
}
void main()
{
char ch;
clrscr();
gstinfo();
do
{
ptladdr();
getch();
}
SEGMENT TABLE
1 4 5
2 5 4
3 3 4
EXPERIMENT-8
Simulate how parent and child processes use shared memory and address space.
8.3 PROGRAM
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdio.h>
#include<stdlib.h>
#define SHMSZ 27
main()
{
int shmid;
key_t key;
char *shm, *s;
key=5678;
if((shmid=shmget(key,SHMSZ,0666))<0)
{
perror("shmget");
exit(1);
}
if((shm=shmat(shmid,NULL,0))==(char*)-1)
{
perror("shmat");
exit(1);
}
for(s=shm;*s!= NULL;s++)
putchar(*s);
putchar('\n');
*shm='*';
exit(0);
}
SERVER:
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdio.h>
#include<stdlib.h>
#define SHMSZ 27
main()
1.Discuss the consequences of considering bounded and unbounded buffers in producer-consumer problem?
2.Can producer and consumer processes access the shared memory concurrently? If not which techniqueprovides
such a benefit?
EXPERIMENT-9
def Barber():
while true:
wait(custReady)
wait(accessWRSeats)
numberOfFreeWRSeats += 1
signal(barberReady)
signal(accessWRSeats)
# (Cut hair here.)
def Customer():
wait(accessWRSeats)
if numberOfFreeWRSeats > 0:
numberOfFreeWRSeats -= 1
signal(custReady)
signal(accessWRSeats)
wait(barberReady)
else:
signal(accessWRSeats)
# (Leave without a haircut.)
9.3 PROGRAM
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h> // The maximum number of customer threads.
#define MAX_CUSTOMERS 25 // Function prototypes...
while (!allDone) {
printf("The barber is sleeping\n");
sem_wait(&barberPillow);
if (!allDone)
{
printf("The barber is cutting hair\n");
randwait(3);
EXPERIMENT-10
process P[i]
while true do
{ THINK;
PICKUP(CHOPSTICK[i], CHOPSTICK[i+1 mod 5]);
EAT;
PUTDOWN(CHOPSTICK[i], CHOPSTICK[i+1 mod 5])
}
10.3 PROGRAM
int tph, philname[20], status[20], howhung, hu[20], cho; main()
{
int i;
clrscr();
printf("\n\nDINING PHILOSOPHER PROBLEM"); printf("\nEnter the total no. of philosophers: ");
scanf("%d",&tph);
for(i=0;i<tph;i++)
{
philname[i] = (i+1);
status[i]=1;
}
printf("How many are hungry : ");
scanf("%d", &howhung);
if(howhung==tph)
{
printf("\nAll are hungry..\nDead lock stage will occur"); printf("\nExiting..");
}
else
{
for(i=0;i<howhung;i++)
{
printf("Enter philosopher %d position: ",(i+1));
scanf("%d", &hu[i]); status[hu[i]]=2;
}
do
{
printf("1.One can eat at a time\t2.Two can eat at a time\t3.Exit\nEnter your choice:");
scanf("%d", &cho); switch(cho)
{
case 1: one();
break;
case 2: two();
break;
case 3:
exit(0);
EXPERIMENT-11
Producer algorithm:
while (true)
{
/* produce an item in nextproduced */
while (counter == BUFFER_SIZE) ;
/* do nothing */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
counter++;
}
Consumer algorithm:
while (true)
{
while (counter == 0) ; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
counter--;
/* consume the item in next consumed */
}
11.3 PROGRAM
import java.io.*;
import java.lang.*;
class Q
{
int n;
boolean valueSet=false;
synchronized int get()
{
if(!valueSet)
try
{
wait();
}
catch(InterruptedException e){
System.out.println("InterruptedException caught");
}
System.out.println("Got:"+n);
valueSet=false;
notify();
return n;
}
synchronized void put(int n)
{
if(valueSet)
try
{
wait();
}catch(InterruptedException e){
Put 1
Get1
Put 2
EXPERIMENT-12
12.3 PROGRAM
import java.io.*;
import java.util.*;
class Graph
{
private int V;
private LinkedList<Integer> adj[];
Graph(int v) {
V = v;
adj = new LinkedList[v];
for(int i=0; i<v; ++i)
adj[i] = new LinkedList();
}
void addEdge(int v,int w) {
adj[v].add(w);
adj[w].add(v);
}
javac CheckCycle.java
javaCheckCycle
EXPERIMENT-13
13.3 PROGRAM
#include <stdio.h>
#include <conio.h>
struct pstruct
{
int fno;
int pbit;
}ptable[10];
int pmsize,lmsize,psize,frame,page,ftable[20],frameno;
void info()
{
printf("\n\nMEMORY MANAGEMENT USING PAGING\n\n");
printf("\n\nEnter the Size of Physical memory: ");
scanf("%d",&pmsize);
printf("\n\nEnter the size of Logical memory: ");
scanf("%d",&lmsize);
printf("\n\nEnter the partition size: ");
scanf("%d",&psize);
frame = (int) pmsize/psize;
page = (int) lmsize/psize;
printf("\nThe physical memory is divided into %d no.of frames\n",frame);
printf("\nThe Logical memory is divided into %d no.of pages",page);
}
void assign()
{
int i;
for (i=0;i<page;i++)
{
ptable[i].fno = -1;
ptable[i].pbit= -1;
}
for(i=0; i<frame;i++)
ftable[i] = 32555;
for (i=0;i<page;i++)
{
printf("\n\nEnter the Frame number where page %d must be placed: ",i);
scanf("%d",&frameno);
ftable[frameno] = i;
if(ptable[i].pbit == -1)
EXPERIMENT-14
14.3 PROGRAM
#include<stdio.h>
#include<conio.h>
Void main()
{
int i,s[10],S,m,a[10],n,ch,total=0;
char p[10];
printf(“enter total no of process”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“enter the process name %d”,i)
scanf(“%s”,&p[i])
printf(“enter the size of each process %d”,i)
scanf(“%d”,&s[i])
}
printf(“enter total no of frames”);
scanf(“%d”,&m);
printf(“enter ur choice”);
scanf(“%d”,&ch);
switch(ch)
{
case 1: printf(“Fixed Allocation”);
for(i=0;i<n;i++)
{
a[i]=m/n;
printf(“Allocation of frames to process %c is %d”,p[i],a[i]);
}
Case 2: printf(“Proportional Allocation”);
for(i=0;i<n;i++)
{
total+=s[i];
a[i]=(s[i]/total)*m;
Printf(“Allocation of frames for process %c is %d”,p[i],a[i]);
}
default: printf(“invalid choice”);
}
}
Enter ur choice: 1
Fixed Allocation
Enter ur choice 2
Proportional Allocation
2. What is the process of mapping a logical address to physical address with respect to the paging
memorymanagement technique?
3.Whether the paging memory management technique suffers with internal or external fragmentationproblem.
Why?
15.1 OBJECTIVE
Simulate the prediction of deadlock in operating system when all the processes announce their resource requirement in
advance.
#include<stdio.h>
#include<conio.h>
void main()
{
int found,flag,l,p[4][5],tp,e[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0,tr;
clrscr();
pritnf(“enter total no of process”);
scanf(“%d”,&tp);
pritnf(“enter total no of resources”);
scanf(“%d”,&tr);
printf(“enter claim matrix”);
for(i=0;i<tp;i++)
for(j=0;j<tr;j++)
{
scanf(“%d”,&c[i][j]);
}
printf(“enter allocation matrix”);
for(i=0;i<tp;i++)
for(j=0;j<tr;j++)
{
scanf(“%d”,&p[i][j]);
}
printf(“enter the resource vectors”);
for(i=0;i<tr;i++)
scanf(“%d”,&r[i]);
printf(“enter the availability matrix”));
for(i=0;i<tr;i++)
{
scanf(“%d”,&r[i]);
temp[i]=a[i];
}
for(i=0;i<tp;i++)
{
sum=0;
for(j=0;j<tr;j++)
{
sum+=p[i][j];
01001
00101
00001
1 0 1 0 1
00001
2.What is deadlock?
1.Write a C program to implement deadlock detection technique for the following scenarios?
1.How can be the resource allocation graph used to identify a deadlock situation?
1. OBJECTIVE
2. PROGRAM
#include<conio.h>
#include<stdio.h>
int optimalframe(int w[],int m);
void main()
{
int i,j,n,m,r,pagef,l,h,p;
int a[100],b[100],w[10];
pagef=0;
clrscr();
printf("enter the number of pages\n");
scanf("%d",&n);
printf("enter the number of frames in main memory\n");
scanf("%d",&m);
for(i=0;i<m;i++)
b[i]=-1;
for(i=0;i<n;i++)
{
printf("enter the element %d\n",i);
scanf("%d",&a[i]);
}
for(i=0;i<m;i++)
{
b[i]=a[i];
for(r=0;r<m;r++)
printf("%d ",b[r]);
printf("\n");
pagef++;
}
for(i=m;i<n;i++)
{
for(j=0;j<m;j++)
{
if(b[j]==a[i])
{
printf("the page %d is already present in main memory\n",a[i]);
break;
}
}
if(j==m)
{
for(l=0;l<m;l++)
{
for(p=i+1;p<n;p++)
{
1. OBJECTIVE
2. PROGRAM
# include <stdio.h>
# include<pthread.h>
# include<cursors.h>
void longdelay()
for(t1=0;t1<64000;t1++);
for(t2=0;t2<64000;t2++);
void shortdelay()
int t3,t4;
for(t3=0;t3<32000;t3++)
for(t4=0;t4<32000;t4++)
void test(int i)
int j,k,m,p,q,r,c;
j=1-i;
for(k=0;k<3;k++)
flag[i]=1;
while(flag[j])
if (turn==j)
flag[i]=0;
printf(“Iam waiting:%d”,i);
while(turn==j);
flag[i]=1;
longdelay();
c=bal;
/*critical section*/
printf(“flag[%d]=%d, flag[%d]=%d”,i,flag[i],j,flag[j]);
printf(“turn=%d\n”,turn);
bal=c+1000;
turn=j;
flag[i]=0;
shortdelay();
int main()
pthread_t t1,t2;
pthread_creat(&t,NULL,(void*)&test,(void*)0);
pthread_creat(&t2,NULL,(void*)&test,(void*)1);
pthread_join(t1,NULL);
sleep(s);
printf(“Parent terminated:%d”,bal);
return(0); }