OS Lab Manual
OS Lab Manual
OS Lab Manual
PREPARED BY
DEPARTMENT OF CSE
SYLLABUS
Queuing).
10. Program for FIFO, LRU, and OPTIMAL page replacement algorithm.
********
COURSE OBJECTIVES :
COURSE OUTCOMES :
LAB MAPPING:
Program Outcomes
LAB
Type:
- Average contribution
- Some contribution
- No contribution
Implement the following on LINUX platform. Use C for high level language implementation .
INDEX
8
ii. To study Dinning Philosophers Problem.
8 Simulation of scheduling algorithms: Write a program to
implement the following process scheduling algorithms
i. First Come First Serve
Experiment 1 :
Experiment 2:
based on the Linux kernel. Their development is one of the most prominent
examples of free and open source software collaboration; typically all the
anyone.
The name "Linux" comes from the Linux kernel, originally written in 1991
such as the Apache HTTP Server, the X Window System, the K Desktop
Environment, and utilities and libraries from the GNU operating system
EXPERIMENT – 1
THEORY:
The Linux file system is the structure in which all the information on your computer is
stored. Files are organized within a hierarchy of directories. Each directory can contain files,
as well as other directories.
If you were to map out the files and directories in Linux, it would look like an upside-down
tree. At the top is the root directory, which is represented by a single slash ( / ). Below that is
a set of common directories in the Linux system, such as bin, dev, home, lib , and tmp , to
name a few. Each of those directories, as well as directories added to the root, can contain
subdirectories.
Some of the Linux directories that may interest you include the following:
/bin - Contains common Linux user commands, such as ls, sort , date , and chmod .
/boot - Has the bootable Linux kernel and boot loader configuration files (GRUB).
/dev - Contains files representing access points to devices on your systems. These
include terminal devices ( tty* ), floppy disks ( fd* ), hard disks ( hd* or sc* ), RAM (
ram* ), and CD-ROM ( cd* ). (Applications normally access these devices directly
through the device files, but end users rarely access them directly.)
/etc - Contains administrative configuration files.
/home - Contains directories assigned to each user with a login account.
/media - Provides a location for mounting devices, such as remote file systems and
removable media (with directory names of cdrom , floppy , and so on). In Fedora and
RHEL, many removable media are mounted automatically in this directory when the
media is inserted (CD or DVD) or connected (USB pen drives or cameras ).
/proc - Provides a mechanism for the kernel to send information to processes.
/root - Represents the root user's home directory.
/sbin - Contains administrative commands and daemon processes.
/sys - A /proc -like file system, added with the Linux 2.6 kernel and intended to
contain files for getting hardware status and reflecting the system's device tree as it is
seen by the kernel. It pulls many of its functions from /proc .
/tmp - Contains temporary files used by applications.
/usr - Contains user documentation, games , graphical files (X11), libraries (lib), and
a variety of other user and administrative commands and files.
/var - Contains directories of data used by various applications. In particular, this is
where you would place files that you share as an FTP server ( /var/ftp ) or a Web
server ( /var/www ). It also contains all system log files ( /var/log ). In time, FTP,
HTTP, and similar services will move to the /srv directory to adhere to the Linux
Standards Base ( www.freestandards.org/spec ).
COMMAND :
1.Date Command :
Syntax :
$date
$date +%ch
Options :
a = Abbrevated weekday.
A = Full weekday.
b = Abbrevated month.
B = Full month.
c = Current day and time.
C = Display the century as a decimal number.
d = Day of the month.
D = Day in „mm/dd/yy‟ format
h = Abbrevated month day.
H = Display the hour.
L = Day of the year.
m = Month of the year.
M = Minute.
P = Display AM or PM
S = Seconds
T = HH:MM:SS format
u = Week of the year.
y = Display the year in 2 digit.
Y = Display the full year.
Z = Time zone .
2.Calender Command :
This command is used to display the calendar of the year or the particular month of
calendar year.
Syntax :
a.$cal <year>
b.$cal <month> <year>
Here the first syntax gives the entire calendar for given year & the second Syntax gives
the calendar of reserved month of that year.
3.Echo Command :
4.Banner Command :
5.’who’ Command :
It is used to display who are the users connected to our computer currently.
Options : -
6.’who am i’ Command :
Syntax : $who am i
9.’CLEAR’ Command :
Syntax : $clear
10.’MAN’ Command :
It help us to know about the particular command and its options & working. It is like
„help‟ command in windows .
11.LIST Command :
Options :
a– used to list all the files including the hidden files.
c– list all the files columnwise.
d- list all the directories.
m- list the files separated by commas.
p- list files include „/‟ to all the directories.
r- list the files in reverse alphabetical order.
f- list the files based on the list modification date.
x-list in column wise sorted order.
Syntax : $pwd
2.MKDIR Command :
3.CD Command :
4.RMDIR Command :
To remove a directory in the current directory & not the current directory itself.
Syntax : $rmdir <directory name>
1.CREATE A FILE :
2.DISPLAY A FILE :
To display the content of file mentioned we use CAT command without „>‟ operator.
3.COPYING CONTENTS :
To copy the content of one file with another. If file doesnot exist, a new file is created
and if the file exists with some data then it is overwritten.
Options :
Syntax :
$cat –n <filename>
4.SORTING A FILE :
To sort the contents in alphabetical order in reverse order.
Syntax :
$sort <filename >
Syntax :
$cp <source filename> <destination filename>
$cp <source filename path > <destination filename path>
6.MOVE Command :
To completely move the contents from source file to destination file and to remove the
source file.
Syntax :
$ mv <source filename> <destination filename>
7.REMOVE Command :
To permanently remove the file we use this command .
Syntax :
$rm <filename>
8.WORD Command :
To list the content count of no of lines , words, characters .
Syntax :
$wc<filename>
Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.
Syntax: $head<filename>
TAIL : This command is used to display the last ten lines of file.
Syntax: $tail<filename>
PAGE : This command shows the page by page a screen full of information is displayed after
which the page command displays a prompt and passes for the user to strike the enter key to
continue scrolling.
MORE : It also displays the file page by page .To continue scrolling with more command ,
press the space bar key.
Syntax: $more<filename>
Syntax: $sort<filename>
PIPE : It is a mechanism by which the output of one command can be channelled into the
input of another command.
TR :The tr filter is used to translate one set of characters from the standard inputs to another.
INPUT :
Valid Input-
Valid Output-
Invalid Input-
Invalid Output-
VIVA QUESTION :
EXPERIMENT – 2
AIM :
To study the various commands operated in vi editor in LINUX.
THEORY :
The Vi editor is a visual editor used to create and edit text, files, documents and
programs. It displays the content of files on the screen and allows a user to add, delete or
change part of text . There are three modes available in the Vi editor , they are
1.Command mode
2.Input (or) insert mode.
Starting Vi :
The Vi editor is invoked by giving the following commands in LINUX prompt.
This command would open a display screen with 25 lines and with tilt (~) symbol at the
start of each line. The first syntax would save the file in the filename mentioned and for the
next the filename must be mentioned at the end.
Options :
1.vi +n <filename> - this would point at the nth line (cursor pos).
2.vi –n <filename> - This command is to make the file to read only to change from one mode
to another press escape key.
To move editor from command node to edit mode, you have to press the <ESC> key.
1.ESC a Command :
This command is used to move the edit mode and start to append after the current
character.
Syntax : <ESC> a
2.ESC A command :
This command is also used to append the file , but this command append at the end of
current line.
Syntax : <ESC> A
3.ESC i Command :
This command is used to insert the text before the current cursor position.
Syntax : <ESC> i
4.ESC I Command :
Syntax : <ESC> I
5.ESC o Command :
This command is insert a blank line below the current line & allow insertion of
contents.
Syntax : <ESC> o
6.ESC O Command :
This command is used to insert a blank line above & allow insertion of contents.
Syntax : <ESC> O
7.ESC r Command :
This command is to replace the particular character with the given characters.
8.ESC R Command :
This command is used to replace the particular text with a given text.
9.<ESC> s Command :
Syntax : <ESC> s
10.<ESC> S Command :
This command is used to replace a current line with group of characters.
Syntax : <ESC> S
CURSOR MOVEMENT IN Vi :
1.<ESC> h :
This command is used to move to the previous character typed. It is used to move to
left of the text . It can also used to move character by character (or) a number of characters.
2.<ESC> l :
This command is used to move to the right of the cursor (ie) to the next character. It can
also be used to move the cursor for a number of character.
3.<ESC> j :
Syntax :
<ESC> j – single down movement.
<ESC> nj – „n‟ times down movement.
4.<ESC> k :
Syntax :
<ESC> k – single line above.
<ESC> nk – „n‟ lines above.
This command will move the cursor to the starting of next lines or a group of lines
mentioned.
Syntax :
<ESC> enter <ESC> n enter.
6.<ESC> + Command :
7.<ESC> - Command :
This command is used to move to the beginning of the previous line.
Syntax :
<ESC> - <ESC> n-
8.<ESC> 0 :
This command will bring the cursor to the beginning of the same current line.
Syntax :
<ESC> 0
9.<ESC> $ :
This command will bring the cursor to the end of the current line.
Syntax :
<ESC> $
10.<ESC> ^ :
Syntax :
<ESC> ^
11.<ESC> b Command :
This command is used to move back to the previous word (or) a number of words.
Syntax :
<ESC> b <ESC>nb
12.<ESC> e Command :
This command is used to move towards and replace the cursor at last character of the
word (or) no of words.
Syntax :
<ESC> e <ESC>ne
13.<ESC> w Command :
Syntax :
<ESC> w <ESC> nw
1.<ESC> x Command :
2.<ESC> X Command :
3.<ESC> dw Command :
This command is to delete a single word or number of words to right of current cursor
position.
Syntax :
<ESC> dw <ESC> ndw
4.db Command :
This command is to delete a single word to the left of the current cursor position.
Syntax :
<ESC> db <ESC> ndb
5.<ESC> dd Command :
This command is used to delete the current line (or) a number of line below the current
line.
Syntax :
<ESC> dd <ESC> ndd
6.<ESC> d$ Command :
This command is used to delete the text from current cursor position to last character of
current line.
Syntax : <ESC> d$
1.<ESC> w Command :
To save the given text present in the file.
Syntax : <ESC> : w
2.<ESC> q! Command :
3.<ESC> wq Command :
This command quits the vi editor after saving the text in the mentioned file.
4.<ESC> x Command :
Syntax : <ESC> :x
5.<ESC> q Command :
This command would quit the window but it would ask for again to save the file.
Syntax : <ESC> : q
INPUT :
Valid Input-
Start by creating a file and putting some content into it. Save the file and view it in
both cat and less Go back into the file in vi and enter some more content. Move
around the content using at least 6 different movement commands.
Valid Output-
Invalid Input-
Invalid Output
VIVA QUESTION :
EXPERIMENT – 3
AIM :
THEORY :
Common Shells.
C-Shell - csh : The default on teaching systems Good for interactive systems Inferior
programmable features
Bourne Shell - bsh or sh - also restricted shell - bsh : Sophisticated pattern matching
and file name substitution
Korn Shell : Backwards compatible with Bourne Shell Regular expression
substitution emacs editing mode
Thomas C-Shell - tcsh : Based on C-Shell Additional ability to use emacs to edit the
command line Word completion & spelling correction Identifying your
shell.
SHELL KEYWORDS :
echo, read, if fi, else, case, esac, for , while , do , done, until , set, unset, readonly, shift,
export, break, continue, exit, return, trap , wait, eval ,exec, ulimit , umask. ‘
EXPRESSION Command :
OPERATORS :
Shell uses the built-in test command operators to test numbers and strings.
Equality:
= string
!= string
-eq number
-ne number
Logical:
-a and
-o or
! not
Logical:
AND
&&
OR
||
Relational:
-gt greater than
-ge greater than, equal to
-lt less than
-le less than, equal to
Arithmetic :
+, -, \*, /, %
LINUX Shell supports conditional statements which are used to perform different actions
based on different conditions. Here we will explain following two decision making
statements:
if...else statements:
If else statements are useful decision making statements which can be used to select an option
from a given set of options.
if...fi statement
if...else...fi statement
if...elif...else...fi statement
if...fi statement
Syntax:
if [ expression ]
Then
block of statements
Fi
if...else...fi statement
syntax:
If[expression]
then
block of statements
else
block of statements
fi
if...else...fi statement
syntax:
Department of Computer Science & Engineering Page 23
Operating System Lab Manual GEC
If[expression]
then
block of statements
elif[expression]
then
block of statement
elif [expression]
then
else
block of statements
fi
case...esac statement
case variable_name in
pattern1)
statements
;;
pattern2)
statements
;;
pattern3)
;;
*) default value
;;
esac
1 .ALGORTHIM :
INPUT:
Valid Input:
Enter A:23
Enter B:45
Enter C:67
Valid Output:
C is greater
Invalid Input:
Enter A:GEC
Enter B:45
Enter C:67
Invalid Output:
2. ALGORITHM :
INPUT :
Valid Input:
1. Addition
2. Subtraction
3. Multiplication
4. Division
Valid Output:
Invalid Input:
1. Addition
2. Subtraction
3. Multiplication
4. Division
Invalid Output:
3.
Algorithm:
Step1: Enter into the vi editor and go to the insert mode for entering the code
Step2: Read the first string.
Step3: Read the second string
Step4: Compare the two strings using the if loop
Step5: If the condition satisfies then print that two strings are equal else print two
strings are not equal.
Step6: Enter into the escape mode for the execution of the result and verify the output
INPUT :
Valid Input:
Valid Output:
Invalid Input:
Invalid Output:
VIVA QUESTION:
EXPERIMENT – 4
AIM:
THEORY:
Loop defined as:"Computer can repeat particular instruction again and again, until particular
condition satisfies. A group of instruction that is executed repeatedly is called a loop."
(a) First, the variable used in loop condition must be initialized, then execution of the loop
begins.
(b) A test (condition) is made at the beginning of each iteration.
(c) The body of loop ends with a statement that modifies the value of the test (condition)
variable.
While Loop
Syntax:
while [ condition ]
do
……
statements
done
Until Loop
until command
do
done
For Loop
Syntax 1:
for (( expr1; expr2; expr3 ))
do
.....
.....
repeat all statements between do and
done until expr2 is TRUE
Done
Syntax 2:
do
…..
…..
execute one for each item in the list until the list is not
done
ARRAY:
Shell supports a different type of variable called an array variable that can hold multiple values at the
same time. Arrays provide a method of grouping a set of variables. Instead of creating a new name for
each variable that is required, you can use a single array variable that stores all the other variables.
Simplest method of creating an array variable is to assign a value to one of its indices. This is
expressed as follows:
array_name[index]=value
Here array_name is the name of the array, index is the index of the item in the array that you want to
set, and value is the value you want to set for that item.
After you have set any array variable, you access it as follows:
${array_name[index]}
Here array_name is the name of the array, and index is the index of the value to be accessed.
1.
ALGORTHIM
step 1. Start
step 2. Read the number n
step 3. [Initialize]
i=1, fact=1
step 4. Repeat step 4 through 6 until i=n
step 5. fact=fact*i
step 6. i=i+1
step 7. Print fact
Department of Computer Science & Engineering Page 29
Operating System Lab Manual GEC
step 8. Stop
[process finish of calculate the factorial value of a number]
INPUT :
Valid Input:
Valid Output:
120
Invalid Input:
Invalid Output:
2.
ALGORITHM :
INPUT :
Valid input:
Valid Output:
120
Invalid input:
Invalid output:
3.
ALGORTHIM:
1. Start
2. Declare variables x, y, n, a, z, s
3. Enter the limit
4. Initialize the value of variables, s=n , x=0, y=0 , z=s
5. Do the following operations in loop
a. x = 0 to n
b. a= 1, x++
c. z=s to 0
d. print space
e. z —-
f. y = o to x
g. print a
h. a = a*(x-y)/(y+1)
i. y= y+1
j. go to next line
6. Repeat the process to n
7. Print the final required triangle
8. Stop
INPUT:
Valid input:
Valid output:
Invalid input:
Invalid output:
VIVA QUESTION:
EXPERIMENT – 5
AIM:
Department of Computer Science & Engineering Page 31
Operating System Lab Manual GEC
To study the various File Acess Permission and different types users in LINUX
THEORY:
File ownership is an important component of LINUX that provides a secure method for storing files.
Every file and directory in LINUX has the following attributes:
Owner permissions: The owner's permissions determine what actions the owner of the file
can perform on the file.
Group permissions: The group's permissions determine what actions a user, who is a
member of the group that a file belongs to, can perform on the file.
Other (world) permissions: The permissions for others indicate what action all other users
can perform on the file.
1. Read:Grants the capability to read ie. view the contents of the file and directory .
2. Write:Grants the capability to modify, or remove the content of the file and directory .
3. Execute:User with execute permissions can run a file as a program.But in case of directory , it
does not mean anything only traverse permission .
r W X r __ X r __ X
__
File Permission for the owner Permission of the Permission for the
Type of file group to which the rest of users
files belongs
CHANGING PERMISSIONS:
To change file or directory permissions, you use the chmod (change mode) command. There
are two ways to use chmod: symbolic mode and absolute mode.
The easiest way for a beginner to modify file or directory permissions is to use the symbolic
mode. With symbolic permissions you can add, delete, or specify the permission set you want
by using the operators in the following table.
u user
g group
o other
a all
r read
w write
x execute
The second way to modify permissions with the chmod command is to use a number to
specify each set of permissions for the file.
Each permission is assigned a value, as the following table shows, and the total of each set of
permissions provides a number for that set.
0 No permission ---
1 Execute permission --x
2 Write permission -w-
Execute and write permission: 1 (execute) + 2
3 -wx
(write) = 3
4 Read permission r--
Read and execute permission: 4 (read) + 1
5 r-x
(execute) = 5
While creating an account on Unix, it assigns a owner ID and a group ID to each user. All the
permissions mentioned above are also assigned based on Owner and Groups.
Two commands are available to change the owner and the group of files:
1. chown: The chown command stands for "change owner" and is used to change the
owner of a file.
2. chgrp: The chgrp command stands for "change group" and is used to change the
group of a file.
Changing ownership:
syntax :
The value of user can be either the name of a user on the system or the user id (uid) of a user
on the system.
syntax :
INPUT:
Valid input: Create a directory and put some files into it. Now play about with removing
various permissions from yourself on that directory and see what you can and can't do.
Valid output:
Invalid input:
chmode u + g file1
Invalid output:
EXPERIMENT –6
AIM :
1. To write a program to create a process in LINUX.
2. To study Dinning Philosophers Problem.
THEORY:
Five philosophers are seated around a circular table. Each philosopher has a place of
spaghetti and he needs two forks to eat. Between each plate there is a fork. The life of a
philosopher consists of alternate period of eating & thinking. When a philosopher gets
hungry, he tries to acquire his left fork, if he gets it, it tries to acquire right fork.
In this solution, we check after picking the left fork whether the right fork is available or not.
If not, then philosopher puts down the left fork & continues to think. Even this can fail if all
the philosophers pick the left fork simultaneously & no right forks available & putting the left
fork down again. This repeats & leads to starvation.
Now, we can modify the problem by making the philosopher wait for a random amount of
time instead of same time after failing to acquire right hand fork. This will reduce the
problem of starvation. Solution to dinning philosophers problem.
1 . ALGORITHM:
INPUT:
Valid input:
$cc pc.c
$a.out
parent process$ child process
$ps
PID CLS PRI TTY TIME COMD
5913 TS 70 pts022 0:00 ksh
6229 TS 59 pts022 0:00 ps
Valid output:
Invalid input:
Invalid output:
2 . ALGORITHM:
system DINING_PHILOSOPHERS
VAR
me: semaphore, initially 1; /* for mutual exclusion */
s[5]: semaphore s[5], initially 0; /* for synchronization */
pflag[5]: {THINK, HUNGRY, EAT}, initially THINK; /* philosopher flag */
procedure philosopher(i)
{
while TRUE do
{
THINKING;
take_chopsticks(i);
EATING;
drop_chopsticks(i);
}
}
The take_chopsticks procedure involves checking the status of neighboring philosophers and
then declaring one's own intention to eat. This is a two-phase protocol; first declaring the
status HUNGRY, then going on to EAT.
procedure take_chopsticks(i)
{
DOWN(me); /* critical section */
pflag[i] := HUNGRY;
test[i];
UP(me); /* end critical section */
DOWN(s[i]) /* Eat if enabled */
}
Once a philosopher finishes eating, all that remains is to relinquish the resources---its two
chopsticks---and thereby release waiting neighbours.
void drop_chopsticks(int i)
{
DOWN(me); /* critical section */
test(i-1); /* Let phil. on left eat if possible */
test(i+1); /* Let phil. on rght eat if possible */
UP(me); /* up critical section */
}
INPUT:
Valid input:
No of philosopher - 5
No. of chopstick - 5
Valid output:
Invalid input:
No of philosopher -6
No. of chopstick -5
Invalid output:
VIVA QUESTION:
1. What is starvation
2. What do you mean by process synchronization.
3. What is critical section? What are the requirements to its solution.
4. What is semaphore? What are the types of it.
EXPERIMENT –7
AIM:
1. Write a program to illustrate IPC through pipe and fork system calls – Printing only
odd numbers.
2. Demonstrates a one-way pipe between two processes.
THEORY:
The system call provides an interface to the operating system services. System calls allow
user-level processes to request some services from the operating system which process itself
is not allowed to do.
User programs request the device, and when finished they release the device. Similar to files,
we can read, write, and reposition the device.
Information Management : Some system calls exist purely for transferring information
between the user program and the operating system. An example of this is time, or date.
The OS also keeps information about all its processes and provides system calls to report this
information.
Shared memory use certain system calls to create and gain access to create and gain access to
regions of memory owned by other processes. The two processes exchange information by
reading and writing in the shared data.
1.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
int main()
int pfd[2], i;
pid_t mypid;
if(pipe(pfd) < 0)
perror(“Pipe Error”);
if(!fork())
char data;
printf(“Enter a Number…\n”);
scanf(“%d”, &data);
mypid = getpid();
printf(“Child Exiting…\n”);
exit(0);
else
char data1;
printf(“%5d”, i);
sleep(2);
exit(0);
return(0);
2.
#include <stdio.h>
int main()
exit (ERR);
exit (ERR);
if ( pid_1 != 0 ) /* in parent */
exit (ERR);
exit (0);
VIVA QUESTION :
EXPERIMENT –8
AIM:
1. To write a C program to implement the CPU scheduling algorithm for FIRST COME
FIRST SERVE.
THEORY:
FCFS:
CPU scheduler will decide which process should be given the CPU for its execution.For this it
use different algorithm to choose among the process. one among that algorithm is fcfs algorithm.
In this algorithm the process which arrive first is given the cpu after finishing its request only it
will allow cpu to execute other process.
SJF:
This algorithm associates with each process the length of the process's next CPU burst.
When the CPU is available, it is assigned to the process that has the smallest next CPU burst.
If the next CPU bursts of two processes are the same, FCFS scheduling is used.
RR :
The round-robin (RR) scheduling algorithm is designed especially for time-sharing systems.
It is similar to FCFS scheduling . A small unit of time, called a time quantum or time slice, is
defined. A time quantum is generally from 10 to 100 milliseconds. The ready queue is treated
as a circular queue.
1 .ALGORITHM:
INPUT:
Valid input:
Valid output:
Invalid Input:
Invalid Output:
2 .ALGORITHM:
INPUT:
Valid input:
Valid output:
Invalid Input:
Invalid Output:
3.ALGORITHM:
INPUT:
Valid Input:
Valid output:
Invalid Input:
Invalid output:
VIVA QUESTION :
EXPERIMENT –9
AIM:
To simulate banker’s algorithm for deadlock avoidance
THEORY:
Deadlock :
A set of processes is deadlocked if each process in the set is waiting for an event that only another
process in the set can cause (including itself).
Deadlock Avoidance
Avoid actions that may lead to a deadlock. Think of it as a state machine moving from one state to
another as each instruction is executed.
Safe State
ALGORITHM:
1. Start the program.
8. If the new request comes then check that the system is in safety.
INPUT:
Valid Input:
612
211
002
resource vector:9 3 6
Valid output:
Invalid Input:
Invalid Output :
VIVA QUESTION
1. Consider two processes P1 and P2. Let each of them have exclusive access to resources R1
and R2. In very simple terms tell me any one scenario that could result in a deadlock?
2. What are the necessary conditions for deadlock?
3. How the circular wait condition can be prevented .
4. What is the drawback of banker’s algorithm?
5. Assuming the operating system detects the system is deadlocked, what can the operating
system do to recover from deadlock?
EXPERIMENT – 10
AIM:
1. First-in-first-out
2. Least recently used(LRU)
3. Optimal
THEORY:
In multiprogramming system using dynamic partitioning there will come a time when all of
the processes in the main memory are in a blocked state and there is insufficient memory. To
avoid wasting processor time waiting for an active process to become unblocked. The OS
will swap one of the process out of the main memory to make room for a new process or for a
process in ReadySuspend state. Therefore,the OS must choose which pocess to replace.
Thus, when a page fault occurs, the OS has to change a page to remove from memory to
make room for the page that must be brought in. If the page to be removed has been modified
while in memory it must be written to disk to bring the disk copy up to date.
Replacement algorithms can affect the system's performance.
First-In-First_Out
Replace the page that has been in memory longest, is the policy applied by FIFO.
Pages from
memory are removed in round-robin fashion. Its advantage is it's simplicity.
This paging algorithm selects a page for replacement that has been unused for the
longest time.
The idea is to replace the page that will not be referenced for the longest period of
time.
1 . ALGORITHM:
Step 2: when the page is required replace the page at the head of the queue
Step 3: now the new page is inserted at the tail of the queue
INPUT:
Valid Input
564123
Valid output :
Invalid Input:
564123
Invalid Output:
2 . ALGORITHM:
Step 2: When the page is required replace the page at the head of the queue
Step 3: Now the new page is inserted at the tail of the queue
Step 5: When the page fault occurs replace page present at the bottom of the stack
INPUT:
Valid Input
654231
Valid Output:
Invalid Input :
654231
Invalid Output:
3. ALGORITHM:
1. Start Program
2. Read Number Of Pages And Frames
3. Read Each Page Value
4. Search For Page In The Frames
5. If Not Available Allocate Free Frame
6. If No Frames Is Free Repalce The Page With The Page That Is Not Used In Next N
Pages(N Is Number Of Frames)
7. Print Page Number Of Page Faults
8. Stop process.
INPUT
Valid Input
654231
Valid Output:
Invalid Input:
6 5 4 -2 3 1
Invalid Output:
VIVA QUESTION:
EXPERIMENT-1
AIM:
1. To implement and simulate the MFT algorithm.
2. To write a program to simulate the MVT algorithm
THEORY: In this the memory is divided in to parts and process is fit into it. The process
which is best suited in to it is placed in the particular memory where it suits. We have to
check memory partition. If it suits, its status should be changed.
MFT -
Partition main memory into a set of non-overlapping memory regions called partitions.
Fixed partitions can be of equal or unequal sizes.Leftover space in partition, after program
assignment, is called internal fragmentation.
Main memory use is inefficient. Any program, no matter how small, occupies an entire
partition. This can cause internal fragmentation. Unequal-size partitions lessens these
problems but they still remain ... Equal-size partitions was used in early IBM’s OS/MFT
(Multiprogramming with a Fixed number of Tasks).
MVT -
Variable-partition sizes for efficiency (sized to a given process’ needs).Hole – block of
available memory; holes of various size are scattered throughout memory. When a process
arrives, it is allocated memory from a hole large enough to accommodate it. Process exiting
frees its partition, adjacent free partitions combined.
1.ALGORITHM:
2 .ALGORITHM:
Partition size=ms/n.
Step6: Read the process no and process size.
Step 7: If proceaa size is less than partition size allot alse blocke the process.
While allocating update memory wastage-external fragmentation.
if(pn[i]==pn[j])
f=1;
if(f==0){
if(ps[i]<=size)
{
extft=extft+size-ps[i];
avail[i]=1;
count++;
}
}
Step 8: Print the results
Step 9 :Stop the process.
EXPERIMENT-2
AIM:
THEORY:
Paging is a memory management scheme which permits the physical address space of a
process to be non contiguous.In this scheme physical memory is broken into fixed sized
blocks called FRAMES . The logical memory is broken into blocks of same size called
PAGES.When a process is to be executed, its pages are loaded into any available memory
frames from the backing store.
The size of a page is power of 2 . The selection of power of 2 as the page size makes the
translation of logical address into a page number and page offset easy.The size of a page is 2
lies between 512 bytes and 16mb per page depending on the computer architecture.
When we use the paging scheme we have no external fragmentation.
ALGORITHM: