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

Operating System Lab Manual

Uploaded by

Talha Ch
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Operating System Lab Manual

Uploaded by

Talha Ch
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

BIIT

Series

Lab Manual
Operating
System Concepts
A simplified practical work book of Operating System Concepts course for
Computer Science, Information Technology and Software Engineering
students

Student Name: ______________________________________

Registration No: ___________________________________

Section / Semester: _________________________________

Submission Date: _____________________________________

Student Signature: __________________________________

Marks Obtained: _______________________________________

Maximum Marks: _____________________________________

Examiner Name/Sig: ___________________________________

Shahid Abid
2 Lab Manual: Operating Systems Concepts

PREFACE
This lab manual has been prepared to facilitate the students of computer science in studying,
analyzing and simulating various functions of operating system concepts. The students will have to
work with CLI and GUI of various OS, study how to monitor OS, create process and simulate
several algorithms using high level/visual programming language. The lab sessions are designed to
improve the abilities of the students by giving hands on experience. After completing the laboratory
exercises, the students will be familiar with the practical aspects of the various concepts explained in
the course, as well as with a simple OS development.

PREPARED BY
Lab manual is prepared by Mr. Shahid Abid under the supervision of the Director BIIT, Dr. Jamil
Sawar.

GENERAL INSTRUCTIONS
a. Students are required to maintain the lab manual with them till the end of the semester.
b. All readings, answers to questions and illustrations must be solved on the place provided. If more
space is required then additional sheets may be attached. You may add screen shots to the report
by using the ‘Print Screen’ command on your keyboard to get a snapshot of the output.
c. It is the responsibility of the student to have the lab manual graded as soon as he/she has
completed a task.
d. Loss of manual will result in resubmission of the complete manual.
e. Students are required to go through the experiment before attending a lab session.
f. Students must bring the manual during lab session.
g. Keep the manual neat, clean and presentable.
h. Plagiarism is strictly forbidden. No credit will be given if a lab session is plagiarised and no
resubmission will be entertained.
i. Marks will be deducted for late submission.
j. You need to submit the report even if you have demonstrated the exercises to the lab instructor or
shown them the lab report during the lab session.

VERSION HISTORY
Date Updated by Details
September Mr. Shahid Abid Version 1.0. Initial draft prepared and experiments
2019 outlined.

2
3 Lab Manual: Operating Systems Concepts

MARKS

Max. Marks
Lab# Lab Title Sign
Marks Obtained

Introduction to OS – CLI VS GUI


1 (EXAMPLE OS: MS WINDOWS: MS DOS VS MS 10
WINDOWS)
10
Introduction to OS – CLI vs GUI
2 (example OS: Unix/Linux: Shell vs X window
system)
10
3 System Monitoring
10
4 Processes – fork() system call
10
5 Processes – [ fork() + exec()] system calls
10
6 FCFS Scheduling Algorithm
10
7 SJF Non-Preemptive Scheduling Algorithm
10
8 SJF Preemptive Scheduling Algorithm
10
9 Round Robin Scheduling Algorithm
10
10 Priority Non-preemptive Scheduling Algorithm
10
11 Priority Preemptive Scheduling Algorithm
10
12 MVT (Multiprogramming Variable Task)
10
13 MFT (Multiprogramming Fixed Task)
10
14 Banker’s Algorithm for Dead Lock Avoidance
10
15 Banker’s Algorithm for Dead Lock Prevention
10
16 FIFO (First In First Out) Page Replacement
10
17 LRU (Least Recent Used) Page Replacement
10
18 LFU (Least Frequently Used) Page Replacement
10
19 Paging Technique of Memory Management

Grand Total 190

3
4 Lab Manual: Operating Systems Concepts

LAB#1 - Introduction to OS – CLI vs GUI


(example OS: MS Windows: MS DOS vs MS Windows)

Objectives
• Introduction to CLI commands and GUI commands/elements.
• Write a simple C++ program, compile and execute the program.
Time Required : 1.5 hrs
Programming Language : C++
Software Required : Turbo C++ in DOSBox, VC++
Hardware Required :
 Computer with administrative rights

Structure of the lab

A brief introduction to MS Windows command line interpreter (CLI) and graphical user
interface (GUI) will be shown to students.

MS Windows CLI - MS DOS


Stands for disk operation system. It is single user OS.

DOS Files:
There are three types of DOS files i.e. BAT, COM or EXE. These files contains DOS
commands/programs.

DOS Commands:
There are two types of DOS commands
1. Internal commands
2. External commands

DOS Internal Commands:


These commands are stored in COMMAND.COM. These commands are loaded into
RAM automatically during boot up process. These are simpler commands, which are
needed on regular basis.
Examples:
Some examples of DOS Internal commands are as follow.
1. COPY Command:
Purpose: Copies one or more files to another location.
Syntax: COPY <source> <target>
COPY [Filename][source][destination][directory]
• Suppose you want to copy Letter.doc from C drive to D drive then you will do
COPY C:\Letter.doc D:
• If you want to copy all the files from C whose extension is ‘doc’ to directory whose
name is ‘work’ on D then
COPY C:\*.DOC D:\ WORK
• If you want to copy all files from C to D whose extension is ‘doc’.
COPY C:\*.doc D:\document
4
5 Lab Manual: Operating Systems Concepts

2. DELETE Command:
Purpose: Delete or erase one or more specified files from the disk.
Syntax: DEL <Filename.ext>
DEL [drive][path] filename [/p]
• If you want to delete all backup files from current drive then
DEL *.bak
• If you want to delete all the files form current location then
DEL *.*

3. DIR Command:
Purpose: Display a list of current directory files and subdirectories.
Syntax:
DIR [drive:] [path] [filename] [/p] [/w]

[/p] will display page wise.


[/w] only display name of files/directories.
[/a] hidden and system files.
[/s] All the files including files in subdirectories.

4. Practice of cd, mkdir, rd for directory/folder.

MS Windows - GUI

Introduction to Windows building blocks

Detailed introduction of Task Manager.


Processes, Performance, App History, Startup, Users, Details and Services.

Processes

5
6 Lab Manual: Operating Systems Concepts

Performance

