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

List of Experiments: Exp. No. Name of The Experiments Page No

OS LAB
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

List of Experiments: Exp. No. Name of The Experiments Page No

OS LAB
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 76

CS6412-Operating systems Laboratory Department of CSE

CS6412 OPERATING SYSTEMS LAB L T P C


0 0 3 2

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

EXP. NO. NAME OF THE EXPERIMENTS PAGE NO.

1 Basic of UNIX Commands


2A Sum of First N Numbers
2B Odd or Even
2C Factorial of a Number
2D String Palindrome
3A Implementation of FCFS Scheduling Algorithm
3B Implementation of SJF Scheduling Algorithm
3C Implementation of Priority Scheduling Algorithm
3D Implementation of Round Robin Scheduling Algorithm
4A Implementation of Sequential File Allocation
4B Implementation of Indexed File Allocation
4C Implementation of Linked File Allocation
5 Producer Consumer Problem using Semaphores
6A Implementation of Single Level Directory
6B Implementation of Two Level Directory
6C Implementation of Hierarchy Level Directory
6D Implementation of DAG
7 Bankers Algorithm for Deadlock Avoidance
8 Implementation of Dead Lock Detection Algorithm
9A Implementation of FIFO Algorithm
9B Implementation of LRU Algorithm
9C Implementation of LFU Algorithm
10 Implementation of Shared Memory and IPC
11 Paging Technique of Memory management
12 Threading & Synchronization Applications

Agni College of Technology 1


CS6412-Operating systems Laboratory Department of CSE

Ex No: 1 BASICS OF UNIX COMMANDS


Date:

AIM:

To study and execute basics of UNIX commands.

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$

3. Display the full path of the current working directory


roo@sys5:~/Desktop$ pwd
/home/Desktop
roo@sys5:~/Desktop$

4. Remove a directory
roo@sys5:~/Desktop$ rmdir NewFolder
roo@sys5:~/Desktop$

FILE MANIPULATION COMMANDS

1. Create a file:
roo@sys5:~/Desktop$ cat>a.txt
Hi all
roo@sys5:~/Desktop$

2. Display the contents of a file onto screen:


