Operating Systems Module Fcit
Operating Systems Module Fcit
PROGRAMME BBMIT
LEVEL 2.2
MODULE OVERVIEW The study of operating systems is the study of how a set of computational
resources may be shared safely, efficiently, and effectively amongst many
computing users. This course introduces the major concepts of modern
operating systems and study of the interrelationships between the OS
and the architecture of computer systems. The Course gives a general
overview of an Operating System as a Monitor, Supervisor and Resource
Manager. Therefore, the course teaches the OS design, its usefulness in
resource scheduling and management.
MODULE AIM The aim of the module is to introduce the students to the concepts of
Operating Systems (OS) as a guide towards understanding their design
and implementation as well as their roles in resource management.
LEARNING OUTCOMES By the end of this course, you should be able to:
1. Explain the concept of an operating system and its importance
in a computer system;
2. Describe the architecture of an operating system, especially the
operating systems of LINUX and Microsoft Windows; and
3. Explain the key mechanisms of the operating system like
process management, memory management, files systems and
I/O management.
OBJECTIVES In line with the stated aim of this module, the objectives of this course
are to:
• Expose the students to the different types and components of
operating system.
1
• Introduce to the students Operating System as a resource
manager (process, processor, memory and I/O management).
• Expose the students to the different types scheduling algorithms
and policies.
• Expose the students to the different challenges of concurrent
and cooperation processes (such as Race condition, Deadlock
etc.) and their solutions
• Expose the students to the different debugging methods.
• Expose the students to the different memory management
schemes.
• Expose the students to the different file attributes, protection
and security mechanisms.
1.1. Introduction
Computer software can be divided into two main categories: application software and system
software. Application software consists of the programs for performing tasks particular to the
machine’s utilisation. This software is designed to solve a particular problem for users. Examples
of application software include spreadsheets, database systems, desktop publishing systems,
program development software and games.
On the other hand, system software is more transparent and less noticed by the typical
computer user. This software provides a general programming environment in which
programmers can create specific applications to suit their needs. This environment provides
new functions that are not available at the hardware level and performs tasks related to
executing the application program. System software acts as an interface between the hardware
of the computer and the application software that users need to run on the computer. The
most important type of system software is the operating system.
An Operating Systems (OS) is a collection of programs that acts as an interface between a user
of a computer and the computer hardware. The purpose of an operating system is to provide an
2
environment in which a user may execute the programs. Operating Systems are viewed as
resource managers. The main resource is the computer hardware in the form of processors,
storage, input/output devices, communication devices, and data. Some of the operating system
functions are implementing the user interface, sharing hardware among users, allowing users to
share data among themselves, preventing users from interfering with one another, scheduling
resources usage, facilitating parallel operations, organizing data for secure and rapid access, and
handling network communications. This unit presents the definition of the operating system,
goals of the operating system, generations of OS, different types of OS and functions of OS.
We can view an operating system as a resource allocator. A computer system has many
resources (hardware and software) that may be required to solve a problem: CPU time, memory
space, files storage space, input/output devices etc. The operating system acts as the manager
of these resources and allocates them to specific programs and users as necessary for their
tasks. Since there may be many, possibly conflicting, requests for resources, the operating
system must decide which requests are allocated resources to operate the computer system
fairly and efficiently. An operating system is a control program. This program controls the
execution of user programs to prevent errors and improper use of the computer. Operating
systems exist because: they are a reasonable way to solve the problem of creating a usable
computing system.
While there is no universally agreed upon definition of the concept of an operating system, the
following is a reasonable starting point. A computer’s operating system is a group of programs
designed to serve two basic purpose:
a) To control the allocation and use of the computing system’s resources among the
various users and tasks; and
b) To provide an interface between the computer hardware and the programmer that
simplifies and makes feasible the creation, coding, debugging, and maintenance of
application program.
3
(a) Should act as a command interpreter by providing a user-friendly environment;
(b) Should facilitate communication with other users;
(c) Facilitate the directory/file creation along with the security option;
(d) Provide routines that handle the intricate details of I/O programming;
(e) Provide access to compilers to translate programs from high-level language to
machine language;
(f) Provide a loader program to move the compiled program code to the computer’s
memory for execution;
(g) Assure that when there are several active processes in the computer, each will get
fair and non-interfering access to the central processing unit for execution;
(h) Take care of storage and device allocation;
(i) Provide for long term storage of user information in the form of files; and
(j) Permit system resources to be shared among users when appropriate and be
protected from unauthorised or mischievous intervention as necessary.
The abstract view of the components of a system and the positioning of OS is shown in the
Figure 1.1.
Activity 1a
1. What is meant by resource allocator?
2. List five functions which an effective Operating System should accomplish.
4
b) The secondary goal is to use the hardware in an efficient manner
When the first electronic computer was developed in 1940, it was created without any operating
system. In early times, users have full access to the computer machine and write a program for
each task in absolute machine language. The programmer can perform and solve only simple
mathematical calculations during the computer generation, and this calculation does not require
an operating system.
The first operating system (OS) was created in the early 1950s and was known as GMOS. General
Motors has developed OS for the IBM computer. The second-generation operating system was
based on a single stream batch processing system because it collects all similar jobs in groups or
batches and then submits the jobs to the operating system using a punch card to complete all
jobs in a machine. At each completion of jobs (either normally or abnormally), control transfer to
the operating system that is cleaned after completing one job and then continues to read and
initiates the next job in a punch card. After that, new machines were called mainframes, which
were very big and used by professional operators.
The fourth generation of operating systems is related to the development of the personal
computer. However, the personal computer is very similar to the minicomputers that were
developed in the third generation. The cost of a personal computer was very high at that time;
there were small fractions of minicomputers costs. A major factor related to creating personal
computers was the birth of Microsoft and the Windows operating system. Microsoft created the
first window operating system in 1975. After introducing the Microsoft Windows OS, Bill Gates
and Paul Allen had the vision to take personal computers to the next level. Therefore, they
introduced the MS-DOS in 1981; however, it was very difficult for the person to understand its
cryptic commands. Today, Windows has become the most popular and most commonly used
operating system technology. And then, Windows released various operating systems such as
Windows 95, Windows 98, Windows XP and the latest operating system, Windows 7. Currently,
most Windows users use the Windows 10 operating system. Besides the Windows operating
system, Apple is another popular operating system built in the 1980s, and this operating system
5
was developed by Steve Jobs, a co-founder of Apple. They named the operating system
Macintosh OS or Mac OS.
Activity 1b
1. Explain briefly the development of operating System.
2. Describe the impact of “user-friendly” in the fourth generation.
3. What are the main responsibilities of an Operating System?
These time operating systems are used to control machinery, scientific instruments and
industrial systems. An RTOS typically has very little user-interface capability, and no end-user
utilities. A very important part of an RTOS is managing the resources of the computer so that a
particular operation executes in precisely the same amount of time every time it occurs. In a
complex machine, having a part move more quickly just because system resources are available
may be just as catastrophic as having it not move at all because the system is busy.
6
A multiprogramming operating system is a system that allows more than one active user
program (or part of user program) to be stored on main memory simultaneously. Thus, it is
evident that a time-sharing system is a multiprogramming system but note that a
multiprogramming system is not necessarily a time-sharing system. A batch or real time
operating system could, and indeed usually does, have more than one active user program
simultaneously in main storage. Another important, and all too similar, term is
“multiprocessing”.
Network operating systems are not fundamentally different from single processor operating
systems. They obviously need a network interface controller and some low-level software to
drive it, as well as programs to achieve remote login and remote files access, but these
additions do not change the essential of the operating systems.
A distributed operating system, in contrast, is one that appears to its users as a traditional
uniprocessor system, even though it is actually composed of multiple processors. In a true
distributed system, users should not be aware of where their programs are being run or where
their files are located; that should all be handled automatically and efficiently by the operating
system.
True distributed operating systems require more than just adding a little code to a uni-
processor operating system, because distributed and centralized systems differ in critical ways.
Distributed systems, for example, often allow program to run on several processors at the same
time, thus requiring more complex processor scheduling algorithms in order to optimize the
amount of parallelism achieved.
7
1.6.8. Operating Systems for Embedded Devices
As embedded systems (PDAs, cellphones, point-of-sale devices, VCR’s, industrial robot control,
or even your toaster) becomes more complex hardware-wise with every generation, and more
features are put into them day-by-day, applications they run require more and more to run on
actual operating system code in order to keep the development time reasonable. Some of the
popular OS are:
a) Nexus’s Conix - an embedded operating system for ARM processors.
b) Sun’s Java OS - a standalone virtual machine not running on top of any other OS; mainly
targeted at embedded systems.
c) Palm Computing’s Palm OS - Currently the leader OS for PDAs, has many applications
and supporting companies.
d) Microsoft’s Windows CE and Windows NT Embedded OS.
Let us study various examples of the popular operating systems in the next section.
Activity 1c
1. Explain briefly eight types of Operating system.
2. Differentiate between Network Operating System and Distributed Operating
System.
8
c. Extendible - Extensible
• Adding new facilities and features - which look like the old ones.
Activity 1d
1. Discuss different views of the Operating Systems.
2. Summarise the characteristics of the following Operating Systems: (a) Batch
Processing (b) Time Sharing (c) Real time
9
Memory is the most expensive part in the computer system. Memory is a large array of words
or bytes, each with its own address. Interaction is achieved through a sequence of reads or
writes of specific memory address. The CPU fetches from and stores in memory. There are
various algorithms that depend on the particular situation to manage the memory. Selection of
a memory management scheme for a specific system depends upon many factors, but
especially upon the hardware design of the system. Each algorithm requires its own hardware
support. The operating system is responsible for the following activities in connection with
memory management.
(a) Keep track of which parts of memory are currently being used and by whom;
(b) Decide which processes are to be loaded into memory when memory space
becomes available; and
(c) Allocate and deallocate memory space as needed.
Memory management techniques will be discussed in great detail later in this course.
The operating system is responsible for the following activities in connection with disk
management:
(a) Free space management;
(b) Storage allocation; and
(c) Disk scheduling.
10
For convenient use of the computer system, the operating system provides a uniform logical
view of information storage. The operating system abstracts from the physical properties of its
storage devices to define a logical storage unit, the file. Files are mapped, by the operating
system, onto physical devices. A file is a collection of related information defined by its creator.
Commonly, files represent programs (both source and object forms) and data. Data files may be
numeric, alphabetic or alphanumeric. Files may be free-form, such as text files or may be rigidly
formatted. In general, a file is a sequence of bits, bytes, lines or records whose meaning is
defined by its creator and user. It is a very general concept.
The operating system implements the abstract concept of the file by managing mass storage
device, such as types and disks. Also, files are normally organised into directories to ease their
use. Finally, when multiple users have access to files, it may be desirable to control by whom
and in what ways files may be accessed.
The operating system is responsible for the following activities in connection to the file
management.
(a) The creation and deletion of files;
(b) The creation and deletion of directory;
(c) The support of primitives for manipulating files and directories;
(d) The mapping of files onto disk storage;
(e) Backup of files on stable (nonvolatile) storage; and
(f) Protection and security of the files.
1.9.6. Protection
The various processes in an operating system must be protected from each other’s activities.
For that purpose, various mechanisms which can be used to ensure that the files, memory
segment, CPU and other resources can be operated on only by those processes that have
gained proper authorisation from the operating system.
For example, memory addressing hardware ensures that a process can only execute within its
own address space. The timer ensures that no process can gain control of the CPU without
relinquishing it. Finally, no process is allowed to do its own I/O, to protect the integrity of the
various peripheral devices. Protection refers to a mechanism for controlling the access of
programs, processes, or users to the resources defined by a computer controls to be imposed,
together with some means of enforcement.
Protection can improve reliability by detecting latent errors at the interfaces between
component subsystems. Early detection of interface errors can often prevent contamination of
a healthy subsystem by a subsystem that is malfunctioning. An unprotected resource cannot
defend against use (or misuse) by an unauthorised or incompetent user.
1.9.7. Networking
A distributed system is a collection of processors that do not share memory or a clock. Instead,
each processor has its own local memory, and the processors communicate with each other
through various communication lines such as high-speed buses or telephone lines. Distributed
systems vary in size and function. They may involve microprocessors, workstations,
minicomputers and large general-purpose computer systems.
11
The processors in the system are connected through a communication network, which can be
configured in the number of different ways. The network may be fully or partially connected.
The communication network design must consider routing and connection strategies and the
problem of connection and security.
A distributed system provides the user with access to the various resources the system
maintains. Access to a shared resource allows computation speed-up, data availability and
reliability.
The Figure 1.2 depicts the role of the operating system in coordinating all the functions.
Activity 1d
1. Mention the advantanges and limitations of Multiuser Operating Systems.
2. What is a Multitasking system and mention its advantages.
3. Illustrate a simple operating system for a security control system.
12
1.10. Summary
This Unit presented the principle operation of an operating system. In this unit we had briefly
described about the history, the generations and the types of operating systems. An operating
system is a program that acts as an interface between a user of a computer and the computer
hardware. The purpose of an operating system is to provide an environment in which a user
may execute programs. The primary goal of an operating system is to make the computer
convenient to use. And the secondary goal is to use the hardware in an efficient manner.
Operating systems may be classified by both how many tasks they can perform
“simultaneously” and by how many users can be using the system “simultaneously”. That is:
single-user or multi-user and single-task or multi-tasking. A multi-user system must clearly be
multi-tasking. In the next unit we will discuss the concept of processes and their management
by the OS.
Reading sources/links
1. Deital, H., M. (1984). An introduction to operating systems. Peterson: Addition
Wesley Publishing Company.
2. Dhamdhere, D., M. (2006). Operating systems: A concept-based approach. New
Delhi: Tata McGraw-Hill.
3. Madnicj, & Donovan. (1974). Operating system - Concepts and design. New
York: McGraw-Hill International Education.
4. Milenkovic, M. (2000). Operating systems: Concept and design. New York:
McGrawHill International Education.
5. Silberschatz, A., & James, L. (1985). Operating system concepts. Peterson:
Addition Weslet Publishing Company.
6. Tanenbaum, A., S., & Woodhull, A., S. (2009). Operating system design and
implementation. UK: Pearson.
2 Topic 2: Processes
2.1. Introduction
In the earlier unit we have studied the overview and the functions of an operating system. In
this unit we have detailed discussion on the processes and their management by the operating
system. The other resource management features of operating systems will be discussed in the
subsequent units. The CPU executes a large number of programs. While its main concern is the
execution of user programs, the CPU is also needed for other system activities. These activities
13
are called processes. A process is a program in execution. Typically, a batch job is a process. A
time-shared user program is a process. A system task, such as spooling, is also a process. For
now, a process may be considered as a job or a time-shared program, but the concept is
actually more general.
In general, a process will need certain resources such as CPU time, memory, files, I/O devices,
etc, to accomplish its task. These resources are given to the process when it is created. In
addition to the various physical and logical resources that a process obtains when it is created,
some initialisation data (input) may be passed along. For example, a process whose function is
to display the status of a file, say F1, on the screen will get the name of the file F1 as an input
and execute the appropriate program to obtain the desired information.
We emphasise that a program by itself is not a process; a program is a passive entity, while a
process is an active entity. It is known that two processes may be associated with the same
program; they are nevertheless considered two separate execution sequences. A process is the
topic of work in a system. Such a system consists of a collection of processes, some of which are
operating system processes, those that execute system code, and the rest being user processes,
those that execute user code. All of those processes can potentially execute concurrently.
The operating system is responsible for the following activities in connection with processes
managed.
1. The creation and deletion of both user and system processes;
2. The suspension is resumption of processes;
3. The provision of mechanism for process synchronisation; and
4. The provision of mechanism for deadlock handling.
We will learn the operating system view of the processes, types of schedulers, different types of
scheduling algorithms, in the subsequent sections of this topic.
14
f. Unit of work individually schedulable by an operating system.
Formally, we can define a process is an executing program, including the current values of the
program counter, registers and variables. The subtle difference between a process and a
program is that the program is a group of instructions whereas the process is the activity.
The operating system works as the computer system software that assists hardware in
performing process management functions. Operating system keeps track of all the active
processes and allocate system resources to them according to policies devised to meet design
performance objectives. To meet process requirements OS must maintain many data structures
efficiently. The process abstraction is fundamental means for the OS to manage concurrent
program execution. OS must interleave the execution of a number of processes to maximise
processor use while providing reasonable response time. It must allocate resources to processes
in conformance with a specific policy. In general, a process will need certain resources such as
CPU time, memory, files, I/O devices etc to accomplish its tasks. These resources are allocated
to the process when it is created. A single processor may be shared among several processes
with some scheduling algorithm being used to determine when to stop work on one process
and provide service to a different one which we will discuss later in this topic.
Operating systems must provide some way to create all the processes needed. In simple
systems, it may be possible to have all the processes that will ever be needed be present when
the system comes up. In almost all systems however, some way is needed to create and destroy
processes as needed during operations. In UNIX, for instant, processes are created by the fork
system call, which makes an identical copy of the calling process. In other systems, system calls
exist to create a process, load its memory. And start it running. In general, processes need a way
to create other processes. Each process has one parent process, but zero, one, two or more
children processes.
15
h) Process Synchronisation;
i) Inter process Communication Support; and
j) Management of Process Control Blocks.
2.3.1. Processes Relationship
In the concurrent environment basically processes have two relationships, competition and
cooperation. In the concurrent environment, processes compete with each other for allocation
of system resources to execute their instructions. In addition, a collection of related processes
that collectively represent a single logical application cooperate with each other. There should
be a proper operating system to support these relations. In the competition, there should be
proper resource allocation and protections in address generation.
16
As shown in Figure 2.1, four transitions are possible among the states. Transition 1 appears
when a process discovers that it cannot continue. In order to get into blocked state, some
systems must execute a system call block. In other systems, when a process reads from a pipe
or special file and there is no input available, the process is automatically blocked.
Transition 2 and 3 are caused by the process schedule, a part of the operating system.
Transition 2 occurs when the scheduler decides that the running process has run long enough,
and it is time to let another process have some CPU time.
Transition 3 occurs when all other processes have had their share and it is time for the first
process to run again.
Transition 4 appears when the external event for which a process was waiting was happened. If
no other process is running at that instant, transition 3 will be triggered immediately, and the
process will start running. Otherwise, it may have to wait in ready state for a little while until
the CPU is available. Using the process model, it becomes easier to think about what is going on
inside the system.
17
e) Processor scheduling information, which includes process priority, pointers to
scheduling queues and any other scheduling parameters;
f) List of open files.
2.3.4. Threads
Threads, sometimes called Light-weight Processes (LWPs) are independently scheduled parts of
a single program. We say that a task is multithreaded if it is composed of several independent
sub-processes which do work on common data, and if each of those pieces could (at least in
principle) run in parallel.
If we write a program which uses threads - there is only one program, one executable file, one
task in the normal sense. Threads simply enable us to split up that program into logically
separate pieces, and have the pieces run independently of one another, until they need to
communicate. In a sense, threads are a further level of object orientation for multitasking
systems. They allow certain functions to be executed in parallel with others.
On a truly parallel computer (several CPUs) we might imagine parts of a program (different
subroutines) running on quite different processors, until they need to communicate. When one
part of the program needs to send data to the other part, the two independent pieces must be
synchronised, or be made to wait for one another. But what is the point of this? We can always
run independent procedures in a program as separate programs, using the process mechanisms
we have already introduced. They could communicate using normal interprocesses
communication. Why introduce another new concept? Why do we need threads?
The point is that threads are cheaper than normal processes, and that they can be scheduled for
execution in a user-dependent way, with less overhead. Threads are cheaper than a whole
process because they do not have a full set of resources each. Whereas the process control
block for a heavyweight process is large and costly to context switch, the PCBs for threads are
much smaller, since each thread has only a stack and some registers to manage. It has no open
file lists or resource lists, no accounting structures to update. All of these resources are shared
18
by all threads within the process. Threads can be assigned priorities - a higher priority thread
will get put to the front of the queue. Let us define heavy and lightweight processes with the
help of a Table 2.1.
If the kernel itself is multithreaded, the scheduler assigns CPU time on a thread basis rather
than on a process basis. A kernel level thread behaves like a virtual CPU, or power-point to
which user-processes can connect in order to get computing power. The kernel has as many
system level threads as it has CPUs and each of these must be shared between all of the user-
threads, which in turn is equal to the number of CPUs on the system.
Since threads work “inside” a single task, the normal process scheduler cannot normally tell
which thread to run and which not to run - that is up to the program. When the kernel
schedules a process for execution, it must then find out from that process which is the next
thread it must execute. If the program is lucky enough to have more than one processor
available, then several threads can schedules at the same time. Some important
implementation of threads are:
19
a) The Mach System / OSFI user and system level);
b) Solaris 1 (user level);
c) Solaris 2 (user and system level);
d) OS/2 (system level only);
e) NT threads (user and system level);
f) IRIX threads; and
g) POSIX standardised user threads interface
As an example of how system calls are used, consider writing a simple program to read data
from one file and to copy them to another file. There are two names of two different files in
which one input file and the other is the output file. One approach is for the program to ask the
user the names of the two files. In an interactive system, this approach will require a sequence
of systems calls, first to write a prompting message on the screen and then to read from the
keyboard the character that the two files have. Once the two file names are obtained the
program must open the input file and create the output file. Each of these operations requires
another system call and may encounter possible error conditions. When the program tries to
open the input file, it may find that no file of that name exists or that the file is protected
against access. In these cases the program should print the message on the console and then
terminate abnormally which require another system call. If the input file exists then we must
create the new output file. We may find an output file with the same name. This situation may
cause the program to abort or we may delete the existing file and create a new one. After
opening files, we may enter a loop that reads from input file and writes to output file. Each read
and write must return status information regarding various possible error conditions. Finally,
after the entire file is copies the program may close both files. Examples of some operating
system calls are:
1. Create
In response to the create call the operating system creates a new process with the
specified or default attributes and indentifier. Some of the parameters definable at
the process creation time include:
(i) Level of privilege, such as system or user;
(ii) Priority; (iii)Size and memory requirements;
(iii) Maximum data area and/or stack size;
(iv) Memory protection information and access rights; and
(v) Other system dependent data.
2. Delete
The delete service is also called destroy, terminate or exit. Its execution causes the
operating system to destroy the designated process and remove it from the system.
3. Abort
It is used to terminate the process forcibly. Although a process could concervanly
abort itself, the most frequent use of this call is for involuntary terminations, such
as removal of malfunctioning process from the system.
4. Fork/Join
20
Another method of process creation and termination is by means of FORK/JOIN
pair, originally introduced as primitives for multiprocessor system. The FORK
operations are used to split a sequence of instruction into two concurrently
executable sequences. JOIN is used to merge the two sequences of code divided by
the FORK and it is available to a parent process for synchronisation with a child.
5. Suspend
6. The suspend system call is also called BLOCK in some systems. The designated
process is suspended indefinitely and placed in the suspend state. A process may be
suspended itself or another process when authorized to do so.
6. Resume
The resume system call is also called WAKEUP in some systems. This call resumes
the target process, which is presumably suspended. Obviously, a suspended process
cannot resume itself because a process must be running to have its operating
system call processed. So, a suspended process depends on a partner process to
issue the resume.
7. Delay
The system call delay is also known as SLEEP. The target process is suspended for
the duration of the specified time period. The time may be expressed in terms of
system clock ticks that are system dependent and not portable or in standard time
units such as seconds and minutes. A process may delay itself or optionally, delay
some other process.
8. Get_Attributes
It is an enquiry to which the operating system responds by providing the current
values of the process attributes, or their specified subset, from the PCB.
9. Change Priority
It is an instance of a more general SET-PROCESS-ATTRIBUTES system call. Obviously,
this call is not implemented in systems where process priority is static.
Activity 2a
1) Explain the difference between a process and a thread with some examples.
2) Identify the different states a live process may occupy and show how a process
moves between these states.
3) What are the differences between a thread and a Process?
21
three types of schedulers and performance criteria that schedulers may use in maximising
system performance. Finally, at the end of the unit, we will study various scheduling algorithms.
22
processor utilisation. The short term scheduler, like all other OS programs, has to execute
on the processor. If it takes 1 millisecond to choose a process that means (1/(10 + 1)) = 9%
of the processor time is being used for short time scheduling and only 91% may be used by
processes for execution.
b) Long Term Scheduler
The long-term scheduler selects processes from the process pool and loads selected
processes into memory for execution. The long-term scheduler executes much less
frequently when compared with the short term scheduler. It controls the degress of
multiprogramming (no. of processes in memory at a time). If the degree of
multiprogramming is to be kept stable (say 10 processes at a time), the long-term scheduler
may only need to be invoked till the process finishes execution. The long-term scheduler
must select a good process mix of I/O-bound and processor bound processes. If most of the
processes selected are I/O-bound, then the ready queue will almost be empty, while the
device queue(s) will be very crowded. If most of the processes are processor-bound, then
the device queue(s) will almost be empty while the ready queue is very crowded and that
will cause the short-term scheduler to be invoked very frequently. Time-sharing systems
(mostly) have no long-term scheduler. The stability of these systems either depends upon a
physical limitation (no of available terminals) or the self-adjusting nature of users (if you
can’t get response, you quit). It can sometimes be good to reduce the degree of
multiprogramming by removing processes from memory and storing them on disk.
c) Medium Term Scheduler
The processes of reducing the degree of multiprogramming by removing processes from
memory and storing them on disk can then be reintroduced into memory by the medium-
term scheduler. This operation is also known as swapping. Swapping may be necessary to
improve the process mix or to free memory.
In order to achieve an efficient processor management, OS tries to select the most appropriate
process from the ready queue. For selecting, the relative importance of the following may be
considered as performance criteria:
a) CPU Utilisation
The key idea is that if the CPU is busy all the time, the utilisation factor of all the
components of the system will be also high. CPU utilisation is the ration of busy time of
the processor to the total time passes for processes to finish.
b) Throughput
23
It refers to the amount of work completed in a unit of time. One way to measure
throughput is by means of the number of processes that are completed in a unit of
time. The higher the number of processes, the more work apparently is being done by
the system. But this approach is not very useful for comparison because this is
dependent on the characteristics and resource requirement of the process being
executed. Therefore, to compare throughput of several scheduling algorithms it should
be fed into the process with similar requirements. The throughput can be calculated by
using the formula:
c) Turnaround Time
It may be defined as interval from the time of submission of a process to the time of its
completion. It is the sum of the periods spent waiting to get into memory, waiting in the
ready queue, CPU time and I/O operations.
d) Waiting Time
This is the time spent in the ready queue. In multiprogramming operating system
several jobs reside at a time in memory. CPU executes only one job at a time. The rest
of jobs wait for the CPU. The waiting time may be expressed as turnaround time, less
than the actual processing time. But the scheduling algorithm affects or considers the
amount of time that a process spends waiting in a ready queue. Thus, rather than
looking at turnaround time waiting time is usually the waiting time for each process.
e) Response time
It is most frequently considered in time sharing and real time operating system.
However, its characteristics differ in the two systems. In time sharing system it may be
defined as interval from the time the last character of a command line of a program or
transaction is entered to the time the last result appears on the terminal. In real time
system it may be defined as interval from the time an internal or external event is
signaled to the time the first instruction of the respective service routine is executed.
One of the problems in designing schedulers and selecting a set of its performance
criteria is that they often conflict with each other. For example, the fastest response
time in time sharing and real time system may result in low CPU utilisation. Throughput
and CPU utilisation may be increased by executing the large number of processes, but
then response time may suffer. Therefore, the design of a scheduler usually requires
24
balance of all the different requirements and constraints. In the next section we will
discuss various scheduling algorithms.
CPU scheduling deals with the problem of deciding which of the processes in the ready queue is
to be allocated to the CPU. There are several scheduling algorithms which will be examined in
this section. A major division among scheduling algorithms is that whether they support pre-
emptive or non-preemptive scheduling discipline.
a) Preemptive Scheduling
Preemption means the operating system moves a process from running to ready
without the process requesting it. An OS implementing this algorithms switches to the
processing of a new request before completing the processing of the current request.
The preempted request is put back into the list of the pending requests. Its servicing
would be resumed sometime in the future when it is scheduled again. Preemptive
scheduling is more useful in high priority process which requires immediate response.
For example, in Real time system the consequence of missing one interrupt could be
dangerous. Round Robin scheduling, priority-based scheduling or event driven
scheduling and SRTN are considered to be the preemptive scheduling algorithms.
b) Non-Preemptive scheduling
A scheduling is non-preemptive if once a process has been allotted to the CPU, the CPU
cannot be taken away from the process. A non-preemptible discipline always processes
a scheduled request to its completion. In non-preemptive systems, jobs are made to
wait by longer jobs, but the treatment of all processes is fairer. First come First Served
(FCFS) and Shortest Job First (SJF), are considered to be the non-preemptive scheduling
algorithms.
The decision whether to schedule preemptive or not depends on the environment and the type
of application most likely to be supported by a given operating system.
Activity 2a
1. Briefly explain the following Operating System calls: a)
a. Create
b. Fork/Join
c. Delay
2. What is the Process Control Block?
3. Identify the information which must be maintained by the operating system
for each live process.
25
FCFS tends to favour CPU-Bound processes. Consider a system with a CPU-bound process and a
number of I/O-bound processes. The I/O bound processes will tend to execute briefly, then
block for I/O. A CPU bound process in the ready should not have to wait long before being made
runable. The system will frequently find itself with all the I/O-Bound processes blocked and
CPU-bound process running. As the I/O operations complete, the ready Queue fill up with the
I/O bound processes.
Under some circumstances, CPU utilisation can also suffer. In the situation described above,
once a CPU-bound process does issue an I/O request, the CPU can return to process all the I/O-
bound processes. If their processing completes before the CPU-bound process’s I/O completes,
the CPU sits idle. So, with no preemption, component utilisation and the system throughput
rate may be quite low.
Example:
Calculate the turn-around time, waiting time, average turnaround time, average waiting time,
throughput and processor utilisation for the given set of processes that arrive at a given arrive
time shown in the table, with the length of processing time given in milliseconds:
If the processes arrives as per the arrival time, the Gantt chart will be:
26
Average Response Time :
Formula : Response Time = First Response - Arrival Time
Response Time of P1 = 0
Response Time of P2 => 3-2 = 1
Response Time of P3 => 6-3 = 3
Response Time of P4 => 7-5 = 2
Response Time of P5 => 11-8 =3
Average Response Time => ( 0+1+3+2+3 )/5 => 9/5 = 1.8 ms
Processor Utilisation = (Processor Busy time)/(Processor Busy Time + Processor idle Time) =
13/(13+0)=1 * 100% = 100%
Example: Consider the following set of processes with the following processing time which
arrived at the same time
Using SJF scheduling because the shortest length of process will first get execution, the Gantt
chart will be:
Solution
Average Waiting Time :
Formula = Staring Time - Arrival Time
waiting Time for P1 => 3-0 = 3
waiting Time for P2 => 16-0 = 16
waiting Time for P3 => 9-0 = 9
waiting Time for P4 => 0-0=0
Average waiting time => (3+16+9+0 )/4 => 28/4 =7 ms
27
Formula = waiting Time + burst Time (Process time)
Turn Around Time for P1 => 3+6 =9
Turn Around for P2 => 16+8 =24
Turn Around for P3 => 9+7 = 16
Turn Around Time for P4 => 0+3 =3
Average Turn around time => ( 9+24+16+3 )/4 => 52/4 = 13 ms
Each process is allocated a small time-slice called quantum. No process can run for more than
one quantum while others are waiting in the ready queue. If a process needs more CPU time to
complete after exhausting one quantum, it goes to the end of ready queue to await the next
allocation. To implement the RR scheduling, Queue data structure is used to maintain the
Queue of Ready processes. A new process is added at the tail of that Queue. The CPU scheduler
picks the first process from the ready Queue, Allocate processor for a specified time Quantum.
After that time the CPU scheduler will select the next process is the ready Queue.
Example:
Consider the following set of process with the processing time given in milliseconds
If we use a time Quantum of 4 milliseconds then process P1 gets the first 4 milliseconds. Since it
requires another 20 milliseconds, it is preempted after the first time Quantum, and the CPU is
28
given to the next process in the Queue, Process P2. Since process P2 does not need and
milliseconds, it quits before its time Quantum expires. The CPU is then given to the next
process, Process P3 one each process has received 1 time Quantum, the CPU is returned to
process P1 for an additional time quantum. The Gantt chart will be:
Solution
AVERAGE TURN AROUND TIME :
FORMULA : Turn around time = waiting time + burst Time
Turn around time for P1 => 14+30 =44
Turn around time for P2 => 15+6 = 21
Turn around time for P3 => 16+8 = 24
Average turn around time => ( 44+21+24 )/3 = 29.66 ms
Example:
Consider the set of four processes arrived as per timings described in the table:
At time 0, only process P1 has entered the system, so it is the process that executes. At time 1,
process P2 arrives. At that time, process P1 has 4 time units left to execute. At this juncture
process 2’s processing time is less compared to the P1 left out time (4 units). So P2 starts
executing at time 1. At time 2, process P3 enters the system with the processing time 5 units.
Process P2 continues executing as it has the minimum number of time units when compared
29
with P1 and P3. At time 3, process P2 terminates and process P4 enters the system. Of the
processes P1, P3 and P4.
P4 has the smallest remaining execution time so it starts executing. When process P1
terminates at time 10, process P3 executes. The Gantt chart is shown below:
Solution:
Turnaround time for each process can computed by subtracting the time it terminated from the
arrival time. Turn around Time = t(Process Completed) - t(Process Submitted) The turnaround
time for each of the processes is:
The average turnaround time is (10+2+13+3)/4 = 7 The waiting time can be computed by
subtracting processing time from turnaround time, yielding the following 4 results for the
processes as
The Average Waiting Time = (5+0+8+0) / 4 = 3.25 milliseconds Four jobs executed in 15 time
units, so throughput is 15/4 = 3.75 time units/job
Example:
Consider the following set of five processes, assumed to have arrived at the same time with the
length of processor timing in milliseconds.
30
Using priority scheduling we would schedule these processes according to the following Gantt
chart:
Priorities can be defined either internally or externally. Internally defined priorities use one
measurable quantity or quantities to complete the priority of a process.
Activity 2a
1. What is the different between preemptive dan non-preemptive scheduling.
2. Explain the algorithms of Round Robin scheduling.
a). Maximise CPU utilisation with the maximum response time; and
b). Maximise throughput.
Example:
Assume that we have the following five processes arrived at time 0, in the order given with the
length of CPU time given in milliseconds.
31
First consider the FCFS scheduling algorithm for the set of processes. For FCFS scheduling the
Gantt chart will be:
Average Waiting Time: (0+10+39+42+49)/5 = 28 milliseconds. Now consider the SJF scheduling,
the Gantt chart will be:
32
Average Waiting Time: (10+32+20+23+40)/5 = 23 milliseconds
Now if we compare average waiting time above algorithms, we see that SJF policy results in less
than one half of the average waiting time to that of FCFS scheduling; the RR algorithm gives us
an intermediate value. So performance of algorithm can be measured when all the necessary
information is provided.
Activity 2a
1. Explain the difference between voluntary or co-operative scheduling and
preemptive scheduling. Give two examples of preemptive and of non-
preemptive scheduling algorithms.
2. Outline how different process priorities can be implemented in a scheduling
algorithm. Explain why these priorities need to be dynamically adjusted.
3. Draw the Gantt chart for the FCFS policy, considering the following set of
processes that arrive at time 0, with the length of CPU time given in
milliseconds. Also calculate the Average Waiting Time.
4. For the given five processes arriving at time 0, in the order with the length of
CPU time in milliseconds.
2.8. Summary
A process is an instance of a program in execution. A process can be defined by the system or
process is an important concept in modern operating system. Processes provide a suitable
means for informing the operating system about independent activities that may be scheduled
for concurrent execution. Each process is represented by a Process Control Block (PCB). Several
PCBs can be linked together to form a queue of waiting processes. The selection and allocation
of processes is done by a scheduler. There are several scheduling algorithms. We have discussed
FCFS, SJF, RR, SJRT and priority algorithms along with the performance evaluation.
33
Reading sources /links
1. Deital, H., M. (1984). An introduction to operating systems. Peterson: Addition Wesley
Publishing Company.
2. Dhamdhere, D., M. (2006). Operating systems: A concept-based approach. New Delhi: Tata
McGraw-Hill.
3. Madnicj, & Donovan. (1974). Operating system - Concepts and design. New York: McGraw-
Hill International Education.
4. Milenkovic, M. (2000). Operating systems: Concept and design. New York: McGrawHill
International Education.
5. Silberschatz, A., & James, L. (1985). Operating system concepts. Peterson: Addition Weslet
Publishing Company.
6. Tanenbaum, A., S. & Woodhull, A., S. (2009). Operating system design and implementation.
UK: Pearson.
A simple batch operating system can be viewed as three processes - a reader process, an
executor process and a printer process. The reader reads cards from card reader and places
card images in an input buffer. The executor process reads card images from input buffer and
performs the specified computation and store the result in an output buffer. The printer
process retrieves the data from the output buffer and writes them to a printer. Concurrent
processing is the basis of operating system which supports multiprogramming. The operating
system supports concurrent execution of a program without necessarily supporting elaborate
form of memory and file management. This form of operation is also known as multitasking.
One of the benefits of multitasking is that several processes can be made to cooperate in order
to achieve their goals. To do this, they must do one the following:
a) Communicate
Interprocess communication (IPC) involves sending information from one process to
another. This can be achieved using a “mailbox” system, a socket which behaves like a
virtual communication network (loop back), or through the use of „pipes”, Pipes are a
34
system construction which enable one process to open another process as if it were a
file for writing or reading.
b) Share Data
A segment of memory must be available to both the processes. (Most memory is locked
to a single process).
c) Waiting
Some processes wait for other processes to give a signal before continuing, This is an
issue of synchronisation.
Synchronisation is often necessary when processes communicate. Processes are executed with
unpredictable speeds. Yet to communicate one process must perform some action such as
setting the value of a variable or sending a message that the other detects. This only works if
the events perform an action or detect an action are constrained to happen in that order. Thus
one can view synchronisation as a set of constrainst on the ordering of events. The programmer
employs a synchronisation mechanism to delay execution of a process in order to satisfy such
constraints.
In this unit, let us study the concept of interprocess communication and synchronisation, need
of semaphores, classical problems in concurrent processing, critical regions, monitors and
message passing.
Example:
Consider a machine with a single printer running a time-sharing operation system. If a process
needs to print its results, it must request that the operating system gives it access to the
35
printer’s device driver. At this point, the operating system must decide whether to grant this
request, depending upon whether the printer is already being used by another process. If it is
not, the operating system should grant the request and allow the process to continue;
otherwise, the operating system should deny the request and perhaps classify the process as a
waiting process until the printer becomes available. Indeed, if two processes were given
simultaneous access to the machine’s printer, the results would be worthless to both.
Consider the following related definition to understand the example in a better way:
a) Critical Resource
It is a resource shared with constraints on its use (e.g, memory, files, printers, etc).
b) Critical Exclusion
It is code that accesses a critical resource.
c) Mutual Exclusion
At most one process may be executing a critical section with respect to a particular
critical resource simultaneously.
In the example given above, the printer is the critical resource. Let’s suppose that the processes
which are sharing this resource are called process A and process B. The critical sections of
process A and process B are the section of the code which issue the print command. In order to
ensure that both processes do not attempt to use the printer at the same, they must be granted
mutually exclusive access to the printer driver. First, we consider the interprocess
communication part. There exist two complementary interprocess communication types:
a) Shared-memory system; and
b) Message-passing system.
It is clear that these two schemes are not mutually exclusive and could be used simultaneously
within a single operating system.
A critical problem occurring in shared-memory system is that two or more processes are
reading or writing some shared variables or shared data, and the final results depend on who
runs precisely and when. Such situations are called race conditions. In order to avoid race
conditions, we must find some way to prevent more than one process from reading and writing
shared variables or shared data at the same time, i.e., we need the concept of mutual exclusion
(which we will discuss in the later section). It must be sure that if one process is using a shared
variable, the other process will be excluded from doing the same thing.
36
basically provides two operations: send (message) and receive (message). In order to send and
to receive messages, a communication link must exist between two involved processes. This link
can be implemented in different ways. The possible basic implementation questions are:
a) How are links established?
b) Can a link be associated with more than two processes?
c) How many links can there be between every pair of process?
d) What is the capacity of a link? That is, does the link have some buffer space? If so, how
much?
e) What is the size of the message? Can the link accommodate variable size or fixed-size
message?
f) Is the link unidirectional or bi-directional?
In the following, we consider several methods for logically implementing a communication link
and the send/receive operations. These methods can be classified into two categories:
a) Naming
It consists of direct and indirect communication.
i. Direct Communication
In direct communication, each process that wants to send or receive a message
must explicitly name the recipient or sender of the communication. In this case, the
send and receive primitives are defined as follows:
• Send (P, message). To send a message to the process P
• Receive (Q, message). To receive a message from process Q
This scheme shows the symmetry in addressing, i.e, both the sender and the
receiver have to name one another in order to communicate. In contrast to this, a
symmetry in addressing can be used, i.e, only the sender has to name the recipient;
the recipient is not required to name the sender. So the send and receive primitives
can be defined as follows:
• Send (P, message). To send a message to the process P
• Receive (id, message). To receive a message from any process; id is set to the
name of the process with whom the communication has taken place.
ii. Indirect Communication With indirect communication, the messages are sent to,
and received from a mailbox. A mailbox can be abstractly viewed as an object into
which messages may be placed and from which messages may be removed by
processes. In order to distinguish one from the other, each mailbox owns a unique
identification. A process may communicate with some other process by a number of
different mailboxes. The send and receive primitives are defined as follows:
• Send (A, message). To send a message to the mailbox A.
• Receive (A, message). To receive a message from the mailbox A.
Mailboxes may be owned either by a process or by the system. If the mailbox is owned
by a process, then we distinguish between the owner who can only receive from this
mailbox and user who can only send message to the mailbox. When a process that
owns a mailbox terminates, its mailbox disappears. Any process that sends a message to
this mailbox must be notified in the form of an exception that the mailbox no longer
exists. If the mailbox is owned by the operating system, then it has an existence of its
37
own, i.e, it is independent and not attached to any particular process. The operating
system provides a mechanism that allows a process to:
a. Create a new mailbox end and receive message through the mailbox; and
b. Destroy a mailbox
Since all processes with access rights to a mailbox may terminate, a mailbox may no
longer be accessible by any process after some time. In this case, the operating system
should reclaim whatever space was used for the mailbox.
b) Buffering
i. Capacity Link
A link has some capacity that determines the number of messages that can
temporarily reside in it. This propriety can be viewed as a queue of messages
attached to the link. Basically there are three ways through which such a queue can
be implemented.
• Zero capacity
This link has a message queue length of zero, i.e, no message can wait in it,
The sender must wait until the recipient receives the message. The two
processes must be synchronised for a message transfer to take place. The
zero-capacity link is referred to as a message passing system without
buffering.
• Bounded capacity
This link has a limited message queue length of n, i.e, at most n message
can reside in it. If a new message is sent, and the queue is not full, it is
placed in the queue by copying the message or by keeping a pointer to the
message and the sender should continue execution without waiting.
Otherwise, the sender must be delayed until space is available in the queue.
• Unbounded capacity
This queue has potentially infinite length, i.e, any number of messages can
wait in it. That is why the sender is never delayed.
Activity 3a
38
1. Explain the purpose of Interprocess Communication (IPC)
2. Differentiate the methods of naming between direct and indirect communication.
3. Explain the capacity link methods in buffering.
Here, the important point is that when one process is executing shared modifiable data in its
critical section, no other process is to be allowed to execute in its critical section. Thus, the
execution of critical sections by the processes is mutually exclusive in time.
A way of making sure that if one process is using a shared modifiable data, the other processes
will be excluded from doing the same thing.
Formally, while one process executes the shared variable, all other processes desiring to do so
at the same time moment should be kept waiting; when that process has finished executing the
shared variable, one of the processes waiting; while that process has finished executing the
shared variable, one of the processes waiting to do so should be allowed to proceed. In this
fashion, each process executing the shared data (variables) excludes all others from doing so
simultaneously. This is called Mutual Exclusion.
Consider the following examples: Two processes sharing a printer must take turns using it; if
they attempt to use it simultaneously, the output from the two processes must be mixed into
an arbitrary jumble which is unlikely to be of any use. two processes attempting to update the
39
same bank account must take turns; if each process reads the current balance from some
database, updates it, and writes it back, one of the updates will be lost.
Mutual exclusion can be achieved by a system of locks. A mutual exclusion lock is colloquially
called a mutex.
Problem: When one process is updating shared modifiable data in its critical section, no other
process should be allowed to enter in its critical section.
Conclusion
Disabling interrupts is sometimes a useful technique within the kernel of an operating system,
but it is not appropriate as a general mutual exclusion mechanism for users process. The reason
is that it is unwise to give user process the power to turn off interrupts.
Conclusion
The flaw in this proposal can be best explained by example. Suppose process A sees that the
lock is 0. Before it can set the lock to 1 another process B is scheduled, runs, and sets the lock to
1. When the process A runs again, it will also set the lock to 1, and two processes will be in their
critical section simultaneously.
40
In this proposed solution, the integer variable ‘turn’ keeps track of whose turn is to enter the
critical section. Initially, process A inspect turn, finds it to be 0, and enters in its critical section.
Process B also finds it to be 0 and sits in a loop continually testing ‘turn’ to see when it becomes
1. Continuously testing a variable waiting for some value to appear is called the Busy-Waiting.
Conclusion
Taking turns is not a good idea when one of the processes is much slower than the other.
Suppose process 0 fi nishes its critical section quickly, so both processes are now in their
noncritical section. This situation violates above mentioned condition 3.
Now look at some interprocess communication primitives which is the pair of sleep-wakeup.
Sleep
It is a system call that causes the caller to block, that is, be suspended until some other process
wakes it up.
Wakeup
It is a system call that wakes up the process. Both ‘sleep’ and ‘wakeup’ system calls have one
parameter that represents a memory address used to match up ‘sleeps’ and ‘wakeups.
3.5 Semaphores
The effective synchronisation tools often used to realise mutual exclusion in more complex
systems are semaphores. A semaphore S is an integer variable which can be accessed only
through two standard atomic operations: wait and signal. Semaphore is an integer variable S.
This integer variable S is initialized to the number of resources present in the system. The value
of semaphore S can be modified only by two functions wait() and signal(). The wait() and
signal() operation modifies the value of the semaphore S indivisibly. Which means when a
process is modifying the value of the semaphore, no other process can simultaneously modify
the value of the semaphore.
41
The value of semaphore ranges between 0 and 1. It is similar to mutex lock, but mutex is a
locking mechanism whereas, the semaphore is a signalling mechanism. In binary semaphore, if
a process wants to access the resource it performs wait() operation on the semaphore and
decrements the value of semaphore from 1 to 0. When process releases the resource, it
performs a signal() operation on the semaphore and increments its value to 1. If the value of
the semaphore is 0 and a process want to access the resource it performs wait() operation and
block itself till the current process utilizing the resources releases the resource.
3.6. Monitors
Monitor is a software synchronization tool with high-level of abstraction that provides a
convenient and effective mechanism for process synchronization. The concept of monitors was
introduced to overcome the timing errors that occurs while using semaphores for process
synchronization. It allows only one process to be active within the monitor at a time. If other
process tries to access the shared variable in monitor, it gets blocked and is lined up in the
queue to get the access to shared data when previously accessing process releases it.
Activity 3a
1. What is the purpose of semaphores?
2. Explain the wait and signal operations in semaphores.
3. What are race conditions? How race conditions occur in Operating Systems?
4. What is a critical section? Explain.
3.7. Summary
Interprocess communication provides a mechanism to allow process to communicate with
other processes. Interprocess communication system is best provided by a message passing
system. Messages systems can be defined in many different ways. If there are collection of
cooperating sequential processes that share some data. Mutual exclusion must be provided.
Different algorithms are available for solving the critical section problem which we have
discussion in this topic. The bakery algorithm is used for solving the n process critical section
problem. Interprocess synchronisation provides the processes to synchronise their activities.
Semaphores can be used to solve synchronisation problems. Semaphore can only be accessed
through two atomic operations and can be implemented efficiently. The two operations are
wait and signal.
42
Deadlocks Dekker’s solution Dynamic data exchange
Interprocess communication (IPC) Locks Locks
Mailbox Message passing Monitor Multithreaded
Mutual exclusion Mutually exclusive Semaphores
Shared memory Synchronisation
Reading sources/links
1. Deital, H., M. (1984). An introduction to operating systems. Peterson: Addition Wesley
Publishing Company.
2. Dhamdhere, D., M. (2006). Operating systems: A concept-based approach. New Delhi:
Tata McGraw-Hill.
3. Milenkovic, M. (2000). Operating systems: Concept and design. New York: McGraw-Hill
International Education.
4. Tanenbaum, A., S., & Woodhull, A., S. (2009). Operating system design and
implementation. UK: Pearson.
5. Stalling, W. (2001). Operating system (4th ed.). New Jersey: Prentice Hall.
4 Topic 4: Deadlocks
4.1. Introduction
In a computer system, we have a finite number of resources to be distributed among a number
of competing processes. These system resources are classified in several types which may be
either physical or logical. Examples of physical resources are Printers, Tape drivers, Memory
space and CPU cycles. Examples of logical resources are Files, Semaphores and Monitors. Each
resource type can have some identical instances.
A process must request a resource before using it and release the resource after using it. It is
clear that the number of resources requested cannot exceed the total number of resources
available in the system.
In a normal operation, a process may utilise a resource only in the following sequence:
a) Request
If the request cannot be immediately granted, then the requesting process must wait
until it can get the resource.
b) Use
The requesting process can operate on the resource.
c) Release
The process releases the resource after using it.
The operating system is responsible for making sure that the requesting process has been
allocated the resource. A system table indicates if each resource is free or allocated, and if
allocated, to which process. If a process requests a resource that is currently allocated to
another process, it can be added to a queue of processes waiting for this resource.
43
In some cases, several processes may compete for a fixed number of resources. A process
requests resources and if the resources are not available at that time, it enters a wait state. It
may happen that it will never gain access to the resources, since those resources are being held
by other waiting processes.
For example, assume a system with one tape drive and one plotter. Process P1 requests the
tape drive and process P2 requests the plotter. Both requests are granted. Now P1 requests the
plotter (without giving up the tape drive) and P2 requests the tape drive (without giving up the
plotter). Neither request can be granted so both processes enter a situation called the deadlock
situations.
In the earlier units, we have gone through the concept of process and the need for the
interprocess communication and synchronisation. In this unit we will study about the deadlocks,
its characterisation, deadlock avoidance and its recovery.
4.3. Deadlocks
Before studying about deadlocks, let us look at the various types of resources. There are two
types of resources namely: Pre-emptable and Non-pre-emptable Resources.
a) Pre-emptable Resources
This resource can be taken away from the process with no ill effects. Memory is an
example of a pre-emptable resource.
b) Non-preemptable Resource
This resource cannot be taken away from the process (without causing ill effect). For
example, CD resources are not pre-emptable at an arbitrary moment.
Reallocating resources can resolve deadlocks that involve pre-emptable resources. Deadlocks
that involve non-preemptable resources are difficult to deal with. Let us see how a deadlock
occurs. Definition A set of processes is in deadlock state if each process in the set is waiting for
an event that can be caused by only another process in the set. In other words, each member of
the set of deadlock processes is waiting for a resource that can be released only by a deadlock
process. None of the processes can run, none of them can release any resources and none of
them can awakened. It is important to note that the number of processes and the number and
kind of resources processed and requested are unimportant.
Let us understand the deadlock situation with the help of examples.
Example 1:
44
The simplest example of deadlock is where process 1 has been allocated a non-shareable
resource A, say, a tape drive, and process 2 has been allocated a non-sharable resource B, say, a
printer. Now, if it turns out that process 1 needs resource B (printer) to proceed and process 2
needs resource A (the tape drive) to proceed and these are the only two processes in the
system, each has blocked the other and all useful work in the system stops. This situation is
termed as deadlock.
The system is in deadlock state because each process holds a resource being requested by the
other process and neither process is willing to release the resource it holds.
Example 2:
Consider a system with three disk drivers. Suppose there are three processes, each is holding
one of these three disk drives. If each process now requests another disk drive, three processes
will be in a deadlock state, because each process is waiting for the event “disk drive is released”,
which can only be caused by one of the other waiting processes. Deadlock state involves
processes competing not only for the same resource type, but also for different resource types.
Deadlocks occur most commonly in multitasking and client/server environments and are also
known as a “Deadly Embrace”. Ideally, the program that are deadlocked or the operating
system should resolve the deadlock, but this doesn’t always happen.
From the above examples. We have understood the concept of deadlocks. In the examples, we
were given some instances, but we will study the necessary conditions for a deadlock to occur,
in the next section.
45
Consider each section of the street as a resource. In this situation:
a) Mutual exclusion condition applies, since only one vehicle can be on a section of the
street at a time.
b) Hold-and-wait condition applies, since each vehicle is occupying a section of the street,
and waiting to move on to the next section of the street.
c) Non-preemptive condition applies, since a section of the street that is occupied by a
vehicle cannot be taken away from it.
d) Circular wait condition applies, since each vehicle is waiting for the next vehicle to
move. That is, each vehicle in the traffic is waiting for a section of the street held by the
next vehicle in the traffic.
The simple rule to avoid traffic deadlock is that a vehicle should only enter an intersection if it
assured that it will not have to stop inside the intersection. It is not possible to have a deadlock
involving only one single process. The deadlock involves a circular “hold-and-wait” condition
between two or more processes, so “one” process cannot hold a resource, yet be waiting for
another resource that it is holding. In addition, deadlock is not possible between two threads,
that is, each thread has access to the resources held by the process.
We can use these graphs to determine if a deadline has occurred or may occur. If for example,
all resources have only one instance (all resource node rectangles have one dot) and the graph
is circular, then a deadlock has occurred. If on the other hand some resources have several
instances, then a deadlock may occur. If the graph is not circular, a deadlock cannot occur (the
46
circular wait condition wouldn’t be satisfied). The following are the tips which will help you to
check the graph easily to predict the presence of cycles:
a) If no cycle exists in the resource allocation graph, there is no deadlock.
b) If there is a cycle in the graph and each resource has only one instance, then there is a
deadlock. In this case, a cycle is a necessary and sufficient condition for deadlock.
c) If there is a cycle in the graph, and each resource has more than one instance, there
may or may not be a deadlock. (A cycle may be broken if some process outside the cycle
has a resource instance that can break the cycle). Therefore, a cycle in the resource
allocation graph is a necessary but not sufficient condition for deadlock, when multiple
resource instances are considered.
Figure 4.3: Resource allocation graph having a cycle and not in a deadlock
The above graph shown in Figure 4.3 has a cycle and is not in deadlock.
(Resource 1 has one instance shown by a star)
(Resource 2 has two instances a and b, shown as two stars)
47
If P1 finishes, P2 can get R1 and finish, so there is no deadlock.
Let’s examine each strategy one by one to evaluate their respective strengths and weaknesses.
ii. Elimination of “Hold and Wait” Condition There are two possibilities for the
elimination of the second condition. The first alternative is that a process request
be granted all the resources it needs at once, prior to execution. The second
alternative is to disallow a process from requesting resources whenever it has
previously allocated resources. This strategy requires that all the resources a
process will need must be requested at once. The system must grant resources on
“all or none” basis. If the complete set of resources needed by a process is not
currently available, then the process must wait until the complete set is available.
While the process waits, however, it may not hold any resources. Thus the “wait
for” condition is denied, and deadlocks simply cannot occur. This strategy can lead
to serious waste of resources.
For example, a program requiring ten tap drives must request and receive all ten
drives before it begins executing. If the program needs only one tap drive to begin
execution and then does not need the remaining tap drives for several hours then
substantial computer resources (nine tape drives) will sit idle for several hours. This
strategy can cause indefinite postponement (starvation), since not all the required
resources may become available at once.
48
may use them to finish their needs. Suppose a system does allow processes to hold
resources while requesting additional resources. Consider what happens when a
request cannot be satisfied. A process holds resources a second process may need
in order to proceed, while the second process may hold the resources needed by
the first process. This a deadlock. This strategy requires that when a process that is
holding some resources is denied a request for additional resources, the process
must release its held resources and, of necessary, request them again together with
additional resources. Implementation of this strategy denies the “no-preemptive”
condition effectively.
b) High Cost When a process releases resources, the process may lose all its work to that
point. One serious consequence of this strategy is the possibility of indefinite
postponement (starvation). A process might be held off indefinitely as it repeatedly
requests and releases the same resources.
i. Elimination of “Circular Wait” Condition The last condition, the circular wait, can be
denied by imposing a total ordering on all of the resource types and then forcing all
processes to request the resources in order (increasing or decreasing). This strategy
imposes a total ordering of all resource types and requires that each process
requests resources in a numerical order of enumeration. With this rule, the
resource allocation graph can never have a cycle. For example, provide a global
numbering of all the resources, as shown in the given Table 4.1.
Rule: Processes can request resources whenever they want to, but all requests must
be made in numerical order. A process may request first printer and then a tape
drive (order: 2,4), but it may not request first a plotter and then a printer (order:
3,2). The problem with this strategy is that may be impossible to find an ordering
that satisfies everyone.
This strategy, if adopted, may result in low resource utilisation and in some cases
starvation is possible too.
49
accordingly. This method differs from deadlock prevention, which guarantees that deadlock
cannot occur by denying one of the necessary conditions of deadlock. The most famous
deadlock avoidance algorithm, from Dijkstra (1965), is the Banker’s algorithm. It is named as
Banker’s algorithm because the process is analogous to that used by a banker in deciding if a
loan can be safely made a not.
The Banker’s Algorithm is based on the banking system, which never allocates its available cash
in such a manner that it can no longer satisfy the needs of all its customers. Here we must have
the advance knowledge of the maximum possible claims for each process, which is limited by
the resource availability. During the run of the system we should keep monitoring the resource
allocation status to ensure that no circular wait condition can exist.
If the necessary conditions for a deadlock are in place, it is still possible to avoid deadlock by
being careful when resources are allocated. The following are the features that are to be
considered for avoidance of the deadlock as per the Banker’s Algorithms.
a) Each process declares maximum number of resources of each type that it may need;
b) Keep the system in a safe state in which we can allocate resources to each process in
some order and avoid deadlock;
c) Check for the safe state by finding a safe sequence: <Pi, P2,...,Pn where resources that
Pi needs can be satisfied by available resources plus resources held by Pj where j < i;
and
d) Resource allocation graph algorithm uses claim edges to check for a safe state.
The resource allocation state is now defined by the number of available and allocated
resources, and the maximum demands of the processes. Subsequently the system can be in
either of the following states:
a) Safe State
Such a state occurs when the system can allocate resources to each process (up to its
maximum) in some order and avoid a deadlock. This state will be characterised by a safe
sequence. It must be mentioned here that we should not falsely conclude that all
unsafe states are deadlocked although it may eventually lead to a deadlock.
b) Unsafe State
If the system did not follow the safe sequence of resource allocation from the beginning
and it is now in a situation, which may lead to a deadlock, then it is in an unsafe state.
c) Deadlock State
If the system has some circular wait condition existing for some processes, then it is in
deadlock state.
Let us study this concept with the help of an example as shown below: Consider an analogy in
which four processes (P1, P2, P3 and P4) can be compared with the customers in a bank,
resources such as printers etc. as cash available in the bank and the operating system as the
Banker.
50
Let us assume that total available resources = 10 In the above table, we see four processes,
each of which has been granted a number of maximum resources that can be used. The
operating system reserved only 10 resources rather than 22 units to service them. At a certain
moment, the situation becomes:
Available resources = 2
Safe State: The key to a state being safe is that there is at least one way for all users to finish. In
other words, the state of Table 4.2 is safe because with 2 units left, the operating system can
delay any request except P3, thus letting P3 finish and release all four resources. With four units
in hand, the Operating system can let either P4 or P2 have the necessary units and so on.
Unsafe State: Consider what would happen if a request from P2 for one more unit was granted
in Table 4.3. We would have following situation as shown in Table 4.4.
Available resources = 1
This is an unsafe state.
51
If all the processes request for their maximum resources respectively, then the operating
system could not satisfy any of them and we would have a deadlock.
Important Note: It is important to note that an unsafe state does not imply the existence or
even the eventual existence of a deadlock. What an unsafe state does imply is simply that some
unfortunate sequence of events might lead to a deadlock.
The Banker’s algorithm is thus used to consider each request as it occurs and see if granting it
leads to a safe state. If it does, the request is granted, otherwise, it is postponed until later.
Haberman [1969] has shown that executing of the algorithm has a complexity proportional to
N2 where N is the number of processes and since the algorithm is executed each time a
resource request occurs; the overhead is significant.
52
deadlock, we stop the process terminations. Though the policy is simple, there are
some problems associated with it.
Consider the scenario where a process is in the state of updating a data file and it is
terminated. The file may be left in an incorrect state by the unexpected termination of
the updating process. Further, processes should be terminated based on some
criterion/policy. Some of the criteria may be as follows:
(i) Priority of a process;
(ii) CPU time used and expected usage before completion;
(iii) Number and type of resources being used (can they be pre-empted easily?);
(iv) Number of resources needed for completion;
(v) Number if processes needed to be terminated; and
(vi) Are the processes interactive or batch?
If a deadlock is detected, one or more processes are restarted from their last
checkpoint. Restarting a process from a checkpoint is called rollback. It is done with the
expectation that the resource requests will not interleave again to produce deadlock.
Deadlock recovery is generally used when deadlocks are rare, and the cost of recovery
(process termination or rollback) is low.
4.7. Summary
A deadlock occurs a process has some resource and is waiting to acquire another resource,
while that resource is being held by some process that is waiting to acquire the resource that is
being held by the first process. A deadlock needs four conditions to occur: Mutual exclusion,
hold and wait, non-preemption and circular waiting. We can handle deadlocks in three major
ways: We can prevent them, handle them when we detect them, or simply ignore the whole
deadlock issue altogether.
53
Banker’s algorithm Checkpointing
Circular waiting Deadlocks
Havender’s algorithm Hold-and-wait
Mutual exclusion Non-preemption Rollback
Reading sources/links
1. Deital, H., M. (1984). An introduction to operating systems. Peterson: Addition Wesley
Publishing Company.
2. Dhamdhere, D., M. (2006). Operating systems: A concept-based approach. New Delhi: Tata
McGraw-Hill.
3. Madnicj, & Donovan. (1974). Operating system - Concepts and design. New York: McGraw-
Hill International Education.
4. Milenkovic, M. (2000). Operating systems: Concept and design. New York: McGrawHill
International Education.
5. Silberschatz, A., & James, L. (1985). Operating system concepts. Peterson: Addition Weslet
Publishing Company.
6. Tanenbaum, A., S., & Woodhull, A., S. (2009). Operating system design and implementation.
UK: Pearson.
5 Topic 5: Memory Management
5.5. Introduction
In the previous units, we have studied about introductory concepts of the OS, process
management and deadlocks. In this unit, we will go through another important function of the
Operating System - the memory management.
Memory is central to the operation of a modern computer system. Memory is a large array of
words or bytes, each location with its own address. Interaction is achieved through a sequence
of reads/writes of specific memory address. The CPU fetches from the program from the hard
disk and stores in memory. If a program is to be executed, it must be mapped to absolute
addresses and loaded into memory.
In a multiprogramming environment, in order to improve both the CPU utilisation and the
speed of the computer’s response, several processes must be kept in memory. There are many
different algorithms depending on the particular situation to manage the memory. Selection of
a memory management scheme for a specific system depends upon many factors, but
especially upon the hardware design of the system. Each algorithm requires its own hardware
support.
The Operating System is responsible for the following activities in connection with memory
management:
a) Keep track of which parts of memory are currently being used and by whom;
b) Decide which processes are to be loaded into memory when memory space becomes
available; and
c) Allocate and deallocate memory space as needed.
54
classified into two categories the primary memory (like cache and RAM) and the secondary
memory (like magnetic tape, disc. etc.). The memory is a resource that needs effective and
efficient management. The part of OS that perform this vital task of memory management is
known as memory manager.
55
For better memory utilisation all modules can be kept on disk in a relocatable format and only
main program is loaded into memory and executed. Only on need the other routines are called,
loaded and address is updated. Such scheme is called dynamic loading, which is user’s
responsibility rather than OS. But Operating System provides library routines to implement
dynamic loading.
In the above discussion, we have seen that entire program and its related data is loaded in
physical memory for execution. But what if process is large than the amount of memory
allocated to it? We can overcome this problem by adopting a technique called as Overlays. Like
dynamic loading, overlays can also be implemented by users without OS support. The entire
program or application is divided into instructions and data sets such that when one instruction
set needed it is loaded in memory and after its execution is over, the space is released. Such
instructions can be called as overlays, which are loaded and unloaded by the program.
Definition: An overlay is a part of an application, which has been loaded at same origin where
previously some other part(s) of the program was residing.
A program based on overlap scheme mainly consists of following:
a) A roof piece which is always memory resident; and
b) Sort of overlays.
Overlay gives the program a way to extend limited main storage. An important aspect related to
overlays identification in program is concept of mutual exclusion i.e., routines which do not
invoke each and not loaded in memory simultaneously. For example, suppose total available
memory is 140K. Consider a program with four subroutines named as: Read ( ),Funtion1 (
),Funtion2 ( ) and Display ( ). First, Read is invoked that reads a set of data. Based on this data
set values, conditionally either one of routine Function1 or Funtion2 is called. And then Display
is called to output results. Here, Funtion1 and Funtion2 are manually exclusive and are not
required simultaneously in memory. The memory requirement can be shown as in Figure 5.1.
Without the overlay it requires 180K of memory and with the overlay support memory
requirement is 130K. Overlay manager/driver is responsible for loading and unloading on
overlay segment as per requirement. But this scheme suffers from following limitations:
56
Swapping
Swapping is an approach for memory management by bringing each process in entirety, running
it and then putting it back on the disk, so that another program may be loaded into that space.
Swapping is a technique that lets you use a disk file as an extension of memory. Lower priority
user processes are swapped to backing store (disk) when they are waiting for I/O or some other
event like arrival of higher priority processes. This is Rollout Swapping. Swapping the process
back into store when some event occurs or when needed (may be in a different partition) is
known as Roll-in swapping. Figure 5.2 depicts techniques of swapping.
Through swapping has these benefits but it has few limitations also like entire program must be
resident in store when it is executing. Also processes with changing memory requirements will
need to issue system calls for requesting and releasing memory. It is necessary to know exactly
how much memory a user process is using and also that it is blocked or swapping for I/O.
57
seen by the process) from PHYSICAL memory (i.e., memory as seen by the processor). Because
of this separation, the programmer needs to be aware of only the logical memory space while
the operating system maintains two or more levels of physical memory space.
Activity 5a
1. Explain the concept of overlays.
2. What is meant by swapping?
In compile-time and load-time address binding schemes these two tend to be the same. These
differ in execution-time address binding scheme and the MMU Memory Management Unit
(MMU) handles translation of these addresses.
Definition: MMU (as shown in the Figure 5.3) is a hardware device that maps logical address to
the physical address. It maps the virtual address to the real store location. The simple MMU
scheme adds the relocation register contents to the base address of the program that is
generated at the time it is sent to memory.
58
Figure 5.5 shows the hierarchical of memory allocation.
59
scheme if the logical address space range is 0 to Max the physical address space range is R+0 to
R+Max (where R is relocation register contents). Similarly, a limit resister is checked by
hardware to be sure that logical address generated by CPU is not bigger than size of the
program.
Initially, whole memory is available for user processes and is like large block of available
memory. Operating System keeps details of available memory block and occupied blocks in
tabular form. OS also keeps track on memory requirements of each process. As processes enter
into the input queue and when sufficient space for it is available, process is allocated space and
loaded. After its execution is over it releases its occupied and OS fills this space with other
processes in input queue. The block of available memory is known as a Hole. Hole of various
sizes are scattered throughout the memory. When any process arrives, it is allocated memory
from a hole that is large enough to accommodate it. This example is shown in Figure 5.8.
60
Within a partition if two holes are adjacent then they can be merged to make a single large
hole. But this scheme suffers from fragmentation problem. Storage fragmentation occurs either
because the user processes do not completely accommodate the allocated the allotted partition
or partition remains unused, if it is too small to hold any process form input queue. Main
memory utilisation is extremely inefficient.
Any program, no matter how small, occupies entire partition. In our example, process B takes
150K of partition2 (200K) size). We are left with 50K sized hole. This phenomenon, in which
there is wasted space internal to a partition, is known as internal fragmentation. It occurs
because initially process is loaded in partition that is large enough to hold it (i.e., allocated
memory that is internal to a partition, but is not in use
Variable-sized Partition:
This scheme is also known as dynamic partitioning. I this scheme, boundaries are not fixed.
Processes accommodate memory according to their requirement. There is no wastage as
partition size is exactly same as the size of the user process. Initially when processes start this
wastage can be avoided but later on when they terminate they leave holes in the main storage.
Other processes can accommodate these, but eventually they become too small to
accommodate new jobs as shown in Figure 5.9.
IBM used this technique for OS/MVT (Multiprogramming with a Variable number of Tasks) as
the partitions are of variable length and number. But still fragmentation anomaly exists in this
scheme. As time goes on and processes are loaded and removed from memory, fragmentation
increase and memory utilisation declines. This wastage of memory, which is external to
partition, is known as external fragmentation. In this, though there is enough total memory to
satisfy a request but as it is not contiguous and it is fragmented into small holes, that can’t be
utilised.
External fragmentation problem can be resolved by coalescing holes and storage compaction.
Coalescing holes is process of merging existing hole adjacent to a process that will terminate
and free its allocated space. Thus, new adjacent holes and existing holes can be viewed as a
single large hole and can be efficiently utilised. There is another possibility that holes are
distributed throughout the memory. For utilising such scattered, shuffle all occupied areas of
memory to one end and leave all free memory space as a single large block, which can further
be utilised. This mechanism is known as Storage Compaction, as shown in Figure 5.10.
61
Figure 5.10: Storage compaction
In a multiprogramming system memory is divided into a number of fixed size or variable sized
partitions or regions, which are allocated to running process. For example: a process needs m
words of memory may run in a partition of n words where n is greater than or equal to m. The
variable size partition scheme may result in a situation where available memory is not
contiguous, but fragmentation and external fragmentation. The difference (n-m) is called
internal fragmentation, memory which is internal to a partition but is not being use. If a
partition is unused and available, but too small to be used by any waiting process, then it is
accounted for external fragmentation. These memory fragments cannot be used.
In order to solve this problem, we can either compact the memory making large free memory
blocks or implement paging scheme which allows a program’s memory to be non-contiguous,
thus permitting a program to be allocated physical memory wherever it is available.
Activity 5b
1. What are the four important tasks of a memory manager?
2. What are the three tricks used to resolve absolute addresses?
3. What are the problems that arise with absolute addresses in terms of
swapping?
4. Briefly explain:
(a) Single-partition system
(b) Multiple-partition system
5. List three limitations of the storage compaction.
5.11. Paging
We will see the principles of operation of the paging in the next section. Paging scheme solves
the problem faced in variable sized partitions like external fragmentation.
62
In a paged system, logical memory is divided into a number of fixed sizes chunks’ called pages.
The physical memory is also pre-divided into same fixed sized blocks (as is the size of pages)
called page frames. The pages sizes (also the frame sizes) are always powers of 2 and vary
between 512 bytes to 8192 bytes per page. The reason behind this is implementation of paging
mechanism using page offset. This is discussed in detail in the following sections. Each process
page is loaded to some memory frame. These pages can be loaded into contiguous frames in
memory or into non-contiguous frames also as shown in Figure 5.11. The external
fragmentation is alleviated since processes are loaded into separate holes.
Now, question arises which strategy is likely to be used? In practice, best-fit and first-fit are
better than worst-fit. Both these are efficient in terms of time and storage requirement. Best-fit
on the other hand requires least overheads in its implementation because of its simplicity.
Possibly worst-fit also sometimes leaves large holes that could further be used to accommodate
other processes. Thus, all these policies have their own merits and demerits.
63
This is known as Address Translation scheme. For example, a 16-bit address can be divided as
given in Figure 5.12.
Here, as page number takes 5bits, so range of values is 0 to 31(i.e. 25 - 1). Similarly, offset value
uses 11-bits, so range is 0 to 2023 (i.e., 211 - 1). Summarizing this we can say paging scheme
uses 32 pages, each with 2024 locations.
The table, holds virtual address to physical address translations, is called the page table. As
displacement is constant, so only translation of virtual page number to physical page is
required. This can be seen diagrammatically in Figure 5.12.
Page number is used as an index into a page table and the latter contains base address of each
corresponding physical memory page number (Frame). This reduces dynamic relocation efforts.
The Paging hardware support is shown diagrammatically in Figure 5.13.
64
This is the case of direct mapping as page table sends directly to physical memory page. This is
shown in Figure 5.14. But disadvantage of this scheme is its speed of translation. This is because
page table is kept in primary storage and its size can be considerably large which increases
instruction execution time (also access time) and hence decreases system speed. To overcome
this additional hardware support of registers and buffers can be used. This is explained in next
section.
It is similar to direct mapping scheme but here as TLB’s contain only few page table entries, so
search is fast. But it is quite expensive due to register support. So, both direct and associative
mapping scheme can also be combined to get more benefits. Here, page number is matched
with all associative registers simultaneously, the percentage of the number of times the page is
found in TLB’s is called hit ration. If it is not found, it is searched in page table and added into
TLB. But if TLB is already full then page replacement policies can be used. Entries in TLB can be
limited only. This combined scheme is shown in Figure 5.15.
65
be controlled to protect modification and accessing data in one process by another process. For
this program are kept separately as procedures and data, share procedures and data that are
non-modifiatable (pure/reentrant code) can be shared. Reentrant code cannot modify itself and
must make sure that it has a separate copy of per-process global variable. Modifiable
procedures are also known as pure procedures or reentrant codes (can’t change during
execution). For example, only one copy of editor or compiler code can be kept in memory, and
all editor or compiler processes can execute that single copy of the code. This helps memory
utilisation. Major advantages of paging scheme are:
(a) Virtual address space must be greater than main memory size i.e., can execute program
with large logical address space as compared with physical address space;
(b) Avoid external fragmentation and hence storage compaction; and
(c) Full utilisation of available main storage.
Disadvantages of paging include internal fragmentation problem i.e., wastage within allocated
page when process is smaller than page boundary. Also, extra resource consumption and
overheads for paging hardware and virtual address to physical address translation takes place.
Activity 5c
1. Why do Operating System employ paging?
2. What is the different between paging address transalation by direct mapping
and with association mapping?
5.12. Segmentation
In the earlier section we have seen the memory management scheme called as paging. In
general, a user or a programmer prefers to view system memory as a collection of variable-sized
segment rather than as a linear array of words. Segmentation is a memory management
scheme that supports this view of memory.
66
Figure 5.16: Address translation
The offset d must range between 0 and segment limit/length, otherwise it will generate address
error. For example, consider situation shown in Figure 5.17.
This scheme is similar to variable partition allocation method with improvement that the
process is divided into parts. For fast retrieval we can use registers as paged scheme. This is
known as a segment-table length register (STLR). The segments in a segmentation scheme
correspond to logical division of the process and are defined by program names. Extract the
segment number and offset from logical from logical address first. Then use segment number as
index into segment table to obtain segment base address and its limit/length. Also, check that
the offset is not greater than given limit in segment table. Now, general physical address is
obtained by adding the offset to the base address.
67
Sharing of segments can be done by making common/same entries in segment tables of two
different processes which point to same physical location. Segmentation may suffer from
external fragmentation i.e., when blocks of free memory are not enough to accommodate a
segment. Storage compaction and coalescing can minimise this drawback.
Activity 5d
1. What is the advantage of using Base and Limit registers?
2. How does lookup work with TLB’s? (c) Why is page size always powers of 2?
3. A system with 18-bit address uses 6 bits for page number and next 12 bits for
offset. Compare the total number of pages and express the following address
according to paging scheme 001011 (page number) and 000000111000
(offset)?
5.13. Summary
In this unit, we have learnt memory resource is managed and how processes are protected from
each other. The previous two sections covered memory allocation techniques like swapping and
overlays, which tackle the utilisation of memory. Paging and segmentation was presented as
memory management schemes. Both have their own merits and demerits. We have also seen
how paging is based on physical form of process and is independent of the programming
structures, while segmentation is dependent on logical structure of process as viewed by user.
We have also considered level of fragmentation (internal and external) problems and ways to
tackle them to increase level of multiprogramming and system efficiency. Concept of relocation
and compaction helps to overcome external fragmentation.
Reading sources/links
1. Deital, H., M. (1984). An introduction to operating systems. Peterson: Addition Wesley
Publishing Company.
2. Ritchie, C. (2003). Operating system incorporation UNIX and Windows (4th ed.). New Delhi:
BPB Pulbication.
3. Silberschatz, A., & Galvin, P. B. (1997). Operating system concepts. (5th ed.). New Delhi:
Wiley and Sons (Asia) Publication.
4. Tanenbaum, A., S., & Woodhull, A., S. (2009). Operating system design and implementation.
UK: Pearson.
7 Topic 6…………………………………………………………………………………………………………………………………….
Introduction
68
6.2. Sub topic 2
Reading sources/links
7 Topic 7…………………………………………………………………………………………………………………………………….
7.1. Introduction
Reading sources/links
MODULE SUMMARY/CONCLUSION
4 PRACTICUUM
5 REVISION
6 EXAMINATION
Lbh/ps/ns/202
69