It contains a lot of information about CPU, Memory, Disk, Network, Virtual Memory, Cache,
CPU cores, Threads, Handles etc.

CPU

It contains information about CPU speed, Cache, CPU cores, Threads, Handles etc.

Information about Interrupt Request IRQ)

6
7 Lab Manual: Operating Systems Concepts

7
8 Lab Manual: Operating Systems Concepts

LAB#2 - Introduction to OS – CLI vs GUI


(example OS: Unix/Linux: Shell vs X Windows System)

Objectives
 Introduction to CLI commands and GUI commands/elements.
 Write, compile, and execute a simple C++ program in Linux environment using gcc.
Time Required : 1.5 hrs
Programming Language : C++
Software Required : Linux/Ubuntu in VM, gcc compiler
Hardware Required :
 Computer with administrative rights
Structure of the lab

A brief introduction to Unix/Linux command line interpreter (CLI) and graphical user
interface (GUI) will be given to students.

Introduction
 Fedora is available to you as virtual machine. Fedora is an open-source
Linux-based operating system alternative to Windows. We will learn the
basic desktop environment and common shell commands. Please login
using the credentials provided by the instructor.

 Play with the fedora desktop environment.

Linux Basics

Linux System
Linux System can be split into two parts:
 CLI (Shell)
 GUI (X-Windows Server with Gnome, KDE etc. window manager)
We will work in Kernel / User modes using root / test users.
Formally, a Shell is interface between a user and a Linux operating system, i.e.
user interacts with the Linux operating system through the shell.

Kernel is the core of Linux Operating System, which is operational as long as the
computer system is running. The kernel is part of the Linux Operating system which
consists of routines which interact with underlying hardware, and routines which
include system calls handling, process management, scheduling, signals, the file
system, and I/O to storage devices.

Linux File System Hierarchy


Unlike DOS, which permits you to organize your folders (directories) and files anyway you
please, the Linux file system is organized into a standard directory structure. A portion of
the Linux directory structure is pictured below:

root@ubuntu:/home/sha# cd /
root@ubuntu:/# ls
8
9 Lab Manual: Operating Systems Concepts

bin dev initrd.img lib64 mnt root srv usr vmlinuz.old


boot etc initrd.img.old lost+found opt run sys var
cdrom home lib media proc sbin tmp vmlinuz

/home Users’ home directory


/etc All system administrator commands, configuration files, and
installation control files.
/bin The core set of system commands and programs. Most systems
cannot boot (initially start) without executing some of the commands in
this directory.
/dev The device files used to access system peripherals (for example, your
terminal can be accessed from /dev/tty).
/lib The standard set of programming libraries required by Linux programs.
/tmp Temporary files created and used by many Linux programs.
/var Log files, spool files etc.
/root The root user’s home directory.
/usr/bin Common commands and programs.
/usr/doc Documentation
/usr/games Games
/usr/include Header files
/usr/info Online documentation
/usr/man Manual pages (help)
/usr/share Shared information

Basic Commands
In this section, we learn some basic Linux commands e.g., ls, cd, mkdir etc.
Directory Commands
Command Description
ls List the file in the directory, just like dir command in DOS.

Options

-a Display all the files, and subdirectories, including hidden files.


-l Display detailed information about each file, and directory.
-r Display files in the reverse order.

Command Description
mkdir directory-name Creates a new directory.
Directory-name specifies the name of the new
directory. If the name doesn’t begin with a slash,
the new directory is created as a subdirectory of
the current working directory. If the name begins
with a slash, the name defines the path from the
9
10 Lab Manual: Operating Systems Concepts

root directory to the new directory.

$cd /
Try to use the following command first because this will
bring you back to your home directory
$ cd

mkdir books

This command will create a new directory under the home directory.

How would you go to the directory books?


Command Description
cd Change to another directory.

For Example:

$cd dir-name
To change to any sub-directory under the current directory.

$cd books
(When Enter is pressed, the prompt becomes)

/books$
Do you see any difference between the two prompts?
Now you are in books directory, a step down to home. How could you go up?

$ cd .. (there’s space between cd and ..) Now you will again be in your parent directory. And
the prompt becomes: $

4. C Program in Linux Environment


In this section we write, compile, and execute a Hello Word program in Linux
environment.
Step 1: Create a director; mkdir lab1
Step 2: Switch to director; cd lab1
Step 3: Create a file; touch Hello.c
Step 4: Open the file; gedit Hello.c
Step 5: Type the following source code:
#include<stdio.h>
main()
{
printf("Hello World");
}
10
11 Lab Manual: Operating Systems Concepts

Step 6: Compile; gcc –o Outputhello Hello.c


step 7: Execute; ./Outputhello

In-Lab Exercises
1. Suppose you need to list the contents of a directory in long listing format. What
parameters should you use with ls to perform this task? Hint: remember that
the man command gives you an online reference manual for any Linux
command.

2. Create the following directory structure:

3. Write a program that odd numbers from 1 to 10 and print their sum, Compile and run
it using gcc.

4. Learn the usage of find command. Hint: remember that the man command
gives you an on line reference manual for any Linux command and also you
can get help from the Internet.
Important note: Don't copy paste exact information .write in your own word
after understanding.
Important: The lab instructor will grade you at the end of the lab.

Submission: (email & Hardcopy) A word document containing:


 Filename that includes your Section, ARID#, Name, Lab#, Date (e.g. BSIT3A-1252-
Ali Ahsan-2-9/10/19).
 Screen Shot for each question (Note: If there is need of more screen shots in any
task then add all of them in your document).

11
12 Lab Manual: Operating Systems Concepts

LAB#3 - System Monitoring


Objectives
• Introduction to system monitoring.
• Write, compile, and execute C++ program in Linux environment using gcc.
Time Required : 1.5 hrs
Programming Language : C++
Software Required : Linux/Ubuntu in VM, gcc compiler
Hardware Required :
 Computer with administrative rights
Structure of the lab

A brief introduction to Unix/Linux command to monitor system.