roo@sys5:~/Desktop$ cat a.txt
Hi all
[roo@sys5:~/Desktop$$

3. List information about files and directories


roo@sys5:~/Desktop$ ls
a.txt b.txt hi.txt
roo@sys5:~/Desktop$

4. List all directories (including .(dot) entries in the long listing.)


roo@sys5:~/Desktop$ ls -a
. .. New Folder a.txt b.txt
roo@sys5:~/Desktop$

5. List all directories with access permission


roo@sys5:~/Desktop$ ls -l
total 12
\\-rw-rw-r-- 1 user1 user1 21 Nov 3 14:14 a.txt
-rw-rw-r-- 1 user1 user1 47 Nov 3 14:15 b.txt

Agni College of Technology 2


CS6412-Operating systems Laboratory Department of CSE

-rw-rw-r-- 1 user1 user1 20 Nov 3 14:03 hi.txt


roo@sys5:~/Desktop$

6. Copy a file:
roo@sys5:~/Desktop$ cp a.txt c.txt
[roo@sys5:~/Desktop$

7.Move or rename a file:


roo@sys5:~/Desktop$ mv c.txt d.txt
roo@sys5:~/Desktop$ ls
a.txt b.txt d.txt s.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$

9. Change the access permission of a file:


roo@sys5:~/Desktop$ ls -l f1.txt
-rw-rw-r-- 1 user1 user1 20 Nov 3 14:14 a.txt
roo@sys5:~/Desktop$ chmod 777 a.txt
roo@sys5:~/Desktop$ ls -l a.txt
-rwxrwxrwx 1 user1 user1 20 Nov 3 14:14 a.txt
roo@sys5:~/Desktop$

10. Update the content of a file:


roo@sys5:~/Desktop$ cat>>a.txt
Good morning
roo@sys5:~/Desktop$ cat a.txt
Hi all
Good morning
roo@sys5:~/Desktop$

11. Number lines of files


roo@sys5:~/Desktop$ nl a.txt
1 Hi all
2 Good morning
roo@sys5:~/Desktop$
12. Extract specific fields
Remove sections from each line of files
roo@sys5:~/Desktop$ cut -c 4 a.txt
n
m
roo@sys5:~/Desktop$
roo@sys5:~/Desktop$ cut -c 4-6 a.txt
nam
md
roo@sys5:~/Desktop$

13. tr command
roo@sys5:~/Desktop$ tr [:lower:] [:upper:]
hi

Agni College of Technology 3


CS6412-Operating systems Laboratory Department of CSE

HI
how are you
HOW ARE YOU
roo@sys5:~/Desktop$ tr [:lower:] [:upper:] <a.txt
HI ALL
GOOD MORNING
roo@sys5:~/Desktop$

14. Word count command:


It is used to count the number of lines, words and characters in a file.
roo@sys5:~/Desktop$ wc a.txt
1 10 56 a.txt
roo@sys5:~/Desktop$ wc -l a.txt
1 a.txt
roo@sys5:~/Desktop$ wc -w a.txt
10 a.txt
roo@sys5:~/Desktop$ wc -c a.txt
56 a.txt
roo@sys5:~/Desktop$

15. Find Command:


It is used to display the pathnames of all files in the current directory and all subdirectories.
roo@sys5:~/Desktop$ find
./New Folder/hi.txt
./a.txt
./c.txt
./b.txt
./.bashrc
./.mozilla
./.mozilla/plugins
./.mozilla/extensions

16. Comparing files:


roo@sys5:~/Desktop$ cat>c.txt
my name is user1
my name is Anbarasan
roo@sys5:~/Desktop$ cmp a.txt c.txt
a.txt c.txt differ: byte 21, line 2
roo@sys5:~/Desktop$

17. Differentiating Files:


Find the differences between two files
roo@sys5:~/Desktop$ diff a.txt c.txt
2c2
< i am doing computer programming lab.
\ No newline at end of file
---
> my name is Anbarasan
roo@sys5:~/Desktop$

18. Touch Command:


Update the access and modification times of each FILE to the current time.
roo@sys5:~/Desktop$ ls -l sam.txt
-rw-rw-r-- 1 user1 user1 20 Nov 3 14:03 sam.txt

Agni College of Technology 4


CS6412-Operating systems Laboratory Department of CSE

roo@sys5:~/Desktop$ touch sam.txt


roo@sys5:~/Desktop$ ls -l sam.txt
-rw-rw-r-- 1 user1 user1 20 Dec 3 15:01 sam.txt
roo@sys5:~/Desktop$

SIMPLE UNIX COMMANDS:


1. Calendar Command:
roo@sys5:~/Desktop$ cal
December 2014
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 28
29 30 31

roo@sys5:~/Desktop$ cal 01 2014


January 2014
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 28 29 30 31

roo@sys5:~/Desktop$ cal 2014


2014

January February March


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
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31
April May June
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 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30

July August September


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 5 1 2 1 2 3 4 5 6
6 7 8 9 10 11 12 3 4 5 6 7 8 9 7 8 9 10 11 12 13
13 14 15 16 17 18 19 10 11 12 13 14 15 16 14 15 16 17 18 19 20
20 21 22 23 24 25 26 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27 28 29 30 31 24 25 26 27 28 29 30 28 29 30 31

October November December

Agni College of Technology 5


CS6412-Operating systems Laboratory Department of CSE

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:

Agni College of Technology 6


CS6412-Operating systems Laboratory Department of CSE

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)

11. echo command:


Display a line of text.
roo@sys5:~/Desktop$ echo "i am a good boy"
i am a good boy
roo@sys5:~/Desktop$

12.Changing Password:
roo@sys5:~/Desktop$ passwd

13. uname command:


Displays the Operating System. print system information
roo@sys5:~/Desktop$ uname
Linux
roo@sys5:~/Desktop$ uname -n
Sjit.linuxserver.org roo@sys5:~/Desktop$
14. bc command

Agni College of Technology 7


CS6412-Operating systems Laboratory Department of CSE

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

PIPES AND FILTERS


Pipes: A mechanism in which the output of one command is redirected as input to another command.
Example 1: Count the number of lines in who command
roo@sys5:~/Desktop$ who | wc -l
1
roo@sys5:~/Desktop$
Example 2: Copy one file to another file using Pipe
roo@sys5:~/Desktop$ cat a.txt | cat>d.txt
roo@sys5:~/Desktop$ cat d.txt
my name is user1
i am doing computer programming lab.
roo@sys5:~/Desktop$

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:

Agni College of Technology 8


CS6412-Operating systems Laboratory Department of CSE

An important use of grep using the “^”pattern is to list the directories.


roo@sys5:~/Desktop$ ls | grep "^s"
sam.txt
roo@sys5:~/Desktop$ ls | grep "^f"
a.txt
b.txt
c.txt
d.txt
roo@sys5:~/Desktop$

roo@sys5:~/Desktop$ ls | grep 't$'


a.txt
b.txt
c.txt
d.txt
sam.txt
roo@sys5:~/Desktop$

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?

Agni College of Technology 9


CS6412-Operating systems Laboratory Department of CSE

Exp No:2A SUM OF FIRST ‘N’ NUMBERS


Date:

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

i=i+1 (Increment to the next number)

4. Display the sum.


5. Stop.

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:

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?
5. Syntax of control statements in shell scripts

Exp No: 2B ODD OR EVEN NUMBER

Agni College of Technology 10


CS6412-Operating systems Laboratory Department of CSE

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:

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?
5. Syntax of control statements in shell scripts

Ex.No.2C FACTORIAL OF A NUMBER


Date

Agni College of Technology 11


CS6412-Operating systems Laboratory Department of CSE

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

4. Display the factorial.


5. Stop.

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:

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?
5. Syntax of control statements in shell scripts

Ex.No.2D STRING PALINDROME


Date:

AIM:
To write a shell program to check whether the given string is a palindrome or not.

Agni College of Technology 12


CS6412-Operating systems Laboratory Department of CSE

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?

Ex No: 3A IMPLEMENTATION OF FCFS SCHEDULING


Date:

AIM:
To write a ‘C’ program to implement FCFS Scheduling.

ALGORITHM:

Agni College of Technology 13


CS6412-Operating systems Laboratory Department of CSE

Step 1: Include the header files for simulating FCFS scheme.


Step 2: Declare the variables to calculate the essential aspects of FCFS.
Step 3: Initially get the process time, arrival time and burst time.
Step 4: Swap all the processes in such a way that they are arranged in FCFS order.
Step 5: Prepare the gantt chart for each process so that their waiting time, turn around time is calculated.
Step 6: Calculate the average waiting time and average turn around time and display the result.

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++)
{

Agni College of Technology 14


CS6412-Operating systems Laboratory Department of CSE

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

roo@sys5:~/Desktop$ gcc fcfs.c


roo@sys5:~/Desktop$ ./a.out
Enter no. of process :2
Enter the burst time for process 1: 2
Enter the burst time for process 2: 1
PROCESS BURST TIME WAITING TIME TURN AROUND TIME
1 2 0 2
2 1 2 3
GAANT CHART
----------------
P1 | P2 |
----------------
0 2 3
Total waiting time :2
Total turn around time :5
Average waiting time :1.00
Average turn around time :2.50
roo@sys5:~/Desktop$

RESULT:

Inference:

Viva Questions:

1. Explain FCFS scheduling.


2. What are the other scheduling algorithms?
3. What is the purposed of scheduling algorithms?
4. Define process.
5. What is meant by burst time, waiting time and turn around time?

Ex No: 3B IMPLEMENTATION OF SJF SCHEDULING


Date:

AIM:
To write a ‘C’ program to implement SJF Scheduling.

ALGORITHM:
Step 1: Include the header files for simulating SJF scheme.

Agni College of Technology 15


CS6412-Operating systems Laboratory Department of CSE

Step 2: Declare the variables to calculate the essential aspects of SJF.


Step 3: Initially get the process time and burst time.
Step 4: Swap all the processes in such a way that they are arranged in shortest job first (SJF) order.
Step 5: Prepare the gantt chart for each process so that their waiting time, turn around time is calculated.
Step 6: Calculate the average waiting time and average turn around time and display the result.

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]);
}

