Académique Documents
Professionnel Documents
Culture Documents
OBJECTIVES
LIST OF EXPERIMENTS
LIST OF EXPERIMENTS
4. Shell Programming
6. Implement Semaphores
a) Singleall
15. Implement level
file directory
allocation strategies
b)a)Two level
Contiguous
16. Implement Segmentation Technique of memory management
b) Linked
c)c)Hierarchical
Indexed
d) DAG
1. Calendar Command:
[IT@it clab]$ cal 11 2018
November 2018
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 22 29 30 31
2. Date command:
[IT@it clab]$ date
Wed Oct 21 12:45:25 IST 2018
[IT@it clab]$ date +%m
10
3.Who command:
[IT@it ~]$ who
IT tty5 2018-10-21 12:50
IT pts/1 2018-10-21 10:50 (197.168.1.5)
karthi pts/2 2018-10-21 10:51 (197.168.1.6)
4.Who am I command:
5.Finger Command:
[IT@it ~]$ finger
Login Name Tty Idle Login Time Office Office Phone
karthi pts/2 29 Oct 22 12:53 (197.168.1.6)
IT tty5 31 Oct 22 12:52
IT pts/1 Oct 22 12:55 (197.168.1.5)
6.Help command:
To display the help information about a particular command.
[IT@it clab]$ man clear
clear - clear the terminal screen
7.Clear Command:
To clear the screen.
[IT@it clab]$ clear
8. ID command:
To display the user id and group id information about a user. i.e. user identity.
[IT@it clab]$ id
uid=835(IT) gid=835(IT) groups=835(IT) context=user_u:system_r:unconfined_t
9. write command:
1.Create a file:
2.Head Command:
Displays the initial part of the text file. By default, it displays the first 10 lines of a file.
3.Tail command:
Displays the last part of he text file. By default, it displays the last 10 lines of a file.
[IT@it clab]$ tail -1 f3.txt
I am studying B.Tech IT in SJCE.
5.Copy a file:
[IT@it ~]$ cp f1.c f5.c
[IT@it ~]$ ls
f1.c f2.c f3.txt f4.txt f5.c ITal
7.Remove a file:
[IT@it ~]$ rm f3.txt
[IT@it ~]$ ls
f2.c f4.txt f5.c f4.c ITal
[IT@it ~]$
11.Find Command:
It is used to locate files in a directory and its subdirectories.
[IT@it clab]$ find
.
./1.c
./asd.bak
./f1.txt
./file_copy.c
./f2.c
./a.out
DIRECTORY COMMANDS
1. Create a directory:
[IT@it ~]$ mkdir chem.
5. Remove a directory:
[IT@it ~]$ rmdir ITal
[IT@it ~]$ ls
f1.c f2.c f3.txt f4.txt f4.c f5.c
8.Link Command:
make link between files
[IT@it clab]$ ls
f1.c f2.c f4.c f5.c f3.txt f4.txt IT
[IT@it clab]$ ln -t IT f5.c
[IT@it clab]$ cd IT
[IT@it dma]$ ls
F5.c
AIM:
To write a ‘C’ program for implementing OS system calls fork, exec, getpid, exit, wait, close,
stat, opendir, readdir.
ALGORITHM:
1. Start
2. Create process using fork system call.
3. Check the fork() return value to ensure successful process creation.
4. Display the parent and child pid.
5. Stop.
PROGRAM
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
int pid,pid1,pid2;
pid=fork();
if(pid==-1)
{
printf(“ERROR IN PROCESS CREATION \n”);
exit(1);
}
if(pid!=0)
{
pid1=getpid();
printf(“\n The Parent Process ID is %d\n”, pid1);
}
else
{
pid2=getpid();
printf(“\n The Child Process ID is %d\n”, pid2);
}
}
OUTPUT
The Child Process ID is 8640
ALGORITHM:
1. Start
2. Input directory name to opendir and readdir system call to open and read contents from
directory.
3. Use exit system call if directory not exists.
4. Close directory after reading using closedir()
5. Stop.
#include<stdio.h>
#include<dirent.h>
struct dirent *dptr;
int main(int argc, char *argv[])
{
char buff[100];
DIR *dirp;
printf(“\n\n ENTER DIRECTORY NAME:”);
scanf(“%s”, buff);
if((dirp=opendir(buff))==NULL)
{
printf(“The given directory does not exist”);
exit(1);
}
while(dptr=readdir(dirp))
{
printf(“%s\n”,dptr->d_name);
}
closedir(dirp);
}
OUTPUT
ENTER THE DIRECTORY NAME: UNITS
CHAP1.C
CHAP2.C
RESULT
AIM:
To write a ‘C’ program for implementing OS system calls fork, exec, getpid, exit, wait, close,
stat, opendir, readdir.
ALGORITHM:
1. Start
2. Input directory name to opendir and readdir system call to open and read contents from directory
3. Display the file names inside directory.
4. Stop.
PROGRAM
#include<stdio.h>
#include<dirent.h>
main(int argc, char **argv)
{
DIR *dp;
struct dirent *link;
dp=opendir(argv[1]);
printf(“\n Contents of the directory %s are \n”, argv[1]);
while((link=readdir(dp))!=0)
printf(“%s”,link->d_name);
closedir(dp);
}
OUTPUT
Contents of the directory OS are
Priority.c
Robin.c
Copy
ALGORITHM:
1. Start
2. Input file name and word to be searched.
3. Use fopen to open file in read mode.
4. Use fgets to read each string from file.
5. Find the occurrences of the given word in a file using strstr() string handling function.
6. Stop.
PROGRAM
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define max 1024
void usage()
{
OUTPUT
Sample.txt 2 apple
RESULT
LARGEST OF N NUMBERS
AIM:
To write a shell program to find largest of n numbers.
ALGORITHM:
1. Input the total number of elements (n) .
2. Let i=0
3. Read the elements one by one in an array a$i .
4. Initialize large=0 .
5. Using a for loop, do the following for all elements in the array:
Let temp=a$i ie. Assign the array element to temp.
If temp greater than large, then reassign large=temp
6. large displays the largest of all elements.
7. Stop.
PROGRAM:
echo "Enter the total number of elements"
read n
echo "Enter the elements One by One"
i=0
for((i=0 ; i<$n ; i++))
do
read a$i
done
large=0
for((i=0 ; i<$n ; i++))
do
((temp=a$i))
if (($temp>$large))
then
((large=$temp))
fi
done
echo "The largest of all the elements is: $large"
OUTPUT:
[IT@it ~]$ sh 2C.sh
Enter the total number of elements
4
Enter the elements one by one
20
25
50
10
The largest of all the elements is: 50
AIM:
To write a ‘C’ program to implement FCFS Scheduling.
ALGORITHM:
1. Start.
2. Include the header files for simulating FCFS scheme.
3. Declare the variables to calculate the essential aspects of FCFS.
4. Initially get the process time, arrival time and burst time.
5. Swap all the processes in such a way that they are arranged in FCFS order.
6. Prepare the gantt chart for each process so that their waiting time, turn around time is calculated.
7. Calculate the average waiting time and average turn around time and display the result.
8. Stop
PROGRAM:
#include<stdio.h>
void main()
{
int i,n,br[10],wt[10],wat[10],tr[10],ttr=0,twt=0,twat=0;
float awat,atur;
printf("Enter no. of process :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the burst time for process %d: ",(i+1));
scanf("%d",&br[i]);
}
printf("\nPROCESS\tBURST TIME\tWAITING TIME\tTURN AROUND TIME\n");
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+br[i];
tr[i]=wt[i]+br[i];
printf("\n%d\t\t%d\t\t%d\t\t%d\n",i+1,br[i],wt[i],tr[i]);
}
for(i=0;i<n;i++)
{
ttr=ttr+tr[i];
twat=twat+wt[i];//wat i changed to wt
}
printf("\nGAANT CHART\n\n");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n");
for(i=0;i<n;i++)
{
OUTPUT
[IT@localhost ~]$ ./a.out
Enter no. of process :3
Enter the burst time for process 1: 1
Enter the burst time for process 2: 4
Enter the burst time for process 3: 5
PROCESS BURST TIME WAITING TIME TURN AROUND TIME
1 1 0 1
2 4 1 5
3 5 5 10
GAANT CHART
-------------------------
|p1 |p2 |p3 |
-------------------------
0 1 5 10
RESULT:
AIM:
To write a ‘C’ program to implement SJF Scheduling.
ALGORITHM:
1. Include the header files for simulating SJF scheme.
2. Declare the variables to calculate the essential aspects of SJF.
3. Initially get the process time and burst time.
4. Swap all the processes in such a way that they are arranged in shortest job first (SJF) order.
5. Prepare the gantt chart for each process so that their waiting time, turn around time is calculated.
6. Calculate the average waiting time and average turn around time and display the result.
// SJF SCHEDULING ALGORITHM
PROGRAM:
#include<stdio.h>
void main()
{
int i,j,k,n,p[10],br[10],wt[10],tr[10],ttr=0,twt=0,t;
float awat,atur;
printf("\nEnter no. of process :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the burst time for process %d: ",(i+1));
scanf("%d",&br[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(br[i]>br[j])
{
t=br[i];
br[i]=br[j];
br[j]=t;
t=p[i];
p[i]=p[j];
p[j]=t;
}}}
printf("\nPROCESS\tBURST TIME \t WAITING TIME \t TURN AROUND TIME\n");
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+br[i];
tr[i]=wt[i]+br[i];
}
for(i=0;i<n;i++)
{
ttr=ttr+tr[i];
twt=twt+wt[i];
} for(i=0;i<n;i++) { printf("\n%d\t\t%d\t\t%d\t\t%d\n",p[i],br[i],wt[i],tr[i]);
} printf("\nGAANT CHART\n\n");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n");
for(i=0;i<n;i++)
{
printf(" P%d |",p[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n");
for(i=0;i<=n;i++)
{
printf("%d\t",wt[i]);
}
awat=(float)twt/n;
atur=(float)ttr/n;
printf("\nTotal waiting time :%d\n",twt);
printf("\nTotal turnaround time :%d\n",ttr);
printf("\nAverage waiting time :%.2f\n",awat);
printf("\nAverage turn around time :%.2f\n",atur);
}
OUTPUT
[IT@localhost ~]$ ./a.out
[IT@localhost~]$ gcc sjf.c
[IT@localhost~]$ ./a.out
Enter no. of process :3
Enter the burst time for process 1: 3
Enter the burst time for process 2: 2
Enter the burst time for process 3: 1
PROCESS BURST TIME WAITING TIME TURN AROUND TIME
3 1 0 1
2 2 1 3
1 3 3 6
GAANT CHART
------------------------
| P3 | P2 | P1 |
------------------------
0 1 3 6
Total waiting time :4
Total turnaround time :10
Average waiting time :1.33
Average turn around time :3.33
RESULT:
AIM:
To write a ‘C’ program to implement PRIORITY Scheduling.
ALGORITHM:
1. Start
2. Include the header files for simulating priority scheme.
3. Declare the variables to calculate the essential aspects of priority scheme.
4. Initially get the process time, arrival time and burst time along with their priorities.
5. Execute the process by referring to their priority values.
6. Prepare the gantt chart for each process so that their waiting time, turn around time is calculated.
7. Calculate the average waiting time and average turn around time and display the result.
8. Stop.
OUTPUT
[IT@localhost~]$ gcc prior.c
[IT@localhost~]$ ./a.out
Enter no. of process :4
Enter the burst time for process 1: 8
Enter the burst time for process 2: 6
Enter the burst time for process 3: 4
Enter the burst time for process 4: 5
Enter the priority for process 1: 3
Enter the priority for process 2: 1
Enter the priority for process 3: 2
Enter the priority for process 4: 4
PROCESS BURST TIME PRIORITY WAITING TIME TURNAROUND TIME
2 6 1 0 6
3 4 2 6 10
1 8 3 10 18
4 5 4 18 23
GAANT CHART
--------------------------------
P2 | P3 | P1 | P4 |
--------------------------------
0 6 10 18 23
Total waiting time :34
Total turnaround time :57
Average waiting time :8.50
Average turn around time :14.25
RESULT:
if(bur[x]>=t)
{
bur[x]=bur[x]-t;
a[j+1]=a[j]+t;
if(b[x]==1)
{
p[s]=x;
k[s]=a[j+1];
s++;
}
j++;
b[x]=b[x]-1;
printf(" P%d |",x+1);
}
else if(bur[x]!=0)
{
a[j+1]=a[j]+bur[x];
bur[x]=0;
if(b[x]==1)
{
p[s]=x;
k[s]=a[j+1];
s++;
}
j++;
b[x]=b[x]-1;
printf(" P%d |",x+1);
}
}
printf("\n");
for(i=0;i<m;i++)
printf("--------");
printf("\n");
for(j=0;j<=m;j++)
printf("%d\t",a[j]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(p[i]>p[j])
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
temp=k[i];
k[i]=k[j];
k[j]=temp;
} } }
for(i=0;i<n;i++)
{
wat[i]=k[i]-bur1[i];
tur[i]=k[i];
}
printf("\nPROCESS\tBURST TIME \t WAITING TIME \t TURN AROUND TIME\t");
printf("RESPONSE TIME\n");
for(i=0;i<n;i++)
{
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d\n",p[i]+1,bur1[i],wat[i],
tur[i],a[i]);
}
for(i=0;i<n;i++)
{
ttur=ttur+tur[i];
twat=twat+wat[i];
tres=tres+a[i];
}
awat=(float)twat/n;
atur=(float)ttur/n;
ares=(float)tres/n;
printf("\nTotal waiting time:%d",twat);
printf("\nTotal turnaround time:%d",ttur);
// printf("\nTotal response time:%d",tres);
printf("\nAverage waiting time :%.2f",awat);
printf("\nAverage turn around time :%.2f",atur);
//printf("\nAverage response time:%.2f",ares);
}
OUTPUT
[IT@localhost ~]$ ./a.out
[IT@localhost~]$ gcc round.c
[IT@localhost~]$ ./a.out
Enter no. of process :3
Enter the burst time for process 1: 10
Enter the burst time for process 2: 12
Enter the burst time for process 3: 15
Enter the slicing time :5
GAANT CHART
----------------------------------------------------------------
| P1 | P2 | P3 | P1 | P2 | P3 | P2 | P3 |
----------------------------------------------------------------
0 5 10 15 20 25 30 32 37
PROCESS. BURST TIME. WAITING TIME. TURNAROUND TIME. RESPONSE TIME
1 10 10 20 0
2 12 20 32 5
3 15 22 37 10
Total waiting time:52
Total turnaround time:89
Average waiting time :17.33
Average turn around time :29.67
RESULT:
AIM:
To write a program to implement producer consumer problem using semaphore
ALGORITHM:
1. Declare the buffer size variable.
2. Initialize empty, full and the value of mutex.
3. For case 1 , produce the item till the buffer is full after performing the wait operation
Of variables empty and mutex.
4. Then perform signal of full.
5. For case 2, consume the item till the buffer is empty. Perform the wait and signal operation..
6. print the contents of the buffer.
mutex=signal(mutex);
break;
case 2:
full=wait(full);
mutex=wait(mutex);
if(f==0)
{
printf("\nOne Item is Consumed:\n");
printf("\nConsumed item is: %s\n",buffer[0].a);
for(i=0;i<SIZE;i++)
strcpy(buffer[i].a,buffer[i+1].a);
empty=signal(empty);
}
else
{
printf("\nBuffer is empty\n");
f=0;
}
mutex=signal(mutex);
break;
case 3:
if(full!=0)
{
for(i=0;i<full;i++)
printf("\n%s\n",buffer[i].a);
}
else
printf("\nBuffer is empty\n");
break;
case 4:
exit(0);
default:
printf("Enter Correct Option");
break;
}}}
int wait(int s)
{
if(s==0)
f=1;
else
s--;
return s;
}
int signal(int s)
{
s++;
return s;
}
OUTPUT
[IT@localhost ~]$ ./a.out
Producer Consumer Problem:
RESULT:
AIM:
To write a program to implement inter process communication using queues.
ALGORITHM:
1. Create and declare two description for reading and writing.
2. Set child process to write the message to the buffer.
3. Set the parent to read the message from buffer.
4. Print the message from the buffer.
5. Stop the execution.
PROGRAM
//PIPES
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void)
{
int fd[2], nbytes;
pid_t childpid;
char string[] = "Hai How are you!\n";
char readbuffer[80];
pipe(fd);
if(childpid == 0)
{
/* Child process closes up input side of pipe */
close(fd[0]);
return(0);
}
OUTPUT
[IT@localhost ~]$ ./a.out
client writing ...
: server Received string: Hai How are you !
[IT@localhost ~]$
//SHARED MEMORY
ALGORITHM:
1. Create and shared memory using shmget.
2. Attach pointer to a memory using shmat.
3. Create child process to write data to memory.
4. Print the shared memory data using server process.
5. Stop the execution.
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#define SHMSZ 27
main()
{
char c;
int shmid,childpid;
key_t key;
char *shm, *s;
key = 5679;
}
else
{
wait(15);
for (s = shm; *s != NULL; s++)
putchar(*s);
putchar('\n');
}
exit(0);
}
OUTPUT
[IT@localhost ~]$ ./a.out
abcdefghijklmnopqrstuvwxyz
[IT@localhost ~]$ ipcs
//MESSAGE QUEUE
ALGORITHM:
1. Create a queue using msgget()system call.
2. Create child process using fork() system call.
3. The fork returns a zero to the child process and process id of child to parent.
4. The child process sends messages to the queue using msgsnd(0system call.
5. The parent process reads from the queue using msgrcv() system call.
6. The parent waits for the child to exit and then exit.
#define key 50
main()
{
int msgqid,pid;
struct
{
int mtype;
char mtost[30];
}buf;
msgqid=msgget(key,IPC_CREAT|0454);
if(msgqid==0)
{
printf("Error in the queue creation");
exit(1);
}
pid=fork();
if(pid==1)
{
printf("Error in the process creation");
exit(1);
}
if(pid==0)
{
strcpy(buf.mtost,"Happy day ahead”);
buf.mtype=2;
msgsnd(msgqid,&buf,sizeof(buf.mtost),IPC_NOWAIT);
strcpy(buf.mtost,"Apple keeps doc away");
buf.mtype=1;
msgsnd(msgqid,&buf,sizeof(buf.mtost),IPC_NOWAIT);
msgrcv(msgqid,&buf,sizeof(buf.mtost),1,IPC_NOWAIT);
printf("Message is %s",buf.mtost);
}
}
OUTPUT
[IT@localhost~]$gcc ipcqueue.c
[IT @elserver ~]$ ./a.out
Message is Apple keeps doc away.
[IT @elserver ~]$
RESULT:
Data structures
n-Number of process, m-number of resource types.
Available: Available[j]=k, k – instance of resource type Rj is available.
Max: If max[i, j]=k, Pi may request at most k instances resource Rj.
Allocation: If Allocation [i, j]=k, Pi allocated to k instances of resource Rj
Need: If Need[I, j]=k, Pi may need k more instances of resource type Rj,
Need[I, j]=Max[I, j]-Allocation[I, j];
Safety Algorithm
1. Work and Finish be the vector of length m and n respectively, Work=Available and Finish[i] =False.
2. Find an i such that both
Finish[i] =False
Need<=Work
If no such I exists go to step 4.
ALGORITHM:
PROGRAM
#include<stdio.h>
#include<process.h>
void main()
{
int allocation[10][5],max[10][5],need[10][5],available[3],flag[10],sq[10];
int n,r,i,j,k,count,count1=0;
printf("\n Input the number of processes running ( <10 )..");
scanf("%d",&n);
for(i=0;i<10;i++)
flag[i]=0;
printf("\n Input the number of resources ( <5 )..");
scanf("%d",&r);
printf("\n Input the allocation matrix for the processes in row major order..\n");
for(i=0;i<n;i++)
{
printf("\n Process %d\n",i);
for(j=0;j<r;j++)
{
printf("\n Resource %d\n",j);
scanf("%d",&allocation[i][j]);
}
}
printf("\n Input the no. of resources that a process can maximum have..\n");
for(i=0;i<n;i++)
{
printf("\n Process %d\n",i);
for(j=0;j<r;j++)
{
printf("\n Resource %d\n",j);
scanf("%d",&max[i][j]);
}
}
printf("\n Input the no. of available instances of each resource..\n");
for(i=0;i<r;i++)
{
printf("\n Resource %d : ",i);
scanf("%d",&available[i]);
}
printf("\n The need matrix is as follows : \n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
need[i][j]= max[i][j]-allocation[i][j];
printf("\t %d",need[i][j]);
}
printf("\n");
}
do{
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
{
if(flag[i]==0)
{
count=0;
for(j=0;j<r;j++)
{
if(available[j]>=need[i][j])
count++;
}
if(count==r)
{
count1++;
flag[i]=1;
sq[count1-1]=i;
for(j=0;j<r;j++)
{
available[j]=available[j]+allocation[i][j];
}
break;
}
}
}
}
if(count1!=n)
{
printf("\n---------------IT'S AN UNSAFE STATE---------------");
break;
}
}while(count1!=n);
if(count1==n)
{
printf("\n *******************IT'S A SAFE STATE*******************");
printf("\n The safe sequence is....\n");
for(i=0;i<n;i++)
printf("\t P%d",sq[i]);
printf("\n");
printf("\n The available matrix is now : ");
for(i=0;i<r;i++)
printf("\t %d",available[i]);
}
OUTPUT
[IT@localhost ~]$
RESULT
ALGORITHM:
PROGRAM
#include<stdio.h>
int main()
{
int alloc[10][10],req[10][10],ins[10],avail[10],tp,tr,i,j;
int tmp[10]={0},count=0;
int finish[10]={0},flag;
printf("Enter total no of processes:");
scanf("%d",&tp);
printf("Enter total no of resources:");
scanf("%d",&tr);
printf("Enter the Allocation Matrix:\n");
for(i=0;i<tp;i++)
{
for(j=0;j<tr;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the Request Matrix:\n");
for(i=0;i<tp;i++)
{
for(j=0;j<tr;j++)
{
scanf("%d",&req[i][j]);
}
}
printf("Enter the resource instance vector:\n");
for(i=0;i<tr;i++)
{
scanf("%d",&ins[i]);
}
//To calculate resource availability vector
for(i=0;i<tp;i++)
{
for(j=0;j<tr;j++)
{
tmp[i]+=alloc[j][i]; //sum calculated columnwise for allocation matrix
}
}
printf("\nCalculated Availability Vector:\n");
for(i=0;i<tp;i++)
{
avail[i]=ins[i]-tmp[i];
printf("\t%d",avail[i]);
}
while(count!=tp)
{ //if finish array has all true's(all processes to running state)
//deadlock not detected and loop stops!
for(i=0;i<tp;i++)
{
count=0;
//To check whether resources can be allocated any to blocked process
if(finish[i]==0)
{
for(j=0;j<tr;j++)
{
if(req[i][j]<=avail[j])
{
count++;
}
}
flag=0;
if(count==tr)
{
for(j=0;j<tr;j++)
{
avail[j]+=alloc[i][j]; //allocated reources are released and added to available!
}
finish[i]=1;
printf("\nProcess %d is transferred to running state and assumed finished",i+1);
}
else
flag=1;
}
}
count=0;
for(j=0;j<tr;j++)
{
if(finish[j]==1)
{
count++;
}
}
}
for(i=0;i<tp;i++)
{
if(finish[i]==0)
{
printf("\n Oops! Deadlock detected and causing process is:process(%d)\n",i+1);
break;
}
}
i=i-1;
if(finish[i]==1)
printf("\nHurray! Deadlock not detected:-)\n");
return 0;
}
OUTPUT
[IT@localhost ~]$
RESULT
AIM
To implement POSIX thread operations and synchronize using mutex variable.
ALGORITHIM
PROGRAM
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<pthread.h>
#include<stdlib.h>
pthread_t tid[2];
int counter;
pthread_mutex_t lock;
unsigned long i = 0;
counter += 1;
printf("\n Job %d started\n", counter);
for(i=0; i<(0xFFFFFFFF);i++);
pthread_mutex_unlock(&lock);
return NULL;
}
int main(void)
{
int i = 0;
int err;
if (pthread_mutex_init(&lock, NULL) != 0)
{
printf("\n mutex init failed\n");
return 1;
}
while(i < 2)
{
err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
if (err != 0)
printf("\ncan't create thread :[%s]", strerror(err));
i++;
}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy(&lock);
return 0;
}
OUTPUT
[IT@localhost ~]$
Job 1 started
Job 2 started
Job 1 finished
Job 2 finished
RESULT
AIM:
To implement memory allocation methods first fit, best fit & worst fit for fixed partitions.
#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++) //allocation as per first fit
for(j = 0; j < bno; j++)
if(flags[j] == 0 && bsize[j] >= psize[i])
{
allocation[j] = i;
flags[j] = 1;
break;
}
//display allocation details
OUTPUT
PROGRAM
#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];
St.Joseph’s College of Engineering ISO 9001:2008
40
CS8461-Operating systems Lab Department of IT 2019-2020
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]);
}
OUTPUT
PROGRAM
#include<stdio.h>
main()
{
int i,j,temp,f[10],fp[10];
int no,p[15],part[15],pno,pr[15],prmem[15];
printf("\n*******************************************");
printf("\n IMPLEMENTATION OF WORST-FITALGORITHM");
printf("\n*******************************************");
printf("\n Enter the number of partitions");
scanf("%d",&no);
for(i=1;i<=no;i++)
{
p[i]=i;
printf("Enter the memory for partition %d:\t",i);
scanf("%d",&part[i]);
}
//Arrange partitions in descending order
for(i=1;i<=no;i++)
{
for(j=1;j<=i;j++)
{
if(part[j]<part[i])
St.Joseph’s College of Engineering ISO 9001:2008
42
CS8461-Operating systems Lab Department of IT 2019-2020
{
temp=part[i];
part[i]=part[j];
part[j]=temp;
temp=p[i];
p[i]=p[j];
p[j]=temp:
}}}
printf("\nFree memory");
for(i=1;i<=no;i++)
{
printf("\n partition %d: \t %d",p[i],part[i]);
}
//Input process details
printf("\n Enter the number of process");
scanf("%d",&pno);
for(i=1;i<=pno;i++)
{
pr[i]=i;
printf("Enter the size for process %d:\t",i);
scanf("%d",&prmem[i]);
}
//Applying Worst-Fit Method
printf("\n----------------------------------------\n");
printf("PROCESS|\t PARTITION| \t FREE_MEMORY|\n");
printf("\n----------------------------------------\n");
j=1;
for(i=1;i<=no;i++)
{
f[i]=0;
fp[j]=0;
}
while(j<=pno)
{
for(i=1;i<=no;i++)
{
if((part[i]>=prmem[j]) && (f[i]==0))
{
part[i]=part[i]-prmem[j];
fp[j]=1;//process alloted
f[i]=1; //partition alloted
printf("%d \t %d \t %d \n",pr[j],p[i],part[i]);
goto l1;
}}
l1:
j++;
}
for(i=1;i<=no;i++)
{
if(f[i]==0)
{
printf(" \t %d \t %d \n",p[i],part[i]);
}}
printf("The following process is not allocatted:");
for(i=1;i<=pno;i++)
{
if(fp[i]==0)
{
printf(" %d ",pr[i]);
}}}
OUTPUT
*******************************************
IMPLEMENTATION OF WORST-FITALGORITHM
*******************************************
Enter the number of partitions4
Enter the memory for partition 1: 35
Enter the memory for partition 2: 25
Enter the memory for partition 3: 50
Enter the memory for partition 4: 60
Free memory
partition 4: 60
partition 3: 50
partition 1: 35
partition 2: 25
Enter the number of process4
Enter the size for process 1: 25
Enter the size for process 2: 15
Enter the size for process 3: 20
Enter the size for process 4: 30
----------------------------------------
PROCESS| PARTITION| FREE_MEMORY|
----------------------------------------
1 4 35
2 3 35
3 1 15
2 25
The following process is not allocatted: 4 i
RESULT:
AIM:
To implement the Memory management policy- Paging.
ALGORITHM:
PROGRAM
#include <stdio.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)
{
ptable[i].fno = frameno;
ptable[i].pbit = 1;
}
}
printf("\n\nPAGE TABLE\n\n");
printf("PageAddress FrameNo. PresenceBit\n\n");
for (i=0;i<page;i++)
printf("%d\t\t%d\t\t%d\n",i,ptable[i].fno,ptable[i].pbit);
printf("\n\n\n\tFRAME TABLE\n\n");
printf("FrameAddress PageNo\n\n");
for(i=0;i<frame;i++)
printf("%d\t\t%d\n",i,ftable[i]);
}
void cphyaddr()
{
int laddr,paddr,disp,phyaddr,baddr;
// clrscr();
printf("\n\n\n\tProcess to create the Physical Address\n\n");
printf("\nEnter the Base Address: ");
scanf("%d",&baddr);
printf("\nEnter theLogical Address: ");
scanf("%d",&laddr);
info();
assign();
cphyaddr();
OUTPUT
RESULT
AIM
To write a c program to implement FIFO page replacement algorithm
ALGORITHM
1. Start the process
2. Declare the size with respect to page length
3. Check the need of replacement from the page to memory
4. Check the need of replacement from old page to new page in memory
5. Forma queue to hold all pages
6. Insert the page require memory into the queue
7. Check for bad replacement and page fault
8. Get the number of processes to be inserted
9. Display the values
10. Stop the process
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER :\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tref string\t page frames\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("Page Fault Is %d",count);
return 0;
}
OUTPUT
RESULT
AIM:
ALGORITHM:
PROGRAM
#include<stdio.h>
main()
{
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
printf("Enter no of pages:");
scanf("%d",&n);
printf("Enter the reference string:");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of frames:");
scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{
c1=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
}
if(c1==f)
{
c++;
if(k<f)
{
q[k]=p[i];
k++;
for(j=0;j<k;j++)
printf("\t%d",q[j]);
printf("\n");
}
else
{
for(r=0;r<f;r++)
{
c2[r]=0;
for(j=i-1;j<n;j--)
{
if(q[r]!=p[j])
c2[r]++;
else
break;
}
}
for(r=0;r<f;r++)
b[r]=c2[r];
for(r=0;r<f;r++)
{
for(j=r;j<f;j++)
{
if(b[r]<b[j])
{
t=b[r];
b[r]=b[j];
b[j]=t;
}
}
}
for(r=0;r<f;r++)
{
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
}
printf("\n");
}
}
}
printf("\nThe no of page faults is %d",c);
return 0;
}
OUTPUT
RESULT
AIM:
To implement optimal page replacement technique.
ALGORITHM:
Here we select the page that will not be used for the longest period of time.
1. Start Program
2. Read Number Of Pages And Frames
3. Read Each Page Value
4. Search For Page In The Frames
5. If Not Available Allocate Free Frame
6. If No Frames Is Free Repalce The Page With The Page That Is Not Used In Next N
Pages(N Is Number Of Frames)
7. Print Page Number Of Page Faults
8. Stop process.
PROGRAM
#include<stdio.h>
int findmax(int*);
int n;
int main()
{
int seq[30],fr[5],pos[5],find,flag,max,i,j,m,k,t,s,pf=0;
int count=1,p=0;
float pfr;
printf("%d\t",fr[count] );
count++;
pf++;
}
i++;
}
printf("\n");
for(i=p;i<max;i++)
{
flag=1;
for(j=0;j<n;j++)
{
if(seq[i]==fr[j])
flag=0;
}
if(flag!=0)
{
for(j=0;j<n;j++)
{
m=fr[j];
for(k=i;k<max;k++)
{
if(seq[k]==m)
{
pos[j]=k;
break;
}
else
pos[j]=-1;
}
}
for(k=0;k<n;k++)
{
if(pos[k]==-1)
flag=0;
}
if(flag!=0)
s=findmax(pos);
if(flag==0)
{
for(k=0;k<n;k++)
{
if(pos[k]==-1)
{
s=k;
break;
}
}
}
pf++;
fr[s]=seq[i];
for(k=0;k<n;k++)
printf("%d\t",fr[k]);
printf("\n");
}
}
pfr=(float)pf/(float)max;
printf("\n theno of page faults are:%d",pf);
printf("\n page fault rate:%f",pfr);
}
int findmax(int a[])
{
int max,i,k=0;
max=a[0];
for(i=0;i<n;i++)
{
if(max<a[i])
{
max=a[i];
k=i;
}
}
return k;
}
OUTPUT
RESULT
ALGORITHM:
PROGRAM
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
int result,i;
if (strcmp(av[1],"-p")!=0)
{
if (mkdir(av[1],0777)==-1)
{
perror("cant make it");
exit(1);
}
else
{
if (chdir(av[1])==-1)
printf("not right\n");
fopen("sample1.txt","w");
}
}
else if (strcmp(av[1],"-p")==0)
{
for(i=2;i<4;i++)
{
tokenizer(av[i]);
if (chdir("/root")==-1)
printf("not right\n");
}
printf("\n Simulating DAG... \n");
DAG();
}
return EXIT_SUCCESS;
}
void tokenizer(char *path)
{
char *dir;
const char *fname[10];
if (mkdir(path, 0777)==-1)
{
dir=strtok(path,"/");
while (dir!=NULL)
{
printf("%s\n",dir);
mkdir(dir, 0777);
printf("\n Enter the file name to be created within %s directory ",dir);
scanf("%s",&fname);
if (chdir(dir)==-1)
printf("not right\n");
fopen(fname,"w");
dir=strtok(NULL,"/");
}
}
void DAG()
{
//const char fname[]="sharedfile";
const char *pt1[10];
const char *pt2[10];
char cwd[1024];
printf("Sharing file between two different directories\n");
printf("\n Enter the source and destination path from where the file to be shared \n ");
scanf("%s",&pt1);
scanf("%s",&pt2);
/* chdir("/root");
if(getcwd(cwd,sizeof(cwd))!=NULL)
{
printf("current working dir %s \n",cwd);
}
else
{
perror("getcwd() error");
}*/
if(link(pt1,pt2)<0)
{
printf(" not done");
}
else
printf("\n link created between %s and %s \n",&pt1,&pt2);
}
OUTPUT
Simulating DAG
RESULT
AIM:
To write a C program to implementation contiguous file allocation techniques.
ALGORITHM:
Step 1: Start.
Step 2: Memory before allocation is displayed.
Step 3: The file Id is entered by the user.
Step 4: the number of blocks memory required and the starting address of the file is given by the user..
Step 5: If starting address and length of block is greater than 20 print error message.
Else , the memory address is replaced by the id.
Display memory after allocation.
Step 6: Stop.
PROGRAM:
#include<stdio.h>
#include<conio.h>
int a[20],num=0;
int fid[10],length[10],start[10];
void filedescriptor();
void display();
void filedescriptor()
{
int i;
printf("\n file id \t starting address \t length \n");
for(i=0;i<num;i++)
printf("%d\t\t\t %d\t\t%d\n",fid[i],start[i],length[i]);
}
void display()
{
int i;
for(i=0;i<20;i++)
printf("%2d",i);
printf("\n");
for(i=0;i<20;i++)
printf("%2d", a[i]);
}
void main()
{
int i,n,k,temp,st,l,id,flag=0,cho;
for(i=0;i<20;i++)
a[i]=0;
clrscr();
printf("\n memory before allocation:\n");
display();
while(1)
{
printf("\n enter the file id:");
scanf("%d",&id);
OUTPUT:
[IT@localhost ~]$
memory before allocation:
0 1 2 3 4 5 6 7 8 910111213141516171819
00000000000000000000
enter the file id:9
enter the number of blocks the file occupies:4
enter the starting address:4
file id starting address length
9 4 4
memory after allocation
0 1 2 3 4 5 6 7 8 910111213141516171819
00 09999000000000000
want to continue?
1.yes
2.no
RESULT
AIM:
To write a C program to implementation linked list file allocation techniques.
ALGORITHM:
1. Start.
2. Get the number of blocks already allocated and its block numbers as input from user.
3. Add that block numbers to a list as allocated block number list and mark that block numbers are
allocated.
4. To perform allocation .Get the starting block number and length of the input file
5. From the starting block check whether each block is in allocated block number list
6. If so Print block is already allocated. Else allocate file to the block number.
7. Continue the loop if the processes want to be repeated.
8. Stop.
PROGRAM
#include<stdio.h>
void main()
{
int f[50],p,i,j,k,a,st,len,n,c;
for(i=0;i<50;i++)
f[i]=0;
printf("enter how many blocks already allocated");
scanf("%d",&p);
printf("\nenter the blocks nos");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
X:
printf("enter index sarting block & length");
scanf("%d%d",&st,&len);
k=len;
if(f[st]==0)
{
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already allocated",j);
k++;
}
}
}
else
printf("\nif u enter one more (yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
OUTPUT:
[IT@localhost ~]$
enter how many blocks already allocated 4
enter the blocks nos 2 4 5 8
enter index starting block & length 1 8
11
2file is already allocated
31
4file is already allocated
5file is already allocated
61
71
8 file is already allocated
91
101
111
121
RESULT
AIM:
To write a C program to implementation indexed file allocation techniques.
ALGORITHM:
1. Start.
2. Get the index block number and number of files in the index block as input from user.
3. Get the file numbers (i.e referred block numbers holding file) as input .
4. Check whether that the input block number is already allocated if so print block allocated
a. Else increase the count and allocate the file.
5. Continue the loop to enter another index block.
6. Stop
PROGRAM
#include<stdio.h>
int main()
{
int f[50],indblk,i,k,j,index[50],n,c,count=0;
for(i=0;i<50;i++)
f[i]=0;
X:
printf("enter index block");
scanf("%d",&indblk);
if(f[indblk]!=1)
{
f[indblk]=1;
printf("enter no of files on index");
scanf("%d",&n);
}
Y:
for(i=0;i<n;i++)
{
scanf("%d",&index[i]);
if(f[index[i]]==0)
{
count++;
}
}
if(count==n)
{
for(j=0;j<n;j++)
f[index[j]]=1;
printf("\nallocated");
printf("\n file indexed");
for(k=0;k<n;k++)
printf("\n%d->%d:%d",indblk,index[k],f[index[k]]);
}
else
{
printf("\n file in the index already allocation");
printf("\nenter another file indexed");
goto Y;
}
printf("\n index is already allocated");
count=0;
printf("\n if u enter one more block(1/0)");
scanf("%d",&c);
if(c==1)
goto X;
OUTPUT:
[IT@localhost ~]$
enter index block 3
enter no of files on index 4
5678
allocated
file indexed
3 5:1
3 6:1
3 7:1
3 8:1
index is already allocated
if u enter one or more block(1/0)
RESULT:
AIM
ALGORITHM
1. Start.
2. Get Segment number, base and limit address.
3. Define insert function to create segments and add segmentation details for each.
4. Define find function to search and get the segment details for the given segment number.
5. To display the segment details get segment number and offset.
6. Segment details are displayed when offset is less than limit of the given segment number
7. calculate physical memory address as
phyaddr=base+offset
PROGRAM
#include<stdio.h>
structlist
{
intseg;
intbase;
intlimit;
structlist *next;
}*p;
voidinsert(struct list *q,int base,int limit,int seg)
{
if(p==NULL)
{
p=malloc(sizeof(structlist));
p->limit=limit;
p->base=base;
p->seg=seg;
p->next=NULL;
}
else
{
while(q->next!=NULL)
{
q=q->next;
printf("yes");
}
q->next=malloc(sizeof(structlist));
q->next->limit=limit;
q->next->base=base;
q->next->seg=seg;
q->next->next=NULL;
}
}
intfind(struct list *q,int seg)
{
while(q->seg!=seg)
{
q=q->next;
}
returnq->limit;
}
intsearch(struct list *q,int seg)
{
while(q->seg!=seg)
{
q=q->next;
}
returnq->base;
}
main()
{
p=NULL;
intseg,offset,limit,base,c,s,physical;
printf("Entersegment table/n");
printf("Enter-1 as segment value for termination\n");
do
{
printf("Entersegment number");
scanf("%d",&seg);
if(seg!=-1)
{
printf("Enterbase value:");
scanf("%d",&base);
printf("Entervalue for limit:");
scanf("%d",&limit);
insert(p,base,limit,seg);
}
}while(seg!=-1);
printf("Enteroffset:");
scanf("%d",&offset);
printf("Enterbsegmentation number:");
scanf("%d",&seg);
c=find(p,seg);
s=search(p,seg);
if(offset<c)
{
physical=s+offset;
printf("Addressin physical memory %d\n",physical);
}
else
{
printf("error");
}
}
OUTPUT
[IT@localhost]# a.out
Entersegment table/nEnter -1 as segment value for termination
Entersegment number1
Enterbase value:2000
Entervalue for limit:500
Entersegment number2
Enterbase value:3000
Entervalue for limit:600
Entersegment number-1
Enteroffset:50
Enterbsegmentation number:2
Addressin physical memory 3050
RESULT
VIVA QUESTIONS
1. Define program and process?
i. A Program is a passive entity, such as the contents of a file stored on disk, whereas a
process is an active entity, with a program counter specifying the next instruction
to execute.
2. What are the activities performed by the main-memory management?
a. Keeping track of which parts of memory are currently being used and by whom.
b. Deciding which processes are to be loaded into memory when memory space becomes
available.
c. Allocating and deal locating memory space as needed.
3. Define file?
i. Is a collection of related information defined by its creator.
4. What are the components consists in I/O- system management?
a. A memory- management component that included buffering, caching, and spooling
b. A general device-driver interface
c. Drivers for specific hardware devices.
5. Define protection?
i. Is any mechanism for controlling the access of programs, processes, or users to the
resources defined by he computer system. This mechanism must provide means for
specification of the controls to be imposed and means of enforcement.
6. What are the services given by the operating system?
a. Program execution
b. I/o operations
c. File-system manipulation
d. Communications
e. Error detection
7. Define system call?
i. It provides the interface between a process and the operating system. Its categories
are process control, file management, device management, information maintenance,
and communications.
8. Define process state?
i. The state of a process is defined in part by the current activity of that process. Each
process may be in one of the following states:
1. New, running, waiting, ready and terminated.
9. Define IPC?It provides a mechanism to allow processes to communicate and to synchronize their
actions without sharing the same address space.
1. Example: Chat program
10. What are the two possibilities exist in terms of execution while creating a process?
a. The parent continues to execute concurrently with its execution
b. The parent waits until some or all of its children have terminated.
11. Define control statements?
i. When a new job is started in a batch system, or when a user logs on to a time-shared
system, a program that reads and interprets control statements is executed
automatically
12. Give the use of critical-section problem?
i. Is to design a protocol that the processes can use to operate.
13. What are the 3 requirements to solve critical-section problem?
i. Mutual exclusion
ii.Progress
iii. Bounded waiting.
first in the cache memory and if it finds the data there (from a previous reading of data), it
does not have to do the more time-consuming reading of data from larger memory.
49. What is a Safe State and what is its use in deadlock avoidance?
When a process requests an available resource, system must decide if immediate allocation
leaves the system in a safe state. System is in safe state if there exists a safe sequence of all
processes. Deadlock Avoidance: ensure that a system will never enter an unsafe state.
50. What is a Real-Time System?
A real time process is a process that must respond to the events within a certain time period.
A real time operating system is an operating system that can run real time processes
successfully.
51. Explain the concept of Reentrancy?
A reentrant procedure can be interrupted and called by an interrupting program, and still execute
correctly on returning to the procedure.
52. Explain Belady's Anomaly?
Also called FIFO anomaly. Usually, on increasing the number of frames allocated to a process
virtual memory, the process execution is faster, because fewer page faults occur. Sometimes, the
reverse happens, i.e., the execution time increases even when more frames are allocated to the
process. This is Belady's Anomaly.
53. What is a binary semaphore? What is its use?
A binary semaphore is one, which takes only 0 and 1 as values. They are used to implement mutual
exclusion and synchronize concurrent processes.
54. What is thrashing?
It is a phenomenon in virtual memory schemes when the processor spends most of its time swapping
pages, rather than executing instructions. This is due to an inordinate number of page faults.
55. List the Coffman's conditions that lead to a deadlock.
1. Mutual Exclusion: Only one process may use a critical resource at a time.
2. Hold & Wait: A process may be allocated some resources while waiting for others.
3. No Pre-emption: No resource can be forcible removed from a process holding it.
4. Circular Wait: A closed chain of processes exist such that each process holds at least one resource
needed by another process in the chain.