System Monitoring
In this section, we learn about basic tools (CLI and GUI) to monitor system resources.
1. To identify the available CPU, memory, and disk resources, we can used the following
commands:
• cat /proc/cpuinfo (read the CPU information)
• cat /proc/meminfo (read the memory (RAM) information)
• df -h ( find out secondary storage (hard-disk) information)
Make sure you are able to identify the total RAM size, disk space, and CPU resource
available.
2. top is a command line program provides a real-time view of the processes running in
the system. It provides system summary and also the list of tasks managing by Linux
kernel. The program is useful to identify the processes running with CPU and memory
utilization. Lets play with the top program: provide
• Launch a terminal and execute top command.
• You can press q to exit from top program.

3. Let’s see a GUI tool to monitor system resources. Type “gnome-system-monitor”. It


is similar to Task Manager (Windows)

C Programs and System Calls


strace is a tool that helps to run specified command and traces its interaction with
operating system. We can run any program using strace and identify the system calls it
makes. Let us practice strace tools:
1. Launch a terminal and run strace ls.
2. Try to read the output generated by the program and identify the system calls.
3. Now create a \Hello World" program in C language. Compile it and run it through
strace. Make sure to identify system call against printf function.
4. Now create a new program in C language, let’s call it \File Reader". Create a newly

12
13 Lab Manual: Operating Systems Concepts

named filereader.c and type in the following code:

/*
The code is taken from http://www.daniweb.com/software-
development/c/code/216411/reading-a-file-line-by-line */

#include <stdio.h>
int main ( void )
{
static const char filename[] = "file.txt"; FILE
*file = fopen ( filename, "r" );
if ( file != NULL )
{
char line [ 128 ]; /* or other suitable maximum line size */

while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */


{
fputs ( line, stdout ); /* write the line */
}
fclose ( file );
}
else
{
perror ( filename ); /* why didn't the file open? */
}
return 0;
}

5. Compile and execute the program.


6. Now run the program through strace and identify system calls against C functions.
7. Now read the file using cat command through strace and identify system calls.
8. Do you see any difference in system calls using \File Reader" and cat command?

Simple Batch/Shell Script


In Linux we have a command interpreter known as shell. In this section, we practice to write
a very simple shell script. The objective is to write set of commands in a file and run the file
to understand the batch execution interface.
1. Create a File named hello.sh.
2. Type in the following code:
#!/bin/sh
echo "Hello! Lets Execute ls."
ls

3. Now type sh hello.sh and press enter.


4. Did you understand what happened?

13
14 Lab Manual: Operating Systems Concepts

In-Lab Exercises
• Create a simple shell script to print "Hello Word!" and a C program to print "Hello Word!".
You need to profile the execution time and system calls used by both programs. Hint! time
command may help to identify the program execution time.
• Write a simple shell script to backup a file. Your program should be able to remove the
original file and print appropriate messages.
• Write a report in your own words after reading the article about interpreting the ‘top’
command output. Write briefly.

14
15 Lab Manual: Operating Systems Concepts

LAB#4 - Processes – fork() system call


Objectives
• Introduction to processes, process creation, child process creation.
• Write, compile, and execute a simple C++ program in Linux environment using gcc.
Time Required : 1.5 hrs
Programming Language : C++
Software Required : Linux/Ubuntu in VM, gcc compiler
Hardware Required :
 Computer with administrative rights
Structure of the lab

A brief introduction to Unix/Linux command line interpreter (CLI) and graphical user
interface (GUI) will be given to students.

Process Creation
A process is a program in execution. The process which creates another process is called
parent process. The process which is created is called child process. We can identify
process by their unique key called process identifier or pid (integer number). In Linux we
can use fork() system call to create processes. By this system call new process is created
containing copy of parent process. Both process (parent and child) continue executing
instructions after fork(). The return number of fork() for new (child) process will be 0 (zero),
whereas for parent process value will be nonzero positive process identifier. If fork() fails, it
return a negative number. In this section, we create a simple program using fork() to create
child process using C language.
Create a new file named fork example.c and type in the following code:

#include<stdio.h>
#include<unistd.h>
void main()
{
pid_t pid;
pid = fork(); /* fork a child process */
if( pid <0 ) /* error occurred */
{
printf("Fork Failed");
}

else if (pid == 0) /* child process */


{
printf( Child Process %d \n, pid);
}
else if (pid > 0) /* parent process */
{
printf(Parent Process %d \n, pid);
}
15
16 Lab Manual: Operating Systems Concepts

1. Compile and execute the program.


2. Try to understand the program
3. Now run the program through strace and identify system calls against C functions.

Lab Task:

Create a small program which prints factorial of a number.


Program should accept command line argument as an input. According to argument your
program should print factorial of number provided by command line argument.

For Example: ./output 5

It should print 120


The parent process creates a child and child is only responsible to print the factorial.

16
17 Lab Manual: Operating Systems Concepts

LAB#5 - PROCESSES – [fork() + exec()] system calls


Objectives
• Introduction to processes, process creation, child process creation.
• Write, compile, and execute a simple C++ program in Linux environment using gcc.
Time Required : 1.5 hrs
Programming Language : C++
Software Required : Linux/Ubuntu in VM, gcc compiler
Hardware Required :
 Computer with administrative rights

Structure of the lab

A brief introduction to Unix/Linux command line interpreter (CLI) and graphical user
interface (GUI) will be given to students.

Spawning a new program with fork + exec

The fork system call creates a new process. The execve system call overwrites a process
with a new program. Like peanut butter and chocolate in the ever-delicious Reese's Peanut
Butter Cups, these two system calls go together to spawn a new running program. A
process forks itself and the child process execs a new program, which overlays the one in
the current process.

Because the child process is initially running the same code that the parent was and has
the same open files and the same data in memory, this scheme provides a way for the child
to tweak the environment, if necessary, before calling the execve system call. A common
thing to do is for the child to change its standard input or standard output (file descriptors 0
and 1, respectively) and then exec the new program. That program will then read from and
write to the new sources.

Example

This is a program that forks itself and has the child exec the ls program, running the "ls -aF
/" command. Five seconds later, the parent prints a message saying, I'm still here!. We use
the sleep library function to put the process to sleep for five seconds.

/* forkexec: create a new process. */ /* The child runs "ls -aF /". The parent wakes up after 5
seconds */ /* Paul Krzyzanowski */ #include <stdlib.h> /* needed to define exit() */ #include
<unistd.h> /* needed for fork() and getpid() */ #include <stdio.h> /* needed for printf() */ int
main(int argc, char **argv) { void runit(void); int pid; /* process ID */ switch (pid = fork()) {
case 0: /* a fork returns 0 to the child */ runit(); break; default: /* a fork returns a pid to the
parent */ sleep(5); /* sleep for 5 seconds */ printf("I'm still here!\n"); break; case -1: /*
something went wrong */ perror("fork"); exit(1); } exit(0); } void runit(void) { printf("About to
run ls\n"); execlp("ls", "ls", "-aF", "/", (char*)0); perror("execlp"); /* if we get here, execlp
failed */ exit(1); }

Save this file as forkexec.c


17
18 Lab Manual: Operating Systems Concepts

/* forkexec: create a new process. */


/* The child runs "ls -aF /". The parent wakes up after 5 seconds */
/* Paul Krzyzanowski */

#include <stdlib.h> /* needed to define exit() */


#include <unistd.h> /* needed for fork() and getpid() */
#include <stdio.h> /* needed for printf() */

int
main(int argc, char **argv) {
void runit(void);
int pid; /* process ID */

switch (pid = fork()) {


case 0: /* a fork returns 0 to the child */
runit();
break;

default: /* a fork returns a pid to the parent */


sleep(5); /* sleep for 5 seconds */
printf("I'm still here!\n");
break;

case -1: /* something went wrong */


perror("fork");
exit(1);
}
exit(0);
}

void
runit(void) {
printf("About to run ls\n");
execlp("ls", "ls", "-aF", "/", (char*)0);
perror("execlp"); /* if we get here, execlp failed */
exit(1);
}

Compile this program via:

gcc -o forkexec forkexec.c

Run the program:

./forkexec

18
19 Lab Manual: Operating Systems Concepts

LAB#6 - First Come First Serve (FCFS)


It is the simplest CPU scheduling algorithm. According to this scheme, a first process that
request to CPU first is allocated the CPU first based on the rule “first come first serve”. The
implementation of FCFS policy is easily managed by FIFO queue. When a process enters into
the ready queue, its PCB is linked at the end of the queue.
Objectives
Write a C++ program to implement FCFS scheduling algorithm?

ALGORITHM:

1. Start.
2. Declare the array size.
3. Read the number of processes to be inserted.
4. Read the Burst times of processes,
5. Sort the array according to the arrival time of process in ascending
order.
6. Calculate the waiting time of each process,
Waiting time [i+1] = Burst time[i] + Waiting time [i]
7. Calculate the turnaround time of each process,
Turnaround time [i+1] = Turnaround time [i] + Burst time [i+1]
8. Calculate the average waiting time and average turnaround time.
9. Display the values
10. Stop.
PROGRAM:
#include<iostream>
using namespace std;
int main()
{
` char pn[10][10];
int arr[10], bur[10], star[10], finish[10], tat[10], wt[10], i, n;
int totwt=0, tottat=0;

cout<<"Enter the number of processes:";


cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the Process Name, Arrival Time & Burst Time:";
cin>>pn[i]>>arr[i]>>bur[i];
}
for(i=0;i<n;i++)
{
if(i==0)
{
star[i]=arr[i];
wt[i]=star[i]-arr[i];
finish[i]=star[i]+bur[i];
tat[i]=finish[i]-arr[i];

19
20 Lab Manual: Operating Systems Concepts

}
else
{
star[i]=finish[i-1];
wt[i]=star[i]-arr[i];
finish[i]=star[i]+bur[i];
tat[i]=finish[i]-arr[i];
}
}
cout<<"\nPNameArrtimeBurtime Start TAT Finish";
for(i=0;i<n;i++)
{
cout<<pn[i]<<arr[i]<<bur[i]<<star[i]<<tat[i]<<finish[i]);
totwt+=wt[i];
tottat+=tat[i];
}
cout"\nAverage Waiting time”<<totwt/n;
cout"\nAverage Turn Around Time:"<<tottat/n);
system(“pause”);
}

Teacher Comments /Signature:

20
21 Lab Manual: Operating Systems Concepts

LAB#7 - Shortest Job First Non-Preemptive


Associate with each process the length of its next CPU burst. Use lengths to
schedule the process with the shortest time. Non-preemptive once CPU given to the
process it cannot be preempted until completes its CPU burst.
Objectives
Write a c++ program to implement shortest job first non-preemptive scheduling algorithm.

Algorithm:
1. Start.
2. Declare the array size.
3. Read the number of processes to be inserted .
4. Read the Burst times of processes.
5. Sort the Burst times in ascending order and process with shortest burst
time is first executed. And also sort the process according to arrival time
of that process.
6. Calculate the waiting time of each process,
Wt[i+1]= bt[i]+wt[i]
7. Calculate the turnaround time of each process,
tt[i+1]=tt[i]+bt[i+1]\
8. Calculate the average waiting time and average turnaround time.
9. Display the values.
10. Stop.

PROGRAM:-
#include<iostream>
Int main()
{
Int I, j, burstt[10], arrivalt[10], t, n, wt[10], tt[10], w1=0, t1=0;
Float awt, atat;

cout<<"enter no. of processes:\n";


cin>>n;
cout<<"enter the burst time of processes:\nEnter the arrival time:\n";

for(i=0;i<n;i++)
{
Cin>>burst[i];
Cin>>arrivalt[i];
}

for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
if(arrivalt[i]>arrivalt[j])
{
if(burstt[i]>burstt[j])
{

21
22 Lab Manual: Operating Systems Concepts

t=burstt[i];
burstt[i]=burstt[j];
burstt[j]=t;
t=arrivalt[i];
arrivalt[i]=arrivalt[j];
arrivalt[j]=t;
}
}
}

for(i=0;i<n;i++)
{
wt[0]=0;
tt[0]=burstt[0];
wt[i+1]=burstt[i]+wt[i];
tt[i+1]=tt[i]+burstt[i+1];
w1=w1+wt[i];
t1=t1+tt[i];
}

aw=w1/n;
at=t1/n;
cout<<"\nbursttime\t waiting time\t turnaround time\n";

for(i=0;i<n;i++)
{
cout<<burstt[i]<<”\t”<<wt[i]<<”\t”<<tt[i]);
}

cout<<”average waiting=”<<awt<<endl<<”Average turn around time=”<<atat<<endl;

system(“pause”);
}

Teacher Comments /Signature:

22
23 Lab Manual: Operating Systems Concepts

LAB#8 - Shortest Job First Preemptive


Associate with each process the length of its next CPU burst. Use lengths to schedule the
process with the shortest time. Preemptive if a new process arrives with CPU burst length
less than remaining time of current executing process, preempt. This scheme is known as
the Shortest-Remaining-Time-First (SRTF).
Objectives
Write a c++ program to implement shortest job first preemptive?
Algorithm:
1. Start
2. Declare the array size
3. Read the number of processes to be inserted
4. Read the Burst times of processes
5. Sort the Burst times in ascending order and process with shortest burst time
is first executed. And also sort the process according to arrival time of that
process.
6. Calculate the waiting time of each process
Wt[i+1]=bt[i]+wt[i]
7. Calculate the turnaround time of each process
tt[i+1]=tt[i]+bt[i+1]
8. Calculate the average waiting time and average turnaround time.
9. Display the values
10. Stop

PROGRAM:-
#include<iostream.h>
#include<stdio.h>
int main()
{
int n=3;
float total, wait[3]={0};
float p[3], twaiting=0, waiting=0;
int proc;
int stack[3];
float brust[3], arrival[3], sbrust,temp[3], top=3;
for(int i=0;i<n;i++)
{
p[i]=i;
stack[i]=i;
cout<<"enter arival time :";
cin>>arrival[i];
cout<<endl<<"enter brust time:";
cin>>brust[i];
temp[i]=arrival[i];
sbrust=brust[i]+sbrust;
}
for(i=0;i<sbrust;i++)

23
24 Lab Manual: Operating Systems Concepts

{
proc=stack[0];
if(temp[proc]==i)
twaiting=0;
else
twaiting=i-(temp[proc]);

temp[proc]=i+1;
wait[proc]=wait[proc]+twaiting;
waiting=waiting+(twaiting);
brust[proc]=brust[proc]-1;
if(brust[proc]==0)
{
for(int x=0;x<top-1;x++)
stack[x]=stack[x+1];
top=top-1;
}
for(int z=0;z<top-1;z++)
{
if((brust[stack[0]]>brust[stack[z+1]]) && (arrival[stack[z+1]] <= i+1))
{
int t=stack[0];
stack[0]=stack[z+1];
stack[z+1]=t;
}
}
}
cout<<"waiting:"<<waiting;
return 0;
}

Teacher Comments /Signature:

24
25 Lab Manual: Operating Systems Concepts

LAB#9 - Round Robin Scheduling Algorithm

To schedule processes fairly, a round-robin scheduler generally employs time sharing,


giving each job a time slot or quantum (its allowance of CPU time), and interrupting the job
if it is not completed by then. The job is resumed next time a time slot is assigned to that
process. If the process terminates or changes its state to waiting during its attributed time
quantum, the scheduler selects the first process in the ready queue to execute. In the
absence of time-sharing, or if the quanta were large relative to the sizes of the jobs, a
process that produced large jobs would be favored over other processes.

Objective:-
Write a c++ program to implements the round robin scheduling algorithm?

Algorithm:
1. Start
2. Declare the array size
3. Read the number of processes to be inserted
4. Read the burst times of the processes
5. Read the Time Quantum
6. If the burst time of a process is greater than time Quantum then subtract time
quantum form the burst time, Else assign the burst time to time quantum.
7. Calculate the average waiting time and turn around time of the processes.
8. Display the values
9. Stop

PROGRAM:-
#include<iostream.h>
#include<stdio.h>
#include<fstream.h>
int main()
{
int n=3;
float total, wait[3]={0};
float p[3], twaiting=0, waiting=0;
int proc;
int stack[3];
float brust[3], arrival[3], sbrust, temp[3], top=3;
for(int j=0;j<n;j++)
{
p[j]=j;
stack[j]=j;
cout<<"enter arival time :";
cin>>arrival[j];
cout<<endl<<"enter brust time:";

25
26 Lab Manual: Operating Systems Concepts

cin>>brust[j];
temp[j]=arrival[j];
sbrust=brust[j]+sbrust;
}
int cont;
cout<<"enter contum time:";
cin>>cont;
int i=0;
while(1)
{
for(int m=0;m<cont;m++)
{
if(i==sbrust)
{
break;
}
proc=stack[0];
cout<<endl<<proc;
if(temp[proc]==i)
twaiting=0;
else
{
twaiting=i-(temp[proc]);
}
temp[proc]=i+1;
wait[proc]=wait[proc]+twaiting;
waiting=waiting+(twaiting);
brust[proc]=brust[proc]-1;

if(brust[proc]==0)
{
for(int x=0;x<top-1;x++)
{
stack[x]=stack[x+1];
}
top=top-1;
m=-1;
}
i=i+1;
}
if(i==sbrust)
{
break;
}
int tp=stack[0];
for(int x=0;x<top-1;x++)
{
stack[x]=stack[x+1];

26
27 Lab Manual: Operating Systems Concepts

}
stack[top-1]=tp;
m=-1;
}
cout<<"waiting:"<<waiting;
return 0;
}

Teacher Comments /Signature:

27
28 Lab Manual: Operating Systems Concepts

LAB#10 - Priority Non-Preemptive Scheduling Algorithm


Priority scheduling is a method of scheduling processes based on priority. In this method,
the scheduler chooses the tasks to work as per the priority. Indefinite blocking, otherwise
called starvation, is one of the major issues concerning priority scheduling algorithms. It is a
state where a process is ready to be executed, but faces a long wait in getting assigned to
the CPU.
Objective:-
Write a program to implement priority non-preemptive scheduling algorithm?
Algorithm:
1. Start.
2. Declare the array size.
3. Read the number of processes to be inserted.
4. Read the Priorities of processes.
5. Sort the priorities, arrival time and Burst times in ascending order.
6. Calculate the waiting time of each process,
wt[i+1]=bt[i]+wt[i]
7. Calculate the turnaround time of each process,
tt[i+1]=tt[i]+bt[i+1]
8. Calculate the average waiting time and average turnaround time.
9. Display the values.
10. Stop.
PROGRAM:-
#include <iostream>
using namespace std;
intmain()
{
Int n;
cout<<"enter your toal no. of process";
cin>>n;
float total, wait[n];
float p[n], twaiting=0, waiting=0;
int proc;
int stack[n];
float brust[n], arrival[n], sbrust,temp[n], top=n, prority[n];
int i;
for(i=0;i<n;i++)
{
p[i]=i;
stack[i]=i;
cout<<"enter arival time :";
cin>>arrival[i];
cout<<endl<<"enter brust time:";
cin>>brust[i];
cout<<endl<<"enter prority time:";
cin>>prority[i];

temp[i]=arrival[i];

28
29 Lab Manual: Operating Systems Concepts

sbrust=brust[i]+sbrust;
}
for(i=0;i<sbrust;i++)
{ //section 1
proc=stack[0];

if(temp[proc]==i)
{
twaiting=0;
}
else
{
twaiting=i-(temp[proc]);
}

temp[proc]=i+1;
wait[proc]=wait[proc]+twaiting;
waiting=waiting+(twaiting);
brust[proc]=brust[proc]-1;

if(brust[proc]==0)
{
for(int x=0;x<top-1;x++)
{
stack[x]=stack[x+1];
}
top=top-1;
for(int z=0;z<top-1;z++)
{
if((prority[stack[0]]>prority[stack[z+1]]) && (arrival[stack[z+1]] <= i+1))
{
int t=stack[0];
stack[0]=stack[z+1];
stack[z+1]=t;
}
}
}
}

cout<<"Average waiting time is:"<<waiting/n;


float tu=(sbrust+waiting)/n;
cout<<endl<<"Average turnaround time is:"<<tu;
return 0;
}

Teacher Comments /Signature:

29
30 Lab Manual: Operating Systems Concepts

LAB#11 - Priority Preemptive Scheduling Algorithm


Priority Scheduling always selects the processes with the highest priority currently ready to
run. If there is more than one process having the currently highest priority, you need a
second scheduling algorithm to choose among these processes. Preemptive Priority
Scheduling is the same algorithm but if a new process having a higher priority than the
currently running process arrives, it gets selected immediately. The new process has not to
wait until the currently running process finishes or yields.
Objectives
Write a c++ program to implements priority preemptive scheduling algorithm?
Algorithm:
1. Start
2. Declare the array size
3. Read the number of processes to be inserted
4. Read the Priorities of processes
5. Sort the priorities, arrival time and Burst times in ascending order
6. Calculate the waiting time of each process
wt[i+1]=bt[i]+wt[i]
7. Calculate the turnaround time of each process
tt[i+1]=tt[i]+bt[i+1]
8. Calculate the average waiting time and average turnaround time.
9. Display the values
10. Stop
PROGRAM:-
#include <iostream>
using namespace std;
intmain()
{
int n;
cout<<"enter your toal no. of process";
cin>>n;
float total, wait[n];
float p[n], twaiting=0, waiting=0;
int proc;
int stack[n];
float brust[n], arrival[n], sbrust, temp[n], top=n, prority[n];
int i;
for(i=0;i<n;i++)
{
p[i]=i;
stack[i]=i;
cout<<"enter arival time :";
cin>>arrival[i];
cout<<endl<<"enter brust time:";
cin>>brust[i];
cout<<endl<<"enter prority time:";
cin>>prority[i];
temp[i]=arrival[i];

30
31 Lab Manual: Operating Systems Concepts

sbrust=brust[i]+sbrust;
}
for(i=0;i<sbrust;i++)
{ //section 1
proc=stack[0];

if(temp[proc]==i)
{
twaiting=0;
}
else
{
twaiting=i-(temp[proc]);
}

temp[proc]=i+1;
wait[proc]=wait[proc]+twaiting;
waiting=waiting+(twaiting);
brust[proc]=brust[proc]-1;

if(brust[proc]==0)
{
for(int x=0;x<top-1;x++)
{
stack[x]=stack[x+1];
}
top=top-1;
}
for(int z=0;z<top-1;z++)
{
if((prority[stack[0]]>prority[stack[z+1]]) && (arrival[stack[z+1]] <= i+1))
{
int t=stack[0];
stack[0]=stack[z+1];
stack[z+1]=t;
}
}
}
cout<<"Average waiting time is:"<<waiting/n;
float tu=(sbrust+waiting)/n;
cout<<endl<<"Average turnaround time is:"<<tu;
return 0;
}

Comments & Teacher Signature.

31
32 Lab Manual: Operating Systems Concepts

LAB#12 - MVT (Multiprogramming Variable Task)


MVT stands For Multiprogramming with Variable Number of Tasks. Multiprogramming is
a technique to execute number of programs simultaneously by a single processor. This is
one of the memory management techniques. To eliminate the same of the problems with
fixed partitions, an approach known as dynamic partitioning developed. In this technique,
partitions are created dynamically, so that each process is loaded into partition of exactly
the same size at that process. This scheme suffering from external fragmentation.

Objective:
Write a program to implement Dynamic allocation of memories in MVT.

Algorithm:
Step 1: Start the process.
Step 2: Declare variables.
Step 3: Enter total memory size.
Step 4: Allocate memory for OS.
Step 5: Allocate total memory to the pages.
Step 6: Display the wastage of memory.
Step 7: Stop the process.

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int m, i, p[15];
char ch;
clrscr();
printf("Enter memory to be allocated: ");
scanf("%d",&m);
printf("Enter process size : ");
scanf("%d", &p[0]);
i=0;
do
{
m=m-p[i];
printf("\nRemaining memory is %d\n",m);
abc:printf("Do you want to continue: ");
fflush(stdin);
scanf("%c",&ch);
i++;
if(ch=='y')
{
printf("Enter the process size: ");

32
33 Lab Manual: Operating Systems Concepts

scanf("%d",&p[i]);
}
else
{
printf("\nExternal fragmentation is %d",m);
break;
}
if(m<p[i])
{
printf("\nRequired memory is not available\n");
goto abc;
}
}while((ch=='y')&&(m>=p[i]));
getch();
}

Teacher Comments /Signature:

33
34 Lab Manual: Operating Systems Concepts

LAB#13 - MULTIPROGRAM FIXED TASK


MFT stands for Multiprogramming with Fixed Number of Tasks.
MFT is the one of the memory management technique. In this technique, main memory is
divided into no of static partitions at the system generated time. A process may be loaded
into a partition of equal or greater size. The partition sizes are depending on OS in this
memory management scheme the OS occupies the low memory, and the rest of the main
memory is available for user space. This scheme suffers from internal as well as external
fragmentation.

Objective:
Write a program to implement Dynamic allocation of memories in MVT.

Algorithm:
Step 1: Start the process.
Step 2: Declare variables.
Step 3: Enter total memory size.
Step 4: Allocate memory for operating system.
Step 5: Allocate total memory to the pages.
Step 6: Display the wastage of memory.
Step 7: Stop the process.

PROGRAM:

#include < stdio.h>


#include <conio.h>
void main()
{
int i, p, a[10], c[15], temp=0, total=0;
float b, t;
clrscr();
printf(“Enter the total memory ”);
scanf(“%f”,&t);
printf(“Enter the processes :”);
scanf(“%d”, &p);
b=t/p;
for(i=0;i<p;i++)
a[i]=b;
for(i=0;i<p;i++)
{
lable: printf(“Enter memory for %d process: ",i);
scanf(“%d”,&temp);
if(temp<=b)
{
c[i]=a[i]-temp;

34
35 Lab Manual: Operating Systems Concepts

printf(“Internal fragmentation for this block”);


printf(“%d”,c[i]);
}
else
{
printf(“Required memory is not available”);
goto lable;
}
total=total+c[i];
}
printf(“Total internal fragmentation %d\n”,total);
getch();
}

Teacher Comments /Signature:

35
36 Lab Manual: Operating Systems Concepts

LAB#14 - Banker’s Algorithm - Deadlock Avoidance


It is one of the method of dynamically escaping from the deadlocks. In this scheme, if
a process request for resources, the avoidance algorithm checks before the allocation of
resources about the state of system. If the state is safe, the system allocate the resources
to the requesting process otherwise (unsafe) do not allocate the resources. So taking care
before the allocation said to be deadlock avoidance.

Objective:
Write a program to implement Bankers Algorithm for Deadlock Avoidance.

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

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
Int alloc[10][10], max[10][10];
int avail[10], work[10], total[10];
int i, j, k, n, need[10][10];
int m;
int count=0,c=0;
char finish[10];
clrscr();
printf("Enter the no. of processes and resources:");
scanf("%d%d",&n,&m);
for(i=0;i<=n;i++)
finish[i]='n';
printf("Enter the claim matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&max[i][j]);
printf("Enter the allocation matrix:\n");

36
37 Lab Manual: Operating Systems Concepts

for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&alloc[i][j]);
printf("Resource vector:");
for(i=0;i<m;i++)
scanf("%d",&total[i]);
for(i=0;i<m;i++)
avail[i]=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
avail[j]+=alloc[i][j];
for(i=0;i<m;i++)
work[i]=avail[i];
for(j=0;j<m;j++)
work[j]=total[j]-work[j];
for(i=0;i<n;i++)
for(j=0;j<m;j++)
need[i][j]=max[i][j]-alloc[i][j];
A:for(i=0;i<n;i++)
{
c=0;
for(j=0;j<m;j++)
if((need[i][j]<=work[j])&&(finish[i]=='n'))
c++;
if(c==m)
{
printf("All the resources can be allocated to Process %d",i+1);
printf("\n\nAvailable resources are:");
for(k=0;k<m;k++)
{
work[k]+=alloc[i][k];
printf("%4d",work[k]);
}
printf("\n");
finish[i]='y';
printf("\nProcess %d executed?:%c \n",i+1,finish[i]);
count++;
}
}
if(count!=n)
goto A;
else
printf("\n System is in safe mode");
printf("\n The given state is safe state");
getch();
}

Teacher Comments /Signature:


37
38 Lab Manual: Operating Systems Concepts

LAB#15 - Banker’s Algorithm - Deadlock Prevention


Prevention for Banker’s Deadlock.

Objective:
Write a program to implement Bankers Algorithm for Deadlock Prevention.

PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
char job[10][10];
int time[10], avail,tem[10], temp[10];
int safe[10];
int ind=i,j,q,n,t;
clrscr();
printf("Enter no of jobs: ");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("Enter name and time: ");
scanf("%s%d",&job[i],&time[i]);
}

printf("Enter the available resources:");


scanf("%d",&avail);

for(i=0;i<n;i++)
{
temp[i]=time[i];
tem[i]=i;
}

for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(temp[i]>temp[j])
{
t=temp[i];
temp[i]=temp[j];
temp[j]=t;
t=tem[i];
tem[i]=tem[j];
tem[j]=t;
}
}

38
39 Lab Manual: Operating Systems Concepts

for(i=0;i<n;i++)
{
q=tem[i];
if(time[q]<=avail)
{
safe[ind]=tem[i];
avail=avail-tem[q];
//printf("%s",job[safe[ind]]);
ind++;
}
else
{
printf("No safe sequence\n");
}
}
printf("Safe sequence is:");

for(i=1;i<ind; i++)
{
printf(" %s %d\n",job[safe[i]],time[safe[i]]);
}
getch();
}

Teacher Comments /Signature:

39
40 Lab Manual: Operating Systems Concepts

LAB#16 - FIFO Page Replacement Algorithm


FIFO is the simplest page replacement algorithm, the idea behind this is, “Replace a
page that page is oldest page of main memory” or “Replace the page that has been in
memory longest”. FIFO focuses on the length of time a page has been in the memory rather
than how much the page is being used.

Objective:
Write a program to implement FIFO (First In First Out) page replacement algorithm.
Algorithm:
Step 1: Create a queue to hold all pages in memory.
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.
PROGRAM:
#include<stdio.h>
#include<conio.h>
int fr[3],m;
void display();
void main()
{
int i, j, page[20];
int flag1=0, flag2=0, pf=0;
int n, top=0;
float pr;
clrscr();
printf("Enter length of the reference string: ");
scanf("%d",&n);
printf("Enter the reference string: ");
for(i=0;i<n;i++)
scanf("%d",&page[i]);
printf("Enter no of frames: ");
scanf("%d",&m);
for(i=0;i<m;i++)
fr[i]=-1;
for(j=0;j<n;j++)
{
flag1=0;
flag2=0;
for(i=0;i<m;i++)
{
if(fr[i]==page[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)

40
41 Lab Manual: Operating Systems Concepts

{
for(i=0;i<m;i++)
{
if(fr[i]==-1)
{
fr[i]=page[i];
flag2=1;
break;
}
}
}
if(flag2==0)
{
fr[top]=page[j];
top++;
pf++;
if(top>=m)
top=0;
}
display();
}
pf+=m;
printf("Number of page faults : %d\n", pf);
pr=(float)pf/n*100;
printf("Page fault rate = %f \n", pr);
getch();
}
void display()
{
int i;
for(i=0;i<m;i++)
printf("%d\t", fr[i]);
printf("\n");
}

Teacher Comments /Signature:

41
42 Lab Manual: Operating Systems Concepts

LAB#17 - LRU Page Replacement Algorithm


LRU (Least Recently Used):
The criterion of this algorithm is “Replace a page that has been used for the longest
period of time”. This strategy is the page replacement algorithm looking backward in time,
rather than forward.

Objective:
Write a program to implement page replacement algorithm LRU.

Algorithm:
Step 1: Create a queue to hold all pages in memory.
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 4: Create a stack.
Step 5: When the page fault occurs replace page present at the bottom of the
stack.

PROGRAM:
#include<stdio.h>
#include<conio.h>
void display();
void main()
{
int i, j, page[20], fs[10], n, m;
int index, k, l, flag1=0, flag2=0, pf=0;
int fr[10];
float pr;
clrscr();
printf("Enter length of the reference string: ");
scanf("%d",&n);
printf("Enter the reference string: ");
for(i=0;i<n;i++)
scanf("%d",&page[i]);
printf("Enter no of frames: ");
scanf("%d",&m);
for(i=0;i<m;i++)
fr[i]=-1;
for(j=0;j<n;j++)
{
flag1=0;
flag2=0;
for(i=0;i<m;i++)
{
if(fr[i]==page[j])
{
flag1=1;
flag2=1;

42
43 Lab Manual: Operating Systems Concepts

break;
}
}
if(flag1==0)
{
for(i=0;i<m;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<m;i++)
fs[i]=0;
for(k=j-1,l=1;l<=m;l++,k--)
{
for(i=0;i<m;i++)
{
if(fr[i]==page[k])
fs[i]=1;
}
}
for(i=0;i<m;i++)
{
if(fs[i]==0)
index=i;
}
fr[index]=page[j];
pf++;
}
for(i=0;i<m;i++)
printf("%d\t", fr[i]);
printf("\n");
}
pf+=m;
printf("Number of page faults : %d\n", pf);
pr=(float)pf/n*100;
printf("Page fault rate = %f \n", pr);
getch();
}

Teacher Comments /Signature:

43
44 Lab Manual: Operating Systems Concepts

LAB#18 - Optimal (LFU) Page Replacement Algorithm


LFU (Least Frequently Used):
The least frequently used algorithm “select a page for replacement, if the page has
not been used for the often in the past” or “Replace page that page has smallest count” for
this algorithm each page maintains as counter which counter value shows the least count,
replace that page. The frequency counter is reset each time is page is loaded.

Objective:
Write a program to implement page replacement algorithms Optimal.

Algorithm:
Here we select the page that will not be used for the longest period of time.
Step 1: Create an array.
Step 2: When the page fault occurs replace page that will not be used for the longest
period of time.

PROGRAM:

#include<stdio.h>
#include<conio.h>
int fr[3], n, m;
void display();
void main()
{
int i, j, page[20], fs[10];
int max, found=0, lg[3], index, k, l, flag1=0, flag2=0, pf=0;
float pr;
clrscr();
printf("Enter length of the reference string: ");
scanf("%d",&n);
printf("Enter the reference string: ");
for(i=0;i<n;i++)
scanf("%d",&page[i]);
printf("Enter no of frames: ");
scanf("%d",&m);
for(i=0;i<m;i++)
fr[i]=-1;
pf=m;
for(j=0;j<n;j++)
{
flag1=0;
flag2=0;
for(i=0;i<m;i++)
{

44
45 Lab Manual: Operating Systems Concepts

if(fr[i]==page[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<m;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<m;i++)
lg[i]=0;
for(i=0;i<m;i++)
{
for(k=j+1;k<=n;k++)
{
if(fr[i]==page[k])
{
lg[i]=k-j;
break;
}
}
}
found=0;
for(i=0;i<m;i++)
{
if(lg[i]==0)
{
index=i;
found = 1;
break;
}
}
if(found==0)
{
max=lg[0];
index=0;
for(i=0;i<m;i++)
45
46 Lab Manual: Operating Systems Concepts

{
if(max<lg[i])
{
max=lg[i];
index=i;
}
}
}
fr[index]=page[j];
pf++;
}
display();
}
printf("Number of page faults : %d\n", pf);
pr=(float)pf/n*100;
printf("Page fault rate = %f \n", pr);
getch();
}
void display()
{
int i;
for(i=0;i<m;i++)
printf("%d\t",fr[i]);
printf("\n");
}

Teacher Comments /Signature:

46
47 Lab Manual: Operating Systems Concepts

LAB#19 - Paging Technique of Memory Management


In this scheme the operating system maintains a data structure that is page table. It
is used for mapping purpose. The page table specifies the some useful information it tells
which frames are there and so on. The page table consisting of two fields one is the page
number and other one is frame number. Every address generated by the CPU divided into
two parts one is page number and second is page offset or displacement. The pages are
loaded into available free frames in the physical memory.

Objective:
Write a program to implement the memory management policy-Paging.

Algorithm:
Step 1: Read all the necessary input from the keyboard.
Step 1: 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:

Teacher Comments /Signature:

47

You might also like