Agni College of Technology 16


CS6412-Operating systems Laboratory Department of CSE

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

roo@sys5:~/Desktop$ gcc sjf.c


roo@sys5:~/Desktop$ ./a.out
Enter no. of process :2
Enter the burst time for process 1: 3
Enter the burst time for process 2: 2
PROCESS BURST TIME WAITING TIME TURN AROUND TIME
2 2 0 2
1 3 2 5

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:

Agni College of Technology 17


CS6412-Operating systems Laboratory Department of CSE

Viva Questions:

1. Explain SJF scheduling.


2. What are the other scheduling algorithms?
3. Advantage of SJF over FCFS?
4. Define process.
5. What is meant by burst time, waiting time and turn around time?

Ex No: 3C IMPLEMENTATION OF PRIORITY SCHEDULING


Date:

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.

Agni College of Technology 18


CS6412-Operating systems Laboratory Department of CSE

Step 4: Execute the process by referring to their priority values.


Step 5: Prepare the gantt chart for each process so that their waiting time, turn around time is calculated.
Step 6: Calculate the average waiting time and average turn around time and display the result.

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];
}

Agni College of Technology 19


CS6412-Operating systems Laboratory Department of CSE

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$ gcc priority.c

roo@sys5:~/Desktop$ ./a.out

Enter no. of process :3

Enter the burst time for process 1: 12

Enter the burst time for process 2: 54

Enter the burst time for process 3: 34

Enter the priority for process 1: 2

Enter the priority for process 2: 3

Enter the priority for process 3: 1

PROCESS BURST TIME PRIORITY WAITING TIME TURNAROUND TIME

Agni College of Technology 20


CS6412-Operating systems Laboratory Department of CSE

3 34 1 0 34

1 12 2 34 46

2 54 3 46 100

GAANT CHART

------------------------

P3 | P1 | P2 |

------------------------

0 34 46 100

Total waiting time :80

Total turnaround time :180

Average waiting time :26.67

Average turn around time :60.00

RESULT:

Inference:

Viva Questions:

1. Explain Priority scheduling.


2. What are the other scheduling algorithms?
3. Advantage of Priority over FCFS?
4. Disadvantage of Priority scheduling?
5. What is meant by burst time, waiting time and turn around time?
6. Can priority scheduling cause starvation?

Agni College of Technology 21


CS6412-Operating systems Laboratory Department of CSE

Ex No: 3D IMPLEMENTATION OF ROUND ROBIN SCHEDULING


Date:
AIM:
To write a ‘C’ program to implement ROUND ROBIN Scheduling.

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;

Agni College of Technology 22


CS6412-Operating systems Laboratory Department of CSE

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;

Agni College of Technology 23


CS6412-Operating systems Laboratory Department of CSE

}
}
}
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

Enter no. of process :3

Enter the burst time for process 1: 2

Enter the burst time for process 2: 2

Enter the burst time for process 3: 2

Enter the slicing time :1

GAANT CHART

------------------------------------------------

P1 | P2 | P3 | P1 | P2 | P3 |

------------------------------------------------

Agni College of Technology 24


CS6412-Operating systems Laboratory Department of CSE

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

Total waiting time:9


Total turnaround time:15
Total response time:3
Average waiting time :3.00
Average turn around time :5.00
Average response time:1.00
roo@sys5:~/Desktop$

RESULT:

Inference:

Viva Questions:

1. Explain Round Robin scheduling.


2. What are the other scheduling algorithms?
3. Advantage of Round Robin scheduling?
4. What is meant by response time and slice time?
5. What is meant by burst time, waiting time and turn around time?

Agni College of Technology 25


CS6412-Operating systems Laboratory Department of CSE

Ex No: 4A IMPLEMENTATION OF SEQUENTIAL FILE ALLOCATION


Date:

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;
}

Agni College of Technology 26


CS6412-Operating systems Laboratory Department of CSE

OUTPUT:

roo@sys5:~/Desktop$ gcc sfa.c


roo@sys5:~/Desktop$ ./a.out
Enter the starting block & length of file 4 10

4->1

5->1

6->1

7->1

8->1

9->1

10->1

11->1

12->1

13->1

the file is allocated to disk

if u want to enter more files?(y-1/n-0)0

RESULT:

Inference:

Viva Questions:

1. Explain Sequential File allocation?


2. What are the other file allocation strategies?
3. Give some real time examples of sequential file allocation?
4. What is the need for efficient file allocation strategies?
5. Explain the program?

Agni College of Technology 27


CS6412-Operating systems Laboratory Department of CSE

Ex No: 4B IMPLEMENTATION OF INDEXED FILE ALLOCATION


Date:

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
{

Agni College of Technology 28


CS6412-Operating systems Laboratory Department of CSE

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]);
for(j=0;j<b1[i];j++)
printf("%d->",blocks[i][j]);
}
}
printf("\n---------------------------------------------\n");
printf("\nDo U want to continue ::(Y-1:n-0)");
scanf("%c",&ch);
}while(ch!=0);
}

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:

1. Explain Indexed File allocation?


2. What are the other file allocation strategies?
3. Give some real time examples of indexed file allocation?
4. What is the need for efficient file allocation strategies?
5. Advantages of indexed file allocation.

Agni College of Technology 29


CS6412-Operating systems Laboratory Department of CSE

Ex No: 4C IMPLEMENTATION OF LINKED FILE ALLOCATION


Date:

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;

Agni College of Technology 30


CS6412-Operating systems Laboratory Department of CSE

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

Agni College of Technology 31


CS6412-Operating systems Laboratory Department of CSE

Fname Fsize Bsize Nblocks Blocks


-------------------------------------------------------------------
bb 1 1024 1 102->104->
-------------------------------------------------------------------
Do U want to continue (Y:n)::0

RESULT:

Inference:

Viva Questions:

1. Explain Linked File allocation?


2. What are the other file allocation strategies?
3. Give some real time examples of linked file allocation?
4. What is the need for efficient file allocation strategies?
5. Advantages of linked file allocation?

Ex No: 5 PRODUCER CONSUMER PROBLEM USING SEMAPHORES

Agni College of Technology 32


CS6412-Operating systems Laboratory Department of CSE

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;

Agni College of Technology 33


CS6412-Operating systems Laboratory Department of CSE

}
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

Agni College of Technology 34


CS6412-Operating systems Laboratory Department of CSE

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

Agni College of Technology 35


CS6412-Operating systems Laboratory Department of CSE

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)
-------------------------------------------------------------------------------

Consumer Stack (Stack Size : 3)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
30 20
-------------------------------------------------------------------------------
CHOICES
~~~~~~~
1.Producer
2.Consumer
3.Exit
Enter your choice : 2

