List of Experiments: Exp. No. Name of The Experiments Page No
List of Experiments: Exp. No. Name of The Experiments Page No
LIST OF EXPERIMENTS
1. Basics of UNIX commands.
2. Shell Programming.
3. Implement the following CPU scheduling algorithms
a) Round Robin b) SJF c) FCFS d) Priority
4. Implement al file allocation strategies
a) Sequential b) Indexed c) Linked
5. Implement Semaphores
6. Implement al File Organization Techniques
a) Single level directory b) Two level c) Hierarchical d) DAG
7. Implement Bankers Algorithm for Dead Lock Avoidance
8. Implement an Algorithm for Dead Lock Detection
9. Implement e al page replacement algorithms
a) FIFO b) LRU c) LFU
10. Implement Shared memory and IPC
11. Implement Paging Technique of memory management.
12. Implement Threading & Synchronization Applications
TOTAL: 45 PERIODS
LIST OF EXPERIMENTS
AIM:
DIRECTORY COMMANDS
1.Create a directory
roo@sys5:~/Desktop$ mkdir cpl
roo@sys5:~/Desktop$
2. Change from one directory to another
roo@sys5:~/Desktop$ cd cpl
roo@sys5:~/Desktop$
roo@sys5:~/Desktop$ cd ..
roo@sys5:~/Desktop$
4. Remove a directory
roo@sys5:~/Desktop$ rmdir NewFolder
roo@sys5:~/Desktop$
1. Create a file:
roo@sys5:~/Desktop$ cat>a.txt
Hi all
roo@sys5:~/Desktop$
6. Copy a file:
roo@sys5:~/Desktop$ cp a.txt c.txt
[roo@sys5:~/Desktop$
8.Remove a file:
roo@sys5:~/Desktop$ rm d.txt
roo@sys5:~/Desktop$ ls
a.txt b.txt c.txt
roo@sys5:~/Desktop$
13. tr command
roo@sys5:~/Desktop$ tr [:lower:] [:upper:]
hi
HI
how are you
HOW ARE YOU
roo@sys5:~/Desktop$ tr [:lower:] [:upper:] <a.txt
HI ALL
GOOD MORNING
roo@sys5:~/Desktop$
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31
30
roo@sys5:~/Desktop$
2. Date command:
roo@sys5:~/Desktop$ date
Tue Nov 3 15:34:41 IST 2014
roo@sys5:~/Desktop$ date +%a
Tue
roo@sys5:~/Desktop$ date +%A
Tuesday
roo@sys5:~/Desktop$ date +%b
Nov
roo@sys5:~/Desktop$ date +%B
November
roo@sys5:~/Desktop$ date +%d
3
roo@sys5:~/Desktop$ date +%D
12/3/13
roo@sys5:~/Desktop$ date +%H
15
roo@sys5:~/Desktop$ date +%M
35
roo@sys5:~/Desktop$ date +%S
17
roo@sys5:~/Desktop$ date +%Y
2014
roo@sys5:~/Desktop$ date +%y
13
3. Who command:
Show who is logged on
roo@sys5:~/Desktop$ who
user1 pts/1 2014-12-3 14:02 (197.168.1.250)
roo@sys5:~/Desktop$
4.Who am I command:
Print the user name associated with the current effective user ID.
roo@sys5:~/Desktop$ whoami
sys5
roo@sys5:~/Desktop$
5. Finger Command:
The finger displays information about the system users.
roo@sys5:~/Desktop$ finger
Login Name Tty Idle Login Time Office Office Phone Host
Sys5 pts/1 Nov 3 14:02 (197.168.1.250)
6. Head Command:
Displays the initial part of the text file. By default, it displays the first 10 lines of a file.
roo@sys5:~/Desktop$ head -n 1 a.txt
my name is user1
roo@sys5:~/Desktop$
7. Tail command:
Displays the last part of the text file. By default, IT displays the last 10 lines of a file.
roo@sys5:~/Desktop$ tail -n 1 a.txt
i am doing computer programming lab.
roo@sys5:~/Desktop$
8. Help command:
To display the help information about a particular command.
roo@sys5:~/Desktop$ man chmod
CHMOD(1) User Commands CHMOD(1)
NAME
chmod - change file access permissions
SYNOPSIS
chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...
DESCRIPTION
This manual page documents the GNU version of chmod. chmod changes the permissions of
each given file according to mode, which can be either a symbolic representation of changes to
make, or an octal number repre- senting the bit pattern for the new permissions.
9. Clear Command:
To clear the screen.
roo@sys5:~/Desktop$ clear
10. ID command:
To display the user id and group id information about a user. i.e. user identity.
roo@sys5:~/Desktop$ id
uid=3978(sys5) gid=3979(sys5) groups=3979(sys5)
12.Changing Password:
roo@sys5:~/Desktop$ passwd
Basic calculator
roo@sys5:~/Desktop$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
45+34
79
23-13
10
Filter: Sort and grep commands are used in customizing the various commands.
Sort Filter:
It arranges the input taken from standard input in alphabetical order.
roo@sys5:~/Desktop$ sort a.txt
i am doing computer programming lab.
my name is user1
roo@sys5:~/Desktop$ sort -r a.txt
my name is user1
i am doing computer programming lab.
roo@sys5:~/Desktop$
Grep filter:
It is used to search for a particular pattern from a file or from std. input.
roo@sys5:~/Desktop$ grep name a.txt
my name is user1
roo@sys5:~/Desktop$ grep am a.txt
my name is user1
i am doing computer programming lab.
roo@sys5:~/Desktop$
roo@sys5:~/Desktop$ grep -c am a.txt
2
roo@sys5:~/Desktop$
egrep command:
It is an extension for grep command Multiple Patterns can be searched in a file by issuing a single
command. These multiple patterns should be separated by a pipe ( | ) symbol.
roo@sys5:~/Desktop$ egrep "computer|is" a.txt
my name is user1
i am doing computer programming lab.roo@sys5:~/Desktop$
Usage of pipes and filters together:
RESULT:
Inference:
Viva Questions:
1. What is unix?
2. List some names of operating systems
3. What is the use of filter/grep/pipe commands?
4. How is unix different from windows
5. Advantages of unix
6. What is the file structure of unix?
AIM:
To write a shell program to find the sum of n numbers.
ALGORITHM:
1. Get the number up to which the sum has to be calculated.
2. Initialize sum=0 and starting number i =1
3. While i less than or equal to n, do the following :
sum=sum+i
PROGRAM:
echo "SUM OF FIRST N NATURAL NUMBERS"
echo "ENTER THE LIMT N:"
read n
i=1
sum=0
while((i<=n))
do
((sum=sum+i))
((i=i+1))
done
echo "Sum: $sum"
OUTPUT:
roo@sys5:~/Desktop$ sh pgm2a.sh
SUM OF FIRST N NATURAL NUMBERS
ENTER THE LIMIT 5
SUM: 15
RESULT:
Inference:
Viva Questions:
Date:
AIM:
To write a shell program to check whether the given number is odd or even.
ALGORITHM:
1. Get the number.
2. Divide the number by 2.
3. If the remainder is equal to 0, then the number is even.
4. Else, the number is odd.
5. Stop.
PROGRAM:
echo "ODD OR EVEN"
echo "ENTER A NUMBER:"
read n
if((n%2==0))
then
echo "EVEN"
else
echo "ODD"
fi
OUTPUT:
roo@sys5:~/Desktop$ sh pgm2a.sh
ODD OR EVEN-ENTER A NUMBER:
2
EVEN
roo@sys5:~/Desktop$ sh pgm2a.sh
ODD OR EVEN
ENTER A NUMBER:15 ODD
RESULT:
Inference:
Viva Questions:
AIM:
To write a shell program to find the factorial of a number.
ALGORITHM:
1. Get the number for which factorial has to be calculated as n.
2. Initialize fact =1
3. While n less than 0, do the following :
fact=fact*n
n=n-1
PROGRAM:
echo "Enter the number"
read n
((fact=1))
while (($n > 0))
do
((fact=fact*n))
((n=n-1))
done
echo "The factorial of the number is:$fact"
OUTPUT:
Enter the number
6
The factorial of the number is:720
RESULT:
Inference:
Viva Questions:
AIM:
To write a shell program to check whether the given string is a palindrome or not.
ALGORITHM:
1. Input string
2. Calculate length of string .
3. Run a loop i=0 to len/2 of string
4. Compare ith character with len th character
5. If character doesn’t matches within loop then exit saying that it’s not a palindrome
6. If loop is successfully executed print that string is palindrome.
PROGRAM:
len=0
i=1
echo -n “Enter a String: “
read str
len=`echo $str | wc -c`
len=`expr $len – 1`
halfLen=`expr $len / 2`
while [ $i -le $halfLen ]
do
c1=`echo $str|cut -c $i`
c2=`echo $str|cut -c $len`
if [ $c1 != $c2 ] ; then
echo “string is not palindrome”
exit
fi
i=`expr $i + 1`
len=`expr $len – 1`
done
echo “String is Palindrome”
OUTPUT:
Enter a String
Madam
String is a palindrome
RESULT:
Inference:
Viva Questions:
1. What is meant by unix shell?
2. What is a shell script?
3. What are the operations performed via shell scripts?
4. What are the advantages and disadvantages of shell scripts?
AIM:
To write a ‘C’ program to implement FCFS Scheduling.
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
main()
{
int i,n,br[10],wt[10],tr[10],ttr=0,twt=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];
twt=twt+wat[i];
}
printf("\nGAANT CHART\n\n");
for(i=0;i<n;i++)
{
printf("--------");
}
printf("\n");
for(i=0;i<n;i++)
{
printf(" P%d |",i+1);
}
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("\n\nTotal waiting time :%d",twt);
printf("\nTotal turn around time :%d",ttr);
printf("\n\nAverage waiting time :%.2f",awat);
printf("\nAverage turn around time :%.2f\n",atur);
}
OUTPUT
RESULT:
Inference:
Viva Questions:
AIM:
To write a ‘C’ program to implement SJF Scheduling.
ALGORITHM:
Step 1: Include the header files for simulating SJF scheme.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
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
GAANT CHART
----------------
P2 | P1 |
----------------
0 2 5
Total waiting time :2
Total turnaround time :7
Average waiting time :1.00
Average turn around time :3.50
roo@sys5:~/Desktop$
RESULT:
Inference:
Viva Questions:
AIM:
To write a ‘C’ program to implement PRIORITY Scheduling.
ALGORITHM:
Step 1: Include the header files for simulating priority scheme.
Step 2: Declare the variables to calculate the essential aspects of priority scheme.
Step 3: Initially get the process time, arrival time and burst time along with their priorities.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
main()
{
int i,j,k,n,p[10],pri[10],bur[10],wat[10], tur[10],ttur=0,twat=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",&bur[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
printf("\nEnter the priority for process %d: ",(i+1));
scanf("%d",&pri[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(pri[i]>pri[j])
{
t=bur[i];
bur[i]=bur[j];
bur[j]=t;
t=p[i];
p[i]=p[j];
p[j]=t;
t=pri[i];
pri[i]=pri[j];
pri[j]=t;
}}}
printf("\nPROCESS\tBURST TIME \t PRIORITY \t WAITING TIME \tTURNAROUND TIME\n");
wat[0]=0;
for(i=0;i<n;i++)
{
wat[i+1]=wat[i]+bur[i];
tur[i]=wat[i]+bur[i];
}
for(i=0;i<n;i++)
{
ttur=ttur+tur[i];
twat=twat+wat[i];
}
for(i=0;i<n;i++)
{
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d\n",p[i],bur[i],pri[i],wat[i],tur[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",wat[i]);
}
awat=(float)twat/n;
atur=(float)ttur/n;
printf("\nTotal waiting time :%d\n",twat);
printf("\nTotal turnaround time :%d\n",ttur);
printf("\nAverage waiting time :%.2f\n",awat);
printf("\nAverage turn around time :%.2f\n",atur);
}
OUTPUT
roo@sys5:~/Desktop$ ./a.out
3 34 1 0 34
1 12 2 34 46
2 54 3 46 100
GAANT CHART
------------------------
P3 | P1 | P2 |
------------------------
0 34 46 100
RESULT:
Inference:
Viva Questions:
ALGORITHM:
Step 1: Include the header files for simulating ROUND ROBIN scheduling scheme.
Step 2: Declare the variables to calculate the essential aspects of ROUND ROBIN.
Step 3: Initially get the time slice along with process time and burst time.
Step 4: Start from the 1st process and execute it for the given time slice and move to 2 nd process and so on
till all process gets executed for each of the time slice allotted.
Step 5: Prepare the gantt chart for each process getting executed within the time slice in a round robin
fashion.
Step 6: Calculate the waiting time and turn around time along with their averages display the result.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
main()
{
int i,x=-1,k[10],m=0,n,t,s=0;
int a[50],temp,b[50],p[10],bur[10],bur1[10];
int wat[10],tur[10],ttur=0,twat=0,tres=0,j=0;
float awat,atur,ares;
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",&bur[i]);
bur1[i]=bur[i];
}
printf("\nEnter the slicing time :");
scanf("%d",&t);
for(i=0;i<n;i++)
{
b[i]=bur[i]/t;
if((bur[i]%t)!=0)
b[i]=b[i]+1;
m=b[i]+m;
}
printf("\nGAANT CHART\n\n");
for(i=0;i<m;i++)
{
printf("--------");
}
printf("\n");
a[0]=0;
while(j<m)
{
if(x==n-1)
x=0;
else
x++;
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
[roo@sys5:~/Desktop$ gcc rb.c
roo@sys5:~/Desktop$ ./a.out
GAANT CHART
------------------------------------------------
P1 | P2 | P3 | P1 | P2 | P3 |
------------------------------------------------
0 1 2 3 4 5 6
PROCESS BURST TIME WAITING TIME TURN AROUND TIME RESPONSE TIME
1 2 2 4 0
2 2 3 5 1
3 2 4 6 2
RESULT:
Inference:
Viva Questions:
AIM:
To write a program to implement sequential file allocation.
ALGORITHM:
Step 1: Create a disk space using array.
Step 2: Give the file length and starting block number.
Step 3: Allocate each block of the file sequentially in disk.
Step 4: The disk space is checked to ensure the block is allocated or not.
PROGRAM
#include<stdio.h>
main()
{
int f[50],i,st,j,len,c,k;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("\n Enter the starting block & length of file");
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("Block already allocated");
break;
}
if(j==(st+len))
printf("\n the file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)");
scanf("%d",&c);
if(c==1)
goto X;
return 0;
}
OUTPUT:
4->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
13->1
RESULT:
Inference:
Viva Questions:
AIM:
To write a program to implement indexed file allocation.
ALGORITHM:
Step 1: Enter the number of files along with their file names.
Step 2: Give the file size and block size for each file.
Step 3: Enter the block numbers for each block in file.
Step 4: Display the indexed file allocation of each file.
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
int n;
void main()
{
int b[20],b1[20],i,j,blocks[20][20],sz[20];
char F[20][20],S[20],ch;
clrscr();
printf("\n Enter no. of Files ::");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter file %d name ::",i+1);
scanf("%s",F[i]);
printf("\n Enter file%d size(in kb)::",i+1);
scanf("%d",&sz[i]);
printf("\n Enter blocksize of File%d(in bytes)::",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
b1[i]=(sz[i]*1024)/b[i];
printf("\n\nEnter blocks for file%d",i+1);
for(j=0;j<b1[i];j++)
{
printf("\n Enter the %dblock ::",j+1);
scanf("%d",&blocks[i][j]);
}
}
do
{
OUTPUT
roo@sys5:~/Desktop$ gcc ifa.c
roo@sys5:~/Desktop$ ./a.out
Enter no. of Files ::2
Enter file 1 name ::fileA
Enter file1 size(in kb)::1
Enter blocksize of File1(in bytes)::543
Enter file 2 name ::fileB
Enter file2 size(in kb)::1
Enter blocksize of File2(in bytes)::489
Enter blocks for file1
Enter the 1block ::1024
Enter blocks for file2
Enter the 1block ::1500
Enter the 2block ::966
Enter the Filename ::fileA
Fname Fsize Bsize Nblocks Blocks
----------------------------------------------------------
fileA 1 543 1 1024->
-----------------------------------------------------------
Do U want to continue ::(Y-1:n-0)
RESULT:
Inference:
Viva Questions:
AIM:
To write a program to implement linked file allocation.
ALGORITHM:
Step 1: Enter the number of files along with their file names.
Step 2: Give the file size and block size for each file.
Step 3: Enter the block numbers for each block in file.
Step 4: Display the linked file allocation of each file using their block delimiters.
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
int n;
void main()
{
int b[20],b1[20],i,j,blocks[20][20],sz[20];
char F[20][20],S[20],ch;
int sb[20],eb[20],x;
clrscr();
printf("\n Enter no. of Files ::");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter file %d name ::",i+1);
scanf("%s",&F[i]);
printf("\n Enter file%d size(in kb)::",i+1);
scanf("%d",&sz[i]);
printf("\n Enter blocksize of File%d(in bytes)::",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
b1[i]=(sz[i]*1024)/b[i];
printf("\n Enter Starting block of file%d::",i+1);
scanf("%d",&sb[i]);
printf("\n Enter Ending block of file%d::",i+1);
scanf("%d",&eb[i]);
printf("\nEnter blocks for file%d::\n",i+1);
for(j=0;j<b1[i]-2;)
{
printf("\n Enter the %dblock ::",j+1);
scanf("%d",&x);
if(x>sb[i]&&x<eb[i])
{
blocks[i][j]=x;
j++;
}
else
printf("\n Invalid block::");
}
}
do
{
printf("\nEnter the Filename ::");
scanf("%s",&S);
for(i=0;i<n;i++)
{
if(strcmp(F[i],S)==0)
{
printf("\nFname\tFsize\tBsize\tNblocks\tBlocks\n");
printf("\n---------------------------------------------\n");
printf("\n%s\t%d\t%d\t%d\t",F[i],sz[i],b[i],b1[i]);
printf("%d->",sb[i]);
for(j=0;j<b1[i]-2;j++)
printf("%d->",blocks[i][j]);
printf("%d->",eb[i]);
}
}
printf("\n---------------------------------------------\n");
printf("\nDo U want to continue (Y:n)::");
scanf("%d",&ch);
}while(ch!=0);
}
OUTPUT
roo@sys5:~/Desktop$ gcc lfa.c
roo@sys5:~/Desktop$ ./a.out
Enter no. of Files ::2
Enter file 1 name ::aa
Enter file1 size(in kb)::1
Enter blocksize of File1(in bytes)::512
Enter file 2 name ::bb
Enter file2 size(in kb)::1
Enter blocksize of File2(in bytes)::1024
Enter Starting block of file1::1100
Enter Ending block of file1::1600
Enter blocks for file1::
Enter Starting block of file2::102
Enter Ending block of file2::104
Enter blocks for file2::
Enter the Filename ::aa
Fname Fsize Bsize Nblocks Blocks
-------------------------------------------------------------------
aa 1 512 2 1100->1600->
-------------------------------------------------------------------
Do U want to continue (Y:n)::y
Enter the Filename ::bb
RESULT:
Inference:
Viva Questions:
Date:
AIM:
To write a program to implement producer consumer problem using semaphore
ALGORITHM:
Step 1: Declare the buffer size variable.
Step 2: Initialize empty, full and the value of mutex.
Step 3: For case 1 , produce the item till the buffer is full after performing the wait operation
of variables empty and mutex.
Step 4: Then perform signal of full.
Step 5: For case 2, consume the item till the buffer is empty. Perform the wait and signal operation..
Step 6: print the contents of the buffer.
PROGRAM:
#include<stdio.h>
#include<string.h>
#define SIZE 3
struct process
{
char a[10];
}buffer[SIZE];
int mutex=1,full=0,empty=SIZE,f=0;
int main()
{
//int mutex=1,full=0,empty=SIZE,f=0;
int ch,i;
printf("\tProdecer Consumer Problem:\n");
while(1)
{
printf("\n The choices are\n");
printf("1.Producer Routine\n2.Consumer Routine\n3.Buffer Contents\n4.Exit\n");
printf("Enter your Coice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
empty=wait(empty);
mutex=wait(mutex);
if(f==0)
{
printf("\nEnter the item to be added:\n");
scanf("%s",&buffer[full]);
full=signal(full);
printf("\nItem Produced Successfully:\n");
}
else
{
printf("\nBuffer is full\n");
f=0;
}
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
roo@sys5:~/Desktop$ gcc pro.c
roo@sys5:~/Desktop$ ./a.out
Enter Stack Size : 3
Producer Stack (Stack Size : 3 )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
Stack is EMPTY
(Now It is sleeping)
-------------------------------------------------------------------------------
Consumer Stack (Stack Size : 3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
Stack is EMPTY
(Now It is sleeping)
-------------------------------------------------------------------------------
CHOICES
~~~~~~~
1.Producer
2.Consumer
3.Exit
Enter your choice : 1
Enter PRODUCE item is :20
Producer Stack (Stack Size : 3 )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
20
-------------------------------------------------------------------------------
Consumer Stack (Stack Size : 3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
Stack is EMPTY
(Now It is sleeping)
-------------------------------------------------------------------------------
CHOICES
~~~~~~~
1.Producer
2.Consumer
3.Exit
Enter your choice : 1
Enter PRODUCE item is :30
Producer Stack (Stack Size : 3 )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
20 30
-------------------------------------------------------------------------------
Consumer Stack (Stack Size : 3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
Stack is EMPTY
(Now It is sleeping)
-------------------------------------------------------------------------------
CHOICES
~~~~~~~
1.Producer
2.Consumer
3.Exit
Enter your choice : 2
CONSUME one item Producer Stack (Stack Size : 3 )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
20
-------------------------------------------------------------------------------
Consumer Stack (Stack Size : 3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
30
-------------------------------------------------------------------------------
CHOICES
~~~~~~~
1.Producer
2.Consumer
3.Exit
Enter your choice : 2
CONSUME one item Producer Stack (Stack Size : 3 )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
Stack is EMPTY
(Now It is sleeping)
-------------------------------------------------------------------------------
Consumer Stack (Stack Size : 3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
30 20
-------------------------------------------------------------------------------
CHOICES
~~~~~~~
1.Producer
2.Consumer
3.Exit
Enter your choice : 2
Producer stack is EMPTY
Producer Stack (Stack Size : 3 )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
Stack is EMPTY
(Now It is sleeping)
-------------------------------------------------------------------------------
RESULT:
Inference:
Viva Questions:
1. What is semaphore?
2. Define synchronization. What is the purpose of synchronization?
3. What are the types of semaphores?
4. What are the operations on the semaphore?
5. Define busy waiting, spin lock.
6. Explain producer consumer problem.
ALGORITHM:
Step 1: Read the number of directories to be created.
Step 2: Input the number of files for each directory.
Step 3: Give the file names for the files.
Step 4: Display the single level directory containing files in each.
PROGRAM:
#include<stdio.h>
main()
{
int master,s[20];
char f[20][20][20];
char d[20][20];
int i,j;
printf("enter number of directorios:");
scanf("%d",&master);
printf("enter names of directories:");
for(i=0;i<master;i++)
scanf("%s",d[i]);
printf("enter size of directories:");
for(i=0;i<master;i++)
scanf("%d",&s[i]);
printf("enter the file names :");
for(i=0;i<master;i++)
for(j=0;j<s[i];j++)
scanf("%s",f[i][j]);
printf("\n");
printf(" directory\tsize\tfilenames\n");
printf("*************************************************\n");
for(i=0;i<master;i++)
{
printf("%s\t\t%2d\t",d[i],s[i]);
for(j=0;j<s[i];j++)
printf("%s\n\t\t\t",f[i][j]);
printf("\n");
}
printf("\t\n");
}
OUTPUT
roo@sys5:~/Desktop$ gcc sld.c
roo@sys5:~/Desktop$ ./a.out
Enter the number of directories: 2
Enter names of directories: Dir1 Dir2
RESULT:
Inference:
Viva Questions:
AIM:
To write a program to implement two level directory structure.
ALGORITHM:
Step 1: Read the number of directories to be created.
Step 2: Input the number of subdirectories and names of the subdirectories for each directory.
Step 3: Give the file names for the files under the subdirectories.
Step 4: Display the two level structure for each directory created.
PROGRAM:
#include<stdio.h>
#include<conio.h>
struct st
{
char dname[10];
char sdname[10][10];
char fname[10][10][10];
int ds,sds[10];
}dir[10];
void main()
{
int i,j,k,n;
clrscr();
printf("enter number of directories:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter directory %d names:",i+1);
scanf("%s",&dir[i].dname);
printf("enter size of directories:");
scanf("%d",&dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("enter subdirectory name and size:");
scanf("%s",&dir[i].sdname[j]);
scanf("%d",&dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
{
printf("enter file name:");
scanf("%s",&dir[i].fname[j][k]);
}
}
}
printf("\ndirname\t\tsize\tsubdirname\tsize\tfiles");
printf("\n******************************************************\n");
for(i=0;i<n;i++)
{
printf("%s\t\t%d",dir[i].dname,dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("\t%s\t\t%d\t",dir[i].sdname[j],dir[i].sds[j]);
for(k=0;k<dir[i].sds[j];k++)
printf("%s\t",dir[i].fname[j][k]);
printf("\n\t\t");
}
printf("\n");
}
getch();
}
OUTPUT:
Inference:
Viva Questions:
ALGORITHM:
Step 1: Read the Directory for which the hierarchy structure to be displayed.
Step 2: Write commands to access through the subdirectories and files in the given directory.
Step 4: If file found print them as next sub level of the sub directory
PROGRAM:
#define _XOPEN_SOURCE 500
#include<ftw.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<limits.h>
#define TRUE 1
#define FALSE 0
#define MAXDEPTH 20
static int display_info(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
{
char blanks[PATH_MAX];
const char *filename=fpath+ftwbuf->base;
int width = 4*ftwbuf->level;
memset(blanks ,' ', width);
blanks[width] = '\0';
printf("%s%s",blanks,filename);
if(tflag==FTW_DNR)
printf("(unreadabledirectory)");
else if(tflag==FTW_SL)
printf("(symboliclink)");
else if(tflag==FTW_SLN)
printf("(brokensymboliclink)");
else if(tflag==FTW_NS)
printf("statfailed");
printf("\n");
return 0;
}
int main(int argc,char *argv[])
{
int flags=0;
int status;
int ch;
char options[]=":cdpm";
opterr=0;
while(TRUE)
{
ch=getopt(argc,argv,options);
///*itreturns−1whenitfindsnomoreoptions */
if(-1 == ch)
break;
switch(ch)
{
case 'c':
flags|=FTW_CHDIR;
break;
case 'd':
flags|=FTW_DEPTH;
break;
case 'p':
flags|=FTW_PHYS;
break;
case 'm':
flags|=FTW_MOUNT;
break;
default:
fprintf(stderr,"Badoptionfound.\n");
return 1;
}
}
if(optind<argc)
{
while(optind<argc)
{
status=nftw(argv[optind],display_info,MAXDEPTH,flags);
if(-1 == status)
{
perror("nftw");
exit(EXIT_FAILURE);
}
else
optind++;
}}
else
{
status=nftw(".",display_info,MAXDEPTH,flags);
if(-1==status)
{
perror("nftw");
exit(EXIT_FAILURE);
}}
exit(EXIT_SUCCESS);
}
OUTPUT:
roo@sys5:~/Desktop$ ./a.out Desktop
Desktop
a
a.txt
b
c
c.txt
b.txt
netbeans-8.0.1.desktop
lab thread and Sync
syncthread.c
h1.c~
h1.c
syncmutexthread.c
advanced-linux-programming.pdf
os lab.odt
h3.c
hierarchicalfile.c~
h3.c~
hierarchicalfile.c
os lab.doc
OS Manual.doc
.~lock.OS Manual.doc#
RESULT:
Inference:
Viva Questions:
ALGORITHM:
Step 1: Start with the implementation of directed acyclic .
Step 4: Use edges to link the sub directories and files which are again vertices of the graph.
PROGRAM:
#include<stdio.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()
{
root=NULL;
read_links();
}
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:");
fflush(stdin);
gets(L[i].to);
}
}
search(node *root,char *s,int *x,int *y)
{
int i;
if(root!=NULL)
{
if(strcmpi(root->name,s)==0)
{
*x=root->x;
*y=root->y;
return;
}
else
{
for(i=0;i<root->nc;i++)
search(root->link[i],s,x,y);
}
}
}
create(node **root,int lev,char *dname,int lx,int rx,int x)
{
int i,gap;
if(*root==NULL)
{
(*root)=(node *)malloc(sizeof(node));
printf("enter name of dir/file(under %s):",dname); fflush(stdin);
gets((*root)->name);
printf("enter 1 for dir/ 2 for file:");
scanf("%d",&(*root)->ftype); (*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
{
printf("no of sub directories /files (for %s):",(*root)->name);
scanf("%d",&(*root)->nc);
if((*root)->nc==0)
gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)->link[i] ),lev+1 ,(*root)->name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
}
else (*root)->nc=0;
}
}
OUTPUT:
roo@sys5:~/Desktop$ dag.c
roo@sys5:~/Desktop$ ./a.out
Enter Name of dir/file (under root): ROOT
Enter 1 for Dir / 2 For File : 1
No of subdirectories / files (for ROOT) :2
Enter Name of dir/file (under ROOT): USER 1
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for USER 1): 2
Enter Name of dir/file (under USER1): VB
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for VB): 2
Enter Name of dir/file (under VB): A
Enter 1 for Dir /2 for file:2
RESULT:
Inference:
Viva Questions:
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.
3. work=work+Allocation, Finish[i] =True;
4. if Finish[1]=True for all I, then the system is in safe state.
ALGORITHM:
PROGRAM:
#include<stdio.h>
void main()
{
int i, work[5],avl[5],alloc[10][10],l;
int need[10][10],n,m,I,j,avail[10],max[10][10],k,count,fcount=0,pr[10];
char finish[10]={'f','f','f','f','f','f','f','f','f','f'};
printf("enter the no of process");
scanf("%d",&n);
printf("enter the no of resources");
scanf("%d",&m);
printf("enter the total no of resources");
for(i=1;i<=m;i++)
scanf("%d",&avail[i]);
printf("enter the max resources req by each pr alloc matrix");
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",&max[i][j]);
printf("process allocation matrix");
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",&alloc[i][j]);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
need[i][j]=max[i][j]-alloc[i][j];
for(i=1;i<=n;i++)
{
k=0;
for(j=1;j<=m;j++)
{
k=k+alloc[i][j];
}
avl[i]=avl[i]-k;
work[i]=avl[i];
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
{
count=0;
for(j=1;j<=m;j++)
{
if((finish[i]=='f')&&(need[i][j]<=work[i]))
count++;
}
if(count==m)
{
for(l=1;l<=m;l++)
work[l]=work[l]+alloc[i][l];
finish[i]='t';
pr[k]=i;
break;
}
}
for(i=1;i<=n;i++)
if(finish[i]=='t')
fcount++;
if(fcount==n)
{
printf("the system is in safe state");
for(i=1;i<=n;i++)
printf("%d",pr[i]);
}
else
printf("the system is not in safe state");
}
OUTPUT
roo@sys5:~/Desktop$ bankers.c
roo@sys5:~/Desktop$ ./a.out
Enter the number of process: 5
Enter the number of resources: 3
Enter the total number of resourced: 10 5 7
Enter the max resources required by each pr alloc matrix
753
322
902
222
433
Process allocation matrix
010
200
302
211
002
The system is in safe state 1 2 3 4 5
RESULT:
Inference:
Viva Questions:
AIM:
To write a program to implement Deadlock detection algorithm.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the values of resources and processes.
Step 3: Get the allocation and request matrix value.
Step 4: Get the available instances for each resources
Step 5: Check whether its possible to allocate using below condition.
Step 6: If Need<=Work update work as work=work +allocation
Step 7: Else proceed with next process.
Step 8: If it is possible to allocate then the system is in safe state.
Step 9: Else system is not in safe state.
PROGRAM:
#include <stdio.h>;
#include <conio.h>;
void main()
{
int found,flag,l,p[4][5],tp,tr,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;
clrscr();
printf("Enter total no of processes");
scanf("%d",&tp);
printf("Enter total no of resources");
scanf("%d",&tr);
printf("Enter claim (Max. Need) matrix\n");
for(i=1;i<=tp;i++)
{
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&c[i][j]);
}
printf("Enter allocation matrix\n");
for(i=1;i<=tp;i++)
{
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);
}
printf("Enter resource vector (Total resources):\n");
for(i=1;i<=tr;i++)
{
scanf("%d",&r[i]);
}
printf("Enter availability vector (available resources):\n");
for(i=1;i<=tr;i++)
{
scanf("%d",&a[i]);
temp[i]=a[i];
}
for(i=1;i<=tp;i++)
{
sum=0;
for(j=1;j<=tr;j++)
{
sum+=p[i][j];
}
if(sum==0)
{
m[k]=i;
k++;
}
}
for(i=1;i<=tp;i++)
{
for(l=1;l<k;l++)
if(i!=m[l])
{
flag=1;
for(j=1;j<=tr;j++)
if(c[i][j]<temp[j])
{
flag=0;
break;
}
}
if(flag==1)
{
m[k]=i;
k++;
for(j=1;j<=tr;j++)
temp[j]+=p[i][j];
}
}
printf("deadlock causing processes are:");
for(j=1;j<=tp;j++)
{
found=0;
for(i=1;i<k;i++)
{
if(j==m[i])
found=1;
}
if(found==0)
printf("%d\t",j);
}
getch();
}
OUTPUT
roo@sys5:~/Desktop$ dead.c
roo@sys5:~/Desktop$ ./a.out
Enter total no. of processes : 4
Enter total no. of resources : 5
Enter claim (Max. Need) matrix :
01001
00101
00001
10101
Enter allocation matrix :
10110
11000
00010
00000
Enter resource vector (Total resources) :
21121
Enter availability vector (available resources) :
00001
deadlock causing processes are : 2 3
RESULT:
Inference:
Viva Questions:
AIM:
To implement First in First Out page replacement technique.
ALGORITHM:
Step 1: Start the process
Step 2: Declare the size with respect to page length
Step 3: Check the need of replacement from the page to memory
Step 4: Check the need of replacement from old page to new page in memory
Step 5: Forma queue to hold all pages
Step 6: Insert the page require memory into the queue
Step 7: Check for bad replacement and page fault
Step 8: Get the number of processes to be inserted
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:
roo@sys5:~/Desktop$ fifo.c
roo@sys5:~/Desktop$ ./a.out
ENTER THE NUMBER OF PAGES: 20
ENTER THE PAGE NUMBER : 70120304230321201701
ENTER THE NUMBER OF FRAMES :3
ref string page frames
7 7 -1 -1
0 7 0 -1
1 7 0 1
2 2 0 1
0
3 2 3 1
0 2 3 0
4 4 3 0
2 4 2 0
3 4 2 3
0 0 2 3
3
2
1 0 1 3
2 0 1 2
0
1
7 7 1 2
0 7 0 2
1 7 0 1
Page Fault Is 15
RESULT:
Inference:
Viva Questions:
AIM:
To implement Least Recently Used page replacement technique.
ALGORITHM:
Step 1: Start the process
Step 2: Declare the size
Step 3: Get the number of pages to be inserted
Step 4: Get the value
Step 5: Declare counter and stack
Step 6: Select the least recently used page by counter value
Step 7: Stack them according the selection.
Step 8: Display the values
Step 9: Stop the process
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);
}
OUTPUT:
roo@sys5:~/Desktop$ lru.c
roo@sys5:~/Desktop$ ./a.out
Enter no of pages:10
Enter the reference string:7 5 9 4 3 7 9 6 2 1
Enter no of frames:3
7
7 5
7 5 9
4 5 9
4 3 9
4 3 7
9 3 7
9 6 7
9 6 2
1 6 2
RESULT:
Inference:
Viva Questions:
AIM:
To implement Least Frequently Used page replacement technique.
ALGORITHM:
Step 1: Start the process
Step 2: Declare the size
Step 3: Get the number of pages to be inserted
Step 4: Get the value
Step 5: Declare counter and stack
Step 6: Select the least frequently used page by counter value
Step 7: Stack them according the selection.
Step 8: Display the values
Step 9: Stop the process
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]);
}
printf("\n");
for(i=0;i<p;i++)
{
count[pages[i]]++;
time[pages[i]]=i;
flag=1;
least=frame[0];
for(j=0;j<f;j++)
{
if(frame[j]==-1 || frame[j]==pages[i])
{
if(frame[j]!=-1)
{
hit++;
}
flag=0;
frame[j]=pages[i];
break;
}
if(count[least]>count[frame[j]])
{
least=frame[j];
}
}
if(flag)
{
minTime=50;
for(j=0;j<f;j++)
{
if(count[frame[j]]==count[least] && time[frame[j]]<minTime)
{
temp=j;
minTime=time[frame[j]];
}
}
count[frame[temp]]=0;
frame[temp]=pages[i];
}
for(j=0;j<f;j++)
{
printf("%d ",frame[j]);
}
printf("\n");
}
printf("Page hit = %d",hit);
return 0;
}
OUTPUT
roo@sys5:~/Desktop$ lru.c
roo@sys5:~/Desktop$ ./a.out
Enter no of frames: 3
Enter no of pages:10
Enter page no:
2
3
4
2
1
3
7
5
4
3
2 -1 -1
2 3 -1
2 3 4
2 3 4
2 1 4
2 1 3
2 7 3
2 7 5
2 4 5
2 4 3
Page hit=1
RESULT:
Inference:
Viva Questions:
AIM:
To write a program to implement inter process communication and shared memory.
ALGORITHM:
Step 1: Create and shared memory using shmget.
PROGRAM
#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;
OUTPUT
roo@sys5:~/Desktop$ ipc.c
roo@sys5:~/Desktop$ ./a.out
------ Shared Memory Segments --------
roo@sys5:~/Desktop$
RESULT:
Inference:
Viva Questions:
1. What is IPC?
2. What the methods to implement IPC?
3. What is shared memory?
4. What is message passing?
5. What is RPC?
AIM:
To implement the Memory management using Paging technique.
ALGORITHM:
Step 1: Read all the necessary input from the keyboard.
Step 2: Pages - Logical memory is broken into fixed - sized blocks.
Step 3: Frames – Physical memory is broken into fixed – sized blocks.
Step 4: Calculate the physical address using the following
Physical address = ( Frame number * Frame size ) + offset
Step 5: Display the physical address.
Step 6: Stop the process.
PROGRAM
#include<stdio.h>
#define MAX 50
int main()
{
int page[MAX],i,n,f,ps,off,pno;
clrscr();
printf("\nEnter the no of pages in memory");
scanf("%d",&n);
printf("\nEnter page size");
scanf("%d",&ps);
printf("\nEnter no of frames");
scanf("%d",&f);
for(i=0;i<n;i++)
page[i]=-1;
printf("\nEnter the page table\n");
printf("(Enter frame no as -1 if that page is not present in any frame)\n\n");
printf("\npageno\tframeno\n-------\t-------");
for(i=0;i<n;i++)
{
printf("\n\n%d\t\t",i);
scanf("%d",&page[i]);
}
printf("\n\nEnter the logical address(i.e,page no & offset):");
scanf("%d%d",&pno,&off);
if(page[pno]==-1)
printf("\n\nThe required page is not available in any of frames");
else
printf("\n\nPhysical address(i.e,frame no & offset):%d,%d",page[pno],off);
getch();
return 1;
}
OUTPUT:
roo@sys5:~/Desktop$ pgmm.c
roo@sys5:~/Desktop$ ./a.out
Enter page size 3
Enter no of frames 4
Enter the page table
(Enter frame no as -1 if that page is not present in any frame)
page no frame no
---------- ------------
0 1
1 2
2 3
Enter the logical address(i.e,page no & offset): 2 30
Physical address(i.e,frame no & offset):3, 30
RESULT:
Inference:
Viva Questions:
AIM:
ALGORITHM:
PROGRAM
//Threading Application Program
#include <pthread.h>
#include <stdio.h>
/* increment x to 100 */
return NULL;
int main()
int x = 0, y = 0;
pthread_t inc_x_thread;
return 1;
if(pthread_join(inc_x_thread, NULL)) {
return 2;
return 0;
OUTPUT
y increment finished
x increment finished
x: 100, y: 100
roo@sys5:~/Desktop$
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
int counter;
pthread_mutex_t lock;
pthread_mutex_lock(&lock);
unsigned long i = 0;
counter += 1;
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)
return 1;
while(i < 2)
if (err != 0)
i++;
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy(&lock);
return 0;
OUTPUT
roo@sys5:~/Desktop$ ./a.out
Job 1 started
Job 1 finished
Job 2 started
Job 2 finished
roo@sys5:~/Desktop$
RESULT:
Inference:
Viva Questions:
1. Define threads?
2. List the types of threads
3. What is multithreading?
4. What is posix thread?
5. Define synchronization.
6. How threads can be used for synchronization.
Cache memory is random access memory (RAM) that a computer microprocessor can access
more quickly than it can access regular RAM. As the microprocessor processes data, it looks 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.
23. 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.
24. 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.
25. What is MUTEX ?
Mutex is the short form for ‘Mutual Exclusion object’. A mutex allows multiple threads for
sharing the same resource. The resource can be file. A mutex with a unique name is created at the
time of starting a program. A mutex must be locked from other threads, when any thread that
needs the resource. When the data is no longer used / needed, the mutex is set to unlock.
26. What is the difference between a ‘thread’ and a ‘process’?
1.Threads share the address space of the process that created it; processes have their own
address.
2.Threads have direct access to the data segment of its process; processes have their own copy of
the data segment of the parent process.
3.Threads can directly communicate with other threads of its process; processes must use
interprocess communication to communicate with sibling processes.
4.Threads have almost no overhead; processes have considerable overhead.
5.New threads are easily created; new processes require duplication of the parent process
. 6.Threads can exercise considerable control over threads of the same process; processes can
only exercise control over child processes
. 7.Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the
other threads of the process; changes to the parent process does not affect child processes.
27. What is INODE?
Inode is a unique number given to a file in Unix OS. Every file in Unix has a inode number. unix
treats directories/folders as a file so they are also having a inode value.
28. Explain the working of Virtual Memory.
Virtual memory is memory that appears to be allocated to application programs. The operating
system uses a portion of the hard disk as virtual memory, and swaps data between the hard disk
and physical memory. Virtual memory enables multitasking. If your computer needs to run
several programs simultaneously, and the memory that all these programs require exceeds the
amount of physical memory available, the operating system allocates virtual memory to meet the
total memory requirements of each program, and then manages the available physical memory to
meet the actual memory requirements at each point in time
29. How does Windows NT supports Multitasking?
Windows NT support multitasking by using extra memory and it also support multitasking by
using the network. It is especially designed for that cause.
in Microsoft Windows
30. Explain the Unix Kernel?
The kenel is a control core of UNIX. It is the part of operating system that interacts directly with
the hardware of the computer system , throuth device driver that are built into the kernel.
31. What is Concurrency?
Cuncurrency is allowing simultaneous access of same data by different users. Locks useful for
accesing the database are a) Exclusive - The exclusive lock is useful for locking the row when an
insert,update or delete is being done.This lock should not be applied when we do only select from
the row. b) Share lock - We can do the table as Share_Lock as many share_locks can be put on the
same resource.
32. Explain Memory Partitioning, Paging, Segmentation
PAGING: Paging memory allocation algorithms divide computer memory into smallpartitions and
allocates memory using a page as the smallest building block.
SEGMENTAION: Segmentation means that a part or parts of the memory will be sealed off from
the currently running process through the use of hardware registers. If the data that is about to be
read or written to is outside the permitted address space of that process a segmentation fault will
result.
Memory Partitioning- means partitioning the memory into small units or blocks & load the data
or code into the blocks & use this data & code when required by a process.
33. Explain Scheduling.
The way by which the processes are allocated to CPU to use the CPU time is called scheduling.
34. Operating System Security
Flaws in the operating systems of computers are discovered almost daily. The majority of viruses
take advantage of these flaws to infect your computer. To avoid contracting a virus, you should
take the following basic precautions:
Software Updates , Firewall, Account Management ,Antivirus Software
35. What is Semaphore?
semaphores are a technique for coordinating or synchronizing activities in which multiple
processes compete for the same operating system resources. A semaphore is a value in a
designated place in operating system (or kernel) storage that each process can check and then
change.
36. Explain the following file systems : NTFS, FAT
NTFS--NTFS is a high-performance and self-healing file system proprietary to Windows XP
2000 NT, which supports file-level security, compression and auditing. It also supports large
volumes and powerful storage solution such as RAID.
The File Allocation Table (FAT) file system is a simple file system originally designed for small
disks and simple folder structures.
37. What are the different process states?
These are the states of a process. The corresponding symbols will come in STAT column of the
output of the
Process command R- running S-sleeping I-Idle Z-Zombie W-swapped out
K-Available kernel Process N- Niced(Execution priority lowered) >Execution priority artificially
raised X-GROWING ,WAITING FOR MEMORY T-Stopped D-Disk wait P-Page wait
38. What is Marshalling?
Marshalling is a process that is used to communicate to remote objects with an object(serialized
object - serialization). It simplifies complex communication, using custom/complex objects to
communicate - instead of primitives.
39. Define and explain COM?
COM (Component Object Model) technology in the Microsoft Windows-family of Operating Systems
enables software components to communicate. COM is used by developers to create re-usable software
components, link components together to build applications, and take advantage of Windows services.
40. Difference - Loading and Linking
loading refers to storing large amt of data into the system.linking means one program or page is
related to another page or program.
41. What are different functions of Syntax phase, Sheduler?
Syntax phase sheduler deals with the problem of deciding which of the process in ready queue is to
allocate the CPU time for processing.
42. What are different tasks of Lexical analysis
The purpose of the lexical analyzer is to partition the input text, delivering a sequence of
comments and basic symbols. Comments are character sequences to be ignored, while basic
symbols are character sequences that correspond to terminal symbols of the grammar defining the
phrase structure of the input
43. What are main difference : Micro-Controller and Micro- Processor?
microprocessor:
1 general purpose digital computer
2 many operational codes for moving data from external memory to cpu
3 rapid movement of code and data from external address to chip
microcontroller
1 specific purpose digital computer
2 one or two codes for moving data from external memory to cpu
3 rapid movements of bits within the chip
44. What do you mean by deadlock?
Deadlock is a situation where the resources are not allocated to the process because they are already
used by another process..ie../suppose P1 requests resources of P2 which is already used by P3 and so on.
this is not the only case for occurrence of deadlock. for a dead lock to occur there are 3 necessary
conditions 1)Mutual Exclusion 2)Non-Preemption 3)Hold and wait
45. What is DRAM? In which form does it store data?
DRAM is the Hershey's chocolate of readable/writable memory: it's not the best, but it's cheap, does the
job, and is available almost everywhere you look. DRAM data resides in a cell made of a capacitor and a
transistor. The capacitor tends to lose data unless it's recharged every couple of milliseconds, and this
recharging tends to slow down the performance of DRAM compared to speedier RAM types.
46. What is a mission critical system ?
Besides its life/death or make/break ingredients of operational procedures or processes, that is what the
most mission critical systems have themselves labeled, a mission critical system is the system that has to
accomplish certain critical tasks within a predefined duration of time and/or a
predefined frame of benchmarks. The time constraint and the benchmarks are the integral part of the
mission. Without the meeting such those constraints, the consequence of failure often thoroughly defeats
the purpose of the entire system
47. What is cache memory?
Cache (pronounced cash) memory is extremely fast memory that is built into a computer’s central
processing unit (CPU), or located next to it on a separate chip. The CPU uses cache memory to store
instructions that are repeatedly required to run programs, improving overall system speed. The advantage
of cache memory is that the CPU does not have to use the motherboard’s system bus for data transfer.
Whenever data must be passed through the system bus, the data transfer speed slows to the motherboard’s
capability. The CPU can process data much faster by avoiding the bottleneck created by the system bus.
48. What is hard disk and what is its purpose?
Hard disk is the secondary storage device, which holds the data in bulk, and it holds the data on the
magnetic medium of the disk.Hard disks have a hard platter that holds the magnetic medium, the
magnetic medium can be easily erased and rewritten, and a typical desktop machine will have a hard disk
with a capacity of between 10 and 40 gigabytes. Data is stored onto the disk in the form of files.
49. Why paging is used ?
Paging is solution to external fragmentation problem which is to permit the logical address space of a
process to be noncontiguous, thus allowing a process to be allocating physical memory wherever the
latter is available.
50. Which is best page replacement algorithm and Why?
Optimal page replacement algorithm. Bcoz it overcomes the belady's anomaly; number of page fault is
low.
51. Multiprocessor Systems are also called as parallel systems or tightly coupled systems.
52. Mainframe Systems are the first computers used to tackle many commercial and scientific
applications.
53. Clustered systems gather together multiple CPU s to accomplish computational work.
54. List out the types of Client- server systems.
Compute-server
File-server systems.
55. Loosely coupled system is otherwise called as distributed system.
56. In the message passing model, information is exchanged through an interprocess – communication
facility
57. Give the details about hardware protection.
Dual-Mode operation
I/O Protection
Memory Protection
CPU Protection
58. System calls provides the interface between a process and the operating system.
59. A uniprocessor system can have only one running process.
60. PCB is process control block.
61. What are the benefits of multithreaded programming?
Responsiveness
Resource sharing
Economy
Utilization of multiprocessor architectures.
62. Thread pool is to create a number of threads at process startup and place them into a pool, where
they sit and wait for work.
63. What are the Scheduling Criteria?
1. CPU utilization
2. Throughput
3. Turnaround time
4. Waiting time
5. Response time
64. Starvation is also called as indefinite blocking.
65. List the advantages of thread?
1. Thread minimizes context switching time.
2. Use of threads provides concurrency within a process.
3. Efficient communication.
4. Utilization of multiprocessor architecture.
66. Define spin lock.
Busy waiting wastes CPU cycles that some other process might be able to use
productively.
67. The round robin scheduling algorithm is designed especially for time sharing systems.
68. In Priority Scheduling Equal priority processes are scheduled in FCFS order.
69. An address generated by the CPU is referred as logical address.
70. Physical memory is broken into fixed size blocks called frames.
71. Logical address is also broken into blocks of same size called pages.
72. Page table contains the base address of each page in physical memory.
73. An inverted page table has one entry for each real page of memory.
74. A lazy swapper never swaps a page into memory unless that page will be needed.
75. Virtual memory is a technique that allows the execution of processes that may not be completely in
memory.
76. Virtual memory is commonly implemented by demand paging.
77. What are the various page replacement algorithms used for page replacement?
o FIFO page replacement
o Optimal page replacement
o LRU page replacement
o LRU approximation page replacement
78. The string of memory reference is called a reference string.
79. What are the various file operations?
Creating a file
Writing a file
Reading a file
Repositioning within a file
Deleting a file
Truncating a file
80. ISAM is Indexed Sequential Access Method
81. VFS is virtual file system.
82. The time taken by the head to move to the appropriate cylinder or track is called seek time.
83. Rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk
head.
84. A cache is a region of fast memory that holds copies of data.
85. What is sector sparing?
Low-level formatting also sets aside spare sectors not visible to the operating system. The
controller can be told to replace each bad sector logically with one of the spare sectors. This
scheme is known as sector sparing or forwarding.
86. FCB is File Control Block.
87. The mount protocol establishes the initial logical connection between a server and a client.
88. Define Path-Name Translation.
It is done by breaking the path into component names and performing a separate NFS lookup
call for every pair of component name and directory vnode.
89. Nonmaskable interrupt is reserved for events such as unrecoverable memory errors.
90. Define Partition Control Block.
It contains partition details, such as the number of blocks in the partition, size of the blocks,
free-block count and free-block pointers, and free FCB count and FCB pointers.
91. A spool is a buffer that holds output for a device, such as printer, that cannot accept interleaved data
streams.
92. What are the advantages of Indexed allocation?
No external-fragmentation problem
Solves the size-declaration problems.
Supports direct access
93. What are the various layers of a file system?
o Application programs
o Logical file system
o File-organization module
o Basic file system
o I/O control
o Devices
94. Define UFD and MFD.
In the two-level directory structure, each user has her own user file directory (UFD).
Each UFD has a similar structure, but lists only the files of a single user. When a job starts the
system’s master file directory (MFD) is searched. The MFD is indexed by the user name or
account number, and each entry points to the UFD for that user.
95. Define Claim Edge.
A claim edge Pi -> Rj indicates that process Pi may request resource Rj at some time in
the future. This edge resembles a request edge in direction, but is represented by a dashed line.
96. What are the common strategies to select a free hole from a set of available holes?
1. First fit
2. Best fit
3. Worst fit
97. External fragmentation occurs when all blocks of free memory are too small to accommodate a
segment
98. To enable a process to be larger than the amount of memory allocated to it, overlays are used.
99. A state is safe if the system can allocate resources to each process in some order and still avoid a
deadlock.
100. What are the 3 requirements to solve critical-section problem?
1. Mutual exclusion
2. Progress
3. Bounded waiting.