Agni College of Technology 36


CS6412-Operating systems Laboratory Department of CSE

Producer stack is EMPTY


Producer Stack (Stack Size : 3 )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
Stack is EMPTY
(Now It is sleeping)
-------------------------------------------------------------------------------
Consumer Stack (Stack Size : 3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------------------------------------------------------------
30 20
-------------------------------------------------------------------------------

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.

Ex No: 6A IMPLEMENTATION OF SINGLE LEVEL DIRECTORY


Date:
AIM:

Agni College of Technology 37


CS6412-Operating systems Laboratory Department of CSE

To write a program to implement Single Level Directory structure.

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

Agni College of Technology 38


CS6412-Operating systems Laboratory Department of CSE

Enter size of directories: 2 1


Enter file names:
File1
File2
File3
Directory Size Filenames
*****************************
Dir1 2 File1
File2
Dir2 1 File3

RESULT:

Inference:

Viva Questions:

1. Explain Single Level Directory (SLD)?


2. What are the various File directory structures?
3. Advantages of SLD
4. Disadvantages of SLD
5. Give a real time example of SLD

Ex No: 6B IMPLEMENTATION OF TWO LEVEL DIRECTORY


Date:

AIM:
To write a program to implement two level directory structure.

Agni College of Technology 39


CS6412-Operating systems Laboratory Department of CSE

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");

Agni College of Technology 40


CS6412-Operating systems Laboratory Department of CSE

}
printf("\n");
}
getch();
}

OUTPUT:

roo@sys5:~/Desktop$ gcc tld.c


roo@sys5:~/Desktop$ ./a.out
Enter the number of directories: 1
Enter directory1 name: Dir1
Enter size of directories: 2
Enter subdirectory name and size: Sub1 1
Enter file name: File1
Enter subdirectory name and size: Sub2 1
Enter file name: File2
dirname size subdirname size files
*********************************************
Dir1 2 Sub1 1 File1
Sub2 1 File2
RESULT:

Inference:

Viva Questions:

1. Explain Two Level Directory (TLD)?


2. What are the various File directory structures?
3. Advantages of TLD over SLD
4. Disadvantages of TLD
5. Give a real time example of TLD

Ex No: 6C IMPLEMENTATION OF HIERARCHY LEVEL DIRECTORY


Date:
AIM:
To write a program to implement Hierarchy level directory.

ALGORITHM:
Step 1: Read the Directory for which the hierarchy structure to be displayed.

Agni College of Technology 41


CS6412-Operating systems Laboratory Department of CSE

Step 2: Write commands to access through the subdirectories and files in the given directory.

Step 3: If subdirectories found print them as next level of the 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;

Agni College of Technology 42


CS6412-Operating systems Laboratory Department of CSE

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

Agni College of Technology 43


CS6412-Operating systems Laboratory Department of CSE

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:

1. Explain Hierarchical Level Directory (HLD)?


2. What are the various File directory structures?
3. Advantages of HLD over SLD and TLD.
4. Disadvantages of HLD.
5. Give a real time example of HLD.

Ex No: 6D IMPLEMENTATION OF DAG


Date:
AIM:
To write a program to implement Directed Acyclic Graph directory structure

ALGORITHM:
Step 1: Start with the implementation of directed acyclic .

Step 2: Create the vertices and edges of the graph.

Step 3: Assign the vertices to the directories.

Agni College of Technology 44


CS6412-Operating systems Laboratory Department of CSE

Step 4: Use edges to link the sub directories and files which are again vertices of the graph.

Step 5: Display the DAG file organization.

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

Agni College of Technology 45


CS6412-Operating systems Laboratory Department of CSE

{
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

Agni College of Technology 46


CS6412-Operating systems Laboratory Department of CSE

Enter Name of dir/file (under VB): B


Enter 1 for Dir /2 for file:2
Enter Name of dir/file (under USER1): C
Enter 1 for Dir /2 for file:2
Enter Name of dir/file (under ROOT): USER2
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for USER2): 1
Enter Name of dir/file (under USER2):JAVA
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for JAVA):2
Enter Name of dir/file (under JAVA):D
Enter 1 for Dir /2 for file:2
Enter Name of dir/file (under JAVA):HTML
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for HTML):0
How many links:2
File/Dir: B
User Name: USER 2
File/Dir: HTML
User Name: USER1

RESULT:

Inference:

Viva Questions:

1. What is Directed acyclic graph?


2. What are the other file organization methods?
3. Draw a sample DAG?
4. Advantages and disadvantages of DAG
5. Real time examples of DAG usage

ExNo:7 BANKERS ALGORITHM FOR DEADLOCK AVOIDANCE


Date:

AIM: To write a program to implement bankers algorithm for deadlock avoidance.

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];

Agni College of Technology 47


CS6412-Operating systems Laboratory Department of CSE

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:

Step 1: Start the program.


Step 2: Get the values of resources and processes.
Step 3: Get the avail value.
Step 4: After allocation find the need value.
Step 5: Check whether its possible to allocate.
Step 6: If it is possible then the system is in safe state.
Step 7: Else system is not in safety state.
Step 8: If the new request comes then check that the system is in safety or not if we allow the request.
Step 9: stop the program.

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++)

Agni College of Technology 48


CS6412-Operating systems Laboratory Department of CSE

{
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

Agni College of Technology 49


CS6412-Operating systems Laboratory Department of CSE

200
302
211
002
The system is in safe state 1 2 3 4 5

RESULT:

Inference:

Viva Questions:

1. Explain Bankers algorithm?


2. What is meant by deadlock?
3. What is dead lock avoidance?
4. What are the dead lock avoidance methods?
5. How can we prevent deadlocks?
6. What is meant by starvation?
7. When a system is said to be in safe state?

Ex No: 8 IMPLEMENTATION OF DEADLOCK DETECTION


Date:

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.

Agni College of Technology 50


CS6412-Operating systems Laboratory Department of CSE

Step 10: Stop the program.

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++;
}
}

Agni College of Technology 51


CS6412-Operating systems Laboratory Department of CSE

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) :

Agni College of Technology 52


CS6412-Operating systems Laboratory Department of CSE

21121
Enter availability vector (available resources) :
00001
deadlock causing processes are : 2 3

RESULT:

Inference:

Viva Questions:

1. What is deadlock, starvation? Explain their difference.


2. How can we detect deadlocks?
3. What is deadlock prevention? Explain its methods.
4. What is meant by finite state?
5. What is resource allocation graph

Ex No: 9A IMPLEMENTATION OF FIFO ALGORITHM


Date:

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

Agni College of Technology 53


CS6412-Operating systems Laboratory Department of CSE

Step 9: Display the values


Step 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:

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

Agni College of Technology 54


CS6412-Operating systems Laboratory Department of CSE

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:

1. What is page and frame in OS?


2. Explain FIFO technique?
3. What is meant by Belady’s Anamoly
4. What are the other page replacement techniques?
5. What is meant by page fault?

Ex No: 9B IMPLEMENTATION OF LRU ALGORITHM


Date:

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

Agni College of Technology 55


CS6412-Operating systems Laboratory Department of CSE

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++)

Agni College of Technology 56


CS6412-Operating systems Laboratory Department of CSE

{
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

The no of page faults is 10

Agni College of Technology 57


CS6412-Operating systems Laboratory Department of CSE

RESULT:

Inference:

Viva Questions:

1. Explain LRU technique?


2. What are the other page replacement techniques?
3. What is meant by page fault?
4. Advantages of LRU over FIFO
5. Disadvantages of LRU

Ex No: 9C IMPLEMENTATION OF LFU ALGORITHM


Date:

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:

Agni College of Technology 58


CS6412-Operating systems Laboratory Department of CSE

#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;

printf("Enter no of frames : ");


scanf("%d",&f);
printf("Enter no of pages : ");
scanf("%d",&p);

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++)

Agni College of Technology 59


CS6412-Operating systems Laboratory Department of CSE

{
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

Agni College of Technology 60


CS6412-Operating systems Laboratory Department of CSE

2 1 3
2 7 3
2 7 5
2 4 5
2 4 3

Page hit=1

RESULT:

Inference:

Viva Questions:

1. Explain LFU technique?


2. What are the other page replacement techniques?
3. What is meant by page fault?
4. Advantages of LFU over FIFO,LRU.
5. Disadvantages of LFU.
6. Which is the best page replacement technique?

Ex No: 10 IMPLEMENTATION OF SHARED MEMORY AND IPC Date:

AIM:
To write a program to implement inter process communication and shared memory.

ALGORITHM:
Step 1: Create and shared memory using shmget.

Step 2: Attach pointer to a memory using shmat.

Step 3: Create child process to write data to memory.

Step 4: Print the shared memory data using server process.

Step 5: Stop the execution.

PROGRAM
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#define SHMSZ 27

Agni College of Technology 61


CS6412-Operating systems Laboratory Department of CSE

main()
{
char c;
int shmid,childpid;
key_t key;
char *shm, *s;

key = 5679;

if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {


perror("shmget");
exit(1);
}
if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
perror("shmat");
exit(1);
}
s = shm;
if((childpid = fork()) < 0) // error occured
{
perror("Fork Failed");
exit(1);
}
else if(childpid == 0) // child process
{
for (c = 'a'; c <= 'z'; c++)
*s++ = c;
*s = NULL;
}
else
{
for (s = shm; *s != NULL; s++)
putchar(*s);
putchar('\n');
}
exit(0);
}

OUTPUT
roo@sys5:~/Desktop$ ipc.c
roo@sys5:~/Desktop$ ./a.out
------ Shared Memory Segments --------

key shmid owner perms bytes nattch status

0x00000000 3801090 root 644 52 2

0x00000000 3833860 root 644 16384 2

0x00000000 3866629 root 644 268 2

0x0000162f 5079047 cse101 666 27 0

------ Semaphore Arrays --------

Agni College of Technology 62


CS6412-Operating systems Laboratory Department of CSE

key semid owner perms nsems

------ Message Queues --------

key msqid owner perms used-bytes messages

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?

Ex No: 11 PAGING TECHNIQUE OF MEMORY MANAGEMENT


Date:

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;

Agni College of Technology 63


CS6412-Operating systems Laboratory Department of CSE

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:

1. Explain paging technique.


2. Define pages, frames, offset in paging technique.

Agni College of Technology 64


CS6412-Operating systems Laboratory Department of CSE

3. What is meant by logical and physical address?


4. What is thrashing?
5. What is meant by page hit, page fault?
6. What is the formula to calculate physical address?

Ex No: 12 THREADING AND SYNCHRONIZATION APPLICATIONS


Date:

AIM:

To write a program to implement the application of threading and synchronization.

ALGORITHM:

Step 1: Start the process


Step 2: Initialize mutex lock ,thread id and required other variables
Step 3: Create POSIX threads using pthread_create
Step 4: Define thread task by creating new function.
Step 5: Synchronize threads using mutex lock and unlock variables
Step 6: Using pthread_join allow threads to wait until parent process completes
Step 7: Destroy the synchronization variable mutex using pthread_mutex_destroy
Step 8: Stop the process

PROGRAM
//Threading Application Program
#include <pthread.h>

#include <stdio.h>

/* this function is run by the second thread */

Agni College of Technology 65


CS6412-Operating systems Laboratory Department of CSE

void *inc_x(void *x_void_ptr)

/* increment x to 100 */

int *x_ptr = (int *)x_void_ptr;

while(++(*x_ptr) < 100);

printf("x increment finished\n");

return NULL;

int main()

int x = 0, y = 0;

/* show the initial values of x and y */

printf("x: %d, y: %d\n", x, y);

/* this variable is our reference to the second thread */

pthread_t inc_x_thread;

/* create a second thread which executes inc_x(&x) */

if(pthread_create(&inc_x_thread, NULL, inc_x, &x)) {

fprintf(stderr, "Error creating thread\n");

return 1;

/* increment y to 100 in the first thread */

while(++y < 100);

printf("y increment finished\n");

/* wait for the second thread to finish */

if(pthread_join(inc_x_thread, NULL)) {

fprintf(stderr, "Error joining thread\n");

return 2;

Agni College of Technology 66


CS6412-Operating systems Laboratory Department of CSE

/* show the results - x is now 100 thanks to the second thread */

printf("x: %d, y: %d\n", x, y);

return 0;

OUTPUT

roo@sys5:~/Desktop$ gcc final.c –o final -lthread


roo@sys5:~/Desktop$ ./a.out
x: 0, y: 0

y increment finished

x increment finished

x: 100, y: 100

roo@sys5:~/Desktop$

//Synchoronization Application Program

#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;

void* doSomeThing(void *arg)

pthread_mutex_lock(&lock);

unsigned long i = 0;

counter += 1;

printf("\n Job %d started\n", counter);

for(i=0; i<(0xFFFFFFFF);i++);

printf("\n Job %d finished\n", counter);

Agni College of Technology 67


CS6412-Operating systems Laboratory Department of CSE

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

roo@sys5:~/Desktop$ synthread.c -o synthread -pthread

roo@sys5:~/Desktop$ ./a.out

Job 1 started

Agni College of Technology 68


CS6412-Operating systems Laboratory Department of CSE

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.

Agni College of Technology 69


CS6412-Operating systems Laboratory Department of CSE

CS6412 – Operating Systems Laboratory

1. What are the basic functions of an operating system?


Operating system controls and coordinates the use of the hardware among the various
applications programs for various uses. Operating system acts as resource allocator and manager.
Operating system is control program which controls the user programs to prevent errors and
improper use of the computer. 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..
2. While running DOS on a PC, which command would be used to duplicate the entire diskette?
Disk copy
3. What resources are used when a thread created?
When a thread is created the threads does not require any new resources to execute the thread
shares the resources like memory of the process to which they belong to.
4. What is virtual memory?
Virtual memory is hardware technique where the system appears to have more memory that it
actually does.
5. What is Throughput?
Throughput - number of processes that complete their execution per time unit.
6. What is Turnaround time?
Turnaround time - amount of time to execute a particular process.
7. What is waiting time ?
Waiting time ¬ amount of time a process has been waiting in the ready queue.
8. What is Response time?
Response time ¬ amount of time it takes from when a request was submitted until the first
response is produced, not output (for time-sharing environment).
9. What is the state of the processor, when a process is waiting for some event to occur?
Waiting state
10. What is the important aspect of a real-time system or Mission Critical Systems?
A real time operating system has well defined fixed time constraints. Process must be done
within the defined constraints or the system will fail. Real-Time systems may be either hard or
soft real-time.
11. What is the difference between Hard and Soft real-time systems?
A hard real-time system guarantees that critical tasks complete on time. This goal requires that all
delays in the system be bounded from the retrieval of the stored data to the time that it takes the
operating system to finish any request made of it. A soft real time system where a critical real-
time task gets priority over other tasks and retains that priority until it completes. As in hard real
time systems kernel delays need to be bounded
12. What is the cause of thrashing? How does the system detect thrashing? Once it detects
thrashing, what can the system do to eliminate this problem?
Thrashing is caused by under allocation of the minimum number of pages required by a process,
forcing it to continuously page fault. The system can detect thrashing by evaluating the level of
CPU utilization as compared to the level of multiprogramming. It can be eliminated by reducing
the level of multiprogramming.
13. What is multi tasking?
Multi tasking: Multitasking is the logical extension of multiprogramming .The concept of
multitasking is quite similar to multiprogramming but difference is that the switching between
jobs occurs so frequently that the users can interact with each program while it is running. This
concept is also known as time-sharing systems. A time-shared operating system uses CPU
scheduling and multiprogramming to provide each user with a small portion of time-shared
system
14. What is multi programming, ? –

Agni College of Technology 70


CS6412-Operating systems Laboratory Department of CSE

Multi programming: Multiprogramming is the technique of running several programs at a time


using timesharing. It allows a computer to do several things at the same time. Multiprogramming
creates logical parallelism. The concept of multiprogramming is that the operating system keeps
several jobs in memory simultaneously. The operating system selects a job from the job pool and
starts executing a job, when that job needs to wait for any i/o operations the CPU is switched to
another job. So the main idea here is that the CPU is never idle.

15. What is Multi threading:?


An application typically is implemented as a separate process with several threads of control. A
busy web server may have several of clients concurrently accessing it. If the web server ran as a
traditional single-threaded process, it would be able to service only one client at a time. The
amount of time that a client might have to wait for its request to be serviced could be enormous.
So it is efficient to have one process that contains multiple threads to serve the same purpose. To
get the advantages like responsiveness, Resource sharing economy and utilization of
multiprocessor architectures multithreading concept can be used.
16. 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.
17. What is fragmentation? Different types of fragmentation?
Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are
too small to satisfy any request. External Fragmentation: External Fragmentation happens when
a dynamic memory allocation algorithm allocates some memory and a small piece is left over that
cannot be effectively used. If too much external fragmentation occurs, the amount of usable
memory is drastically reduced. Total memory space exists to satisfy a request, but it is not
contiguous. Internal Fragmentation: Internal fragmentation is the space wasted inside of
allocated memory blocks because of restriction on the allowed sizes of allocated blocks.
Allocated memory may be slightly larger than requested memory; this size difference is memory
internal to a partition, but not being used
18. What is DRAM? In which form does it store data?
DRAM is 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.
19. What is Dispatcher?
Dispatcher module gives control of the CPU to the process selected by the short-term scheduler;
this involves: Switching context, Switching to user mode, Jumping to the proper location in the
user program to restart that program, dispatch latency time it takes for the dispatcher to stop one
process and start another running.
20. What is CPU Scheduler?
Selects from among the processes in memory that are ready to execute, and allocates the CPU to
one of them. CPU scheduling decisions may take place when a process: 1.Switches from running
to waiting state. 2.Switches from running to ready state. 3.Switches from waiting to ready.
4.Terminates. Scheduling under 1 and 4 is non-preemptive. All other scheduling is preemptive.
21. What is Context Switch?
Switching the CPU to another process requires saving the state of the old process and loading the
saved state for the new process. This task is known as a context switch. Context-switch time is
pure overhead, because the system does no useful work while switching. Its speed varies from
machine to machine, depending on the memory speed, the number of registers which must be
copied, the existed of special instructions(such as a single instruction to load or store all
registers).
22. What is cache memory?

Agni College of Technology 71


CS6412-Operating systems Laboratory Department of CSE

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

Agni College of Technology 72


CS6412-Operating systems Laboratory Department of CSE

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

Agni College of Technology 73


CS6412-Operating systems Laboratory Department of CSE

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

Agni College of Technology 74


CS6412-Operating systems Laboratory Department of CSE

 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.

Agni College of Technology 75


CS6412-Operating systems Laboratory Department of CSE

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.

Agni College of Technology 76

You might also like