Operating System
Operating System
Operating Systems
Contents
Unit 1
Operating System- An Introduction 1
Unit 2
Process Management 18
Unit 3
CPU Scheduling Algorithms 37
Unit 4
Process Synchronization 63
Unit 5
Introduction to Deadlocks 84
Unit 6
Memory Management 109
Unit 7
Virtual Memory 129
Unit 8
File System Interface and Implementation 147
Unit 9
Operating Systems in Distributed Processing 168
Unit 10
Security and Protection 188
Unit 11
Multiprocessor Systems 207
References 224
Prof.V.B.Nanda Gopal
Director & Dean
Directorate of Distance Education
Sikkim Manipal University of Health, Medical & Technological Sciences (SMU DDE)
Board of Studies
Dr.U.B.Pavanaja (Chairman) Nirmal Kumar Nigam
General Manager – Academics HOP- IT
Manipal Universal Learning Pvt. Ltd. Sikkim Manipal University – DDE
Bangalore. Manipal.
Prof.Bhushan Patwardhan Dr.A.Kumaran
Chief Academics Research Manager (Multilingual)
Manipal Education Microsoft Research Labs India
Bangalore. Bangalore.
Dr.Harishchandra Hebbar Ravindranath.P.S.
Director Director (Quality)
Manipal Centre for Info. Sciences Yahoo India
Manipal Bangalore.
Dr.N.V.Subba Reddy Dr.Ashok Kallarakkal
HOD-CSE Vice President
Manipal Institute of Technology IBM India
Manipal Bangalore.
Dr.Ashok Hegde H.Hiriyannaiah
Vice President Group Manager
MindTree Consulting Ltd. EDS Mphasis
Bangalore Bangalore
Dr.Ramprasad Varadachar
Director, Computer Studies
Dayanand Sagar College of Engg.
Bangalore.
Content Preparation Team
Content Writing Content Editing
Mr. Vinayak G. Pai Dr. E.R Naganathan
Asst Professor – IT Professor and Head– IT
Sikkim Manipal University –DDE Sikkim Manipal University – DDE, Manipal
Manipal
Language Editing
Prof. Sojan George
Sr. Lecturer– English
M.I.T
Manipal
Edition: Spring 2009
This book is a distance education module comprising a collection of learning material for our
students. All rights reserved. No part of this work may be reproduced in any form by any
means without permission in writing from Sikkim Manipal University of Health, Medical and
Technological Sciences, Gangtok, Sikkim. Printed and published on behalf of Sikkim
Manipal University of Health, Medical and Technological Sciences, Gangtok, Sikkim by
Mr.Rajkumar Mascreen, GM, Manipal Universal Learning Pvt. Ltd., Manipal – 576 104.
Printed at Manipal Press Limited, Manipal.
BLOCK INTRODUCTION
Unit 6 : Memory Management : This unit speaks about logical v/s physical
address space, swapping, contiguous allocation, paging and segmentation.
Unit 7 : Virtual Memory : This unit speaks about need for virtual Memory,
Demand Paging, different page Replacement Algorithm and Thrashing.
Unit 8 : File Systems Interface and Implementation : This unit speaks
about Concept of file, different file access methods, directory structures,
allocation methods, free space management and directory implementation.
Structure
1.1 Introduction
Objectives
1.2 Definition and functions of Operating System
1.3 Evolution of Operating Systems
Simple Batch Operating Systems
Multi-programmed Batched Operating Systems
Time- Sharing operating Systems
Personal Computer Operating Systems
Multi-processor Operating Systems
Distributed Systems
Real-Time Systems
1.4 Operating system structures
Layered approach
The kernel based approach
The virtual machine approach
1.5 Summary
1.6 Terminal Questions
1.7 Answers
1.1 Introduction
Computer software can be divided into two main categories: application
software and system software. An application software consists of the
programs for performing tasks particular to the machine's utilization.
Examples of application software include spreadsheets, database systems,
desktop publishing systems, program development software and games.
Application software is generally what we think of when someone speaks of
computer programs. This software is designed to solve a particular problem
for users.
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.
Objectives:
At the end of this unit, you will be able to understand:
Definition and functions of Operating System
Evolution of operating systems and
Operating system structures.
period of time, starting from the very primitive systems to the present day
complex and versatile ones. A brief description of the evolution of operating
systems has been described below .
Operating
system
User
area
To speed up processing, jobs with the same needs were batched together
and executed as a group. For example, all FORTRAN jobs were batched
together for execution; all COBOL jobs were batched together for execution
and so on. Thus batch operating systems came into existence .
Spooling overlaps I/O of one job with the computation of other jobs. For
example, spooler may be reading the input of one job while printing the
output of another and executing a third job (Figure 1.2).
Disk
I/O
Figure1.2: Spooling
Spooling increases the performance of the system by allowing both a faster
CPU and slower I/O devices to work at higher operating rates.
Operating
system
Job 1
Job 2
User area
Job 3
User area
Job 4
User area
Figure 1.3: Memory layout for multi-programmed system
User area
CPU scheduling and multi-programming provide each user one time slice
(slot) in a time-shared system. A program in execution is referred to as a
process. A process executes for one time slice at a time. A process may
need more than one time slice to complete. During a time slice a process
may finish execution or go for an I/O. The I/O in this case is usually
interactive like a user response from the keyboard or a display on the
monitor. The CPU switches between processes at the end of a time slice.
The switching between processes is so fast that the user gets the illusion
that the CPU is executing only one user’s process.
The operating system of PCs consists of two parts. One part is called the
BIOS (Basic Input Output system) which is stored in a ROM (Read Only
Memory). The other part called the DOS (Disk Operating System) is stored
in a floppy disk or a hard disk.
BIOS provides basic low level services where as DOS provides many user-
level services. The major services provided by DOS are:
File management which allows user to create , edit, read, write and
delete files.
There are several reasons for building such systems. One advantage is
increased throughput. By increasing the number of processors, we can get
more work done in a shorter time.
processors then the failure of one processor will not halt the system, but
rather will only slow it down. If we have 10 processors and one fails, then
each of the remaining nine processors must share the work of the failed
processor. Thus the entire system runs only 10 percent slower, rather than
failing together.
There are variety of reasons for building distributed systems, the major ones
are :
Resource sharing. If different user are connected to one another with
different resources, then the user at one site may be able to use the
resources available at another.
The layered approach has all the advantages of modular design. In modular
design, the system is divided into several modules and each module is
designed independently. Likewise in layered approach each layer can be
designed, coded and tested independently. Consequently the layered
approach considerably simplifies the design, specification and
implementation of an operating system. However, a drawback of the layered
A user can also run a single user operating system on this virtual machine.
The design of such a single user operating system can be very simple and
efficient because it does not have to deal with the complications that arise
due to multi-programming and protection. The virtual machine concept
provides higher flexibility in that it allows different operating systems to run
on different virtual machines. The efficient implementation of virtual machine
software (e.g. VM/370 ), however , is a very difficult problem because virtual
machine is huge and complex.
A classical example of this system is the IBM 370 system wherein the virtual
machine software VM/370, provides a virtual machine to each user. When
user logs on, VM/370 creates a new virtual machine (i.e a copy of the bare
hardware of the IBM 370 system) for the user.
1.5 Summary
An operating system is a collection of programs that is an intermediary
between a user and the computer hardware. It performs various functions
such as process management, input output management, file management,
managing use of main memory, providing security to user jobs and files etc.
2.1 Introduction
Current day computer system allows multiple programs to be loaded into
memory and to be executed concurrently. This evolution requires more
coordination and firmer control of the various programs. These needs
resulted in the notion of a process. A Process can be simply defined as a
program in execution. A process is created and terminated, and it allows
Thread is single sequence stream which allows a program to split itself into
two or more simultaneously running tasks. Threads and processes differ
from one operating system to another but in general, a thread is contained
inside a process and different threads in the same process share some
resources while different processes do not. An operating system that has
thread facility, the basic unit of CPU utilization, is a thread. A thread has or
consists of a program counter (PC), a register set, and a stack space.
Threads are not independent of one other like processes as a result threads
share with other threads their code section, data section, OS resources
also known as task, such as open files and signals.
Objectives:
At the end of this unit, you will be able to understand:
Locally, the ‘Running’ and ‘Ready’ states are similar. In both cases the
process is willing to run, only in the case of ‘Ready’ state, there is
temporarily no CPU available for it. The ‘Blocked’ state is different from the
‘Running’ and ‘Ready’ states in that the process cannot run, even if the CPU
is available.
These above states are arbitrary and very between operating systems.
Certain operating systems also distinguish among more finely delineating
process states. It is important to realize that only one process can be
running on any processor at any instant. Many processes may be ready and
waiting. A state diagram (Figure 2.1) is used to diagrammatically represent
the states and also the events that trigger the change of state of a process
in execution.
Terminated
New
Ready Running
Dispatch
Memory limits
List of open files
. . ..
As a process enters the system, it joins a job queue that is a list of all
processes in the system. Some of these processes are in the ready state
and are waiting for the CPU for execution. These processes are present in a
ready queue. The ready queue is nothing but a list of PCB’s implemented as
a linked list with each PCB pointing to the next.
There are also some processes that are waiting for some I/O operation like
reading from a file on the disk or writing onto a printer. Such processes are
present in device queues. Each device has its own queue.
A new process first joins the ready queue. When it gets scheduled, the CPU
executes the process until-
1. an I/O occurs and the process gives up the CPU to join a device queue
only to rejoin the ready queue after being serviced for the I/O.
2. it gives up the CPU on expiry of its time slice and rejoins the ready
queue.
Every process is in this cycle until it terminates (Figure 2.3). Once a process
terminates, entries for this process in all the queues are deleted. The PCB
and resources allocated to it are released.
2.5.1 Schedulers
At any given instant of time, a process is in any one of the new, ready,
running, waiting or terminated state. Also a process moves from one state to
another as long as it is active. The operating system scheduler schedules
processes from the ready queue for execution by the CPU. The scheduler
selects one of the many processes from the ready queue based on certain
criteria.
Medium-term scheduler
Many jobs could be ready for execution at the same time. Out of these more
than one could be spooled onto the disk. The long-term scheduler or job
scheduler as it is called picks and loads processes into memory from among
the set of ready jobs. The short-term scheduler or CPU scheduler selects a
process from among the ready processes to execute on the CPU.
A long-term scheduler executes less frequently since new processes are not
created at the same pace at which processes need to be executed. The
number of processes present in the ready queue determines the degree of
multi-programming. So the long-term scheduler determines this degree of
multi-programming. If a good selection is made by the long-term scheduler
in choosing new jobs to join the ready queue, then the average rate of
process creation must almost equal the average rate of processes leaving
the system. The long-term scheduler is thus involved only when processes
leave the system to bring in a new process so as to maintain the degree of
multi-programming.
Choosing one job from a set of ready jobs to join the ready queue needs
careful selection. Most of the processes can be classified as either I/O
bound or CPU bound depending on the time spent for I/O and time spent for
CPU execution. I/O bound processes are those which spend more time
executing I/O whereas CPU bound processes are those which require more
CPU time for execution. A good selection of jobs by the long-term scheduler
will give a good mix of both CPU bound and I/O bound processes. In this
case, the CPU as well as the I/O devices will be busy. If this is not to be so,
then either the CPU is busy and I/O devices are idle or vice-versa. Time
sharing systems usually do not require the services of a long-term scheduler
since every ready process gets one time slice of CPU time at a time in
rotation.
doing any useful work. Context switch time varies from machine to machine
depending on speed, the amount of saving and loading to be done,
hardware support and so on.
Process P0 Operating system Process P1
Executing
Interrupt
Executing
Interrupt
Executing
There are also two possibilities in terms of the address space of the new
process, the first possibility is,
The child process is a duplicate of the parent process.
An example for this is UNIX operating system in which each process is
identified by its process identifier, which is a unique integer. A new
process is created by the fork system call. The new process consists of
a copy of the address space of the original process. This mechanism
allows the parent process to communicate easily with its child process.
Only a parent process can cause termination of its children via abort system
call. For that a parent needs to know the identities of its children. When one
process creates a new process, the identity of the newly created process is
passed to the parent.
A parent may terminate the execution of one of its children for a variety of
reasons, such as:
The child has exceeded its usage of some of the resources that it has
been allocated.
The task assigned to the child is no longer required.
The parent is exiting, and the operating system does not allow a child to
continue if its parent terminates.
call and its parent process may wait for that event by using the wait system
call. The wait system call returns the process identifier of a terminated child,
so the parent can tell which of the possibly many children has terminated. If
the parent terminates, however all the children are terminated by the
operating system. Without a parent, UNIX does not know whom to report
the activities of a child.
2.8 Threads
What is Thread ?
Thread is a single sequence stream which allows a program to split itself
into two or more simultaneously running tasks. It is a basic unit of CPU
utilization, and consists of a program counter, a register set and a stack
space. Because threads have some of the properties of processes, they are
sometimes called lightweight processes. In a process, threads allow
multiple executions of streams. Threads are not independent of one other
like processes. As a result threads shares with other threads their code
section, data section, OS resources also known as task, such as open files
and signals.
2. Because threads can share common data, they do not need to use
interprocess communication.
3. Because of the very nature, threads can take advantage of
multiprocessors.
Advantages:
The most obvious advantage of this technique is that a user-level threads
package can be implemented on an Operating System that does not support
threads. Some other advantages are:
User-level threads does not require modification to operating systems.
Simple Representation:
Each thread is represented simply by a PC, registers, stack and a small
control block, all stored in the user process address space.
Simple Management:
This simply means that creating a thread, switching between threads
and synchronization between threads can all be done without
intervention of the kernel.
Fast and Efficient:
Thread switching is not much more expensive than a procedure call.
Sikkim Manipal University Page No. 32
Operating Systems Unit 2
Disadvantages:
There is a lack of coordination between threads and operating system
kernel. Therefore, process as whole gets one time slice irrespective of
whether process has one thread or 1000 threads within. It is up to each
thread to relinquish control to other threads.
Advantages:
Because kernel has full knowledge of all threads, Scheduler may decide
to give more time to a process having large number of threads than
process having small number of threads.
Kernel-level threads are especially good for applications that frequently
block.
kernel routines can be multi-threaded
Disadvantages:
The kernel-level threads are slow and inefficient. For instance, threads
operations are hundreds of times slower than that of user-level threads.
2.9 Summary
A process is a program in execution. As process executes, it changes it
state. Each process may be in one of the following states: New, Ready,
Running, Waiting, or Halted. Each process is represented in the operating
system by its own process control block(PCB). The PCB serves as a
repository of information about a process and varies from process to
process.
The process in the system can execute concurrently. There are several
reasons for allowing concurrent execution; information sharing, computation
speedup, modularity, and convenience. The processes executing in the
4. Because threads can share common data, they do not need to use
_______________.
5. Co-operating processes that directly share a logical address space can
be implemented as ___________________.
Structure
3.1 Introduction
Objectives
3.2 Basic Concepts of Scheduling.
CPU-I/O Burst Cycle.
CPU Scheduler.
Preemptive/non preemptive scheduling.
Dispatcher
Scheduling Criteria
3.3 Scheduling Algorithms
First come First Served Scheduling
Shortest-Job-First Scheduling
Priority Scheduling.
Round-Robin Scheduling
Multilevel Queue Scheduling
Multilevel Feedback Queue Scheduling
Multiple-Processor Scheduling
Real-Time Scheduling
3.4 Evaluation of CPU Scheduling Algorithms.
Deterministic Modeling
Queuing Models
Simulations
Implementation
3.5 Summary
3.6 Terminal Questions
3.7 Answers
3.1 Introduction
The CPU scheduler selects a process from among the ready processes to
execute on the CPU. CPU scheduling is the basis for multi-programmed
operating systems. CPU utilization increases by switching the CPU among
ready processes instead of waiting for each process to terminate before
executing the next.
Objectives:
At the end of this unit, you will be able to understand:
the execution. An I/O bound job will have short CPU bursts and a CPU
bound job will have long CPU bursts.
:
:
Load memory
Add to memory CPU burst
Read from file
Wait for I/O I/O burst
Load memory
Make increment CPU burst
Write into file
I/O burst
Wait for I/O
Load memory
Add to memory CPU burst
Read from file
Note that the ready queue is not necessarily a first-in, first-out (FIFO) queue.
As we shall see when we consider the various scheduling algorithms, a
ready queue may be implemented as a FIFO queue, a priority queue, a tree,
Sikkim Manipal University Page No. 39
Operating Systems Unit 3
Some operating systems, including most versions of UNIX, deal with this
problem by waiting either for a system call to complete, or for an I/O block to
take place, before doing a context switch. This scheme ensures that the
kernel structure is simple, since the kernel will not preempt a process while
the kernel data structures are in an inconsistent state. Unfortunately, this
kernel execution model is a poor one for supporting real-time computing and
multiprocessing.
3.2.4 Dispatcher
Another component involved in the CPU scheduling function is the
dispatcher. The dispatcher is the module that gives control of the CPU to the
process selected by the short-term scheduler. This function involves:
Switching context
Switching to user mode
Jumping to the proper location in the user program to restart that
program
Even though the algorithm is simple, the average waiting is often quite long
and varies substantially if the CPU burst times vary greatly, as seen in the
following example.
P1 P2 P3
0 24 27 30
If the processes arrive in the order P2, P3 and P3, then the result will be as
follows:
P2 P3 P1
0 3 6 30
Thus, if processes with smaller CPU burst times arrive earlier, then average
waiting and average turnaround times are lesser.
The algorithm also suffers from what is known as a convoy effect. Consider
the following scenario. Let there be a mix of one CPU bound process and
many I/O bound processes in the ready queue.
The CPU bound process gets the CPU and executes (long I/O burst).
In the meanwhile, I/O bound processes finish I/O and wait for CPU, thus
leaving the I/O devices idle.
The CPU bound process releases the CPU as it goes for an I/O.
I/O bound processes have short CPU bursts and they execute and go for
I/O quickly. The CPU is idle till the CPU bound process finishes the I/O and
gets hold of the CPU.
The above cycle repeats. This is called the convoy effect. Here small
processes wait for one big process to release the CPU.
P4 P1 P3 P2
0 3 9 16 24
The SJF algorithm produces the most optimal scheduling scheme. For a
given set of processes, the algorithm gives the minimum average waiting
and turnaround times. This is because, shorter processes are scheduled
earlier than longer ones and hence waiting time for shorter processes
decreases more than it increases the waiting time of long processes.
The main disadvantage with the SJF algorithm lies in knowing the length of
the next CPU burst. In case of long-term or job scheduling in a batch system,
the time required to complete a job as given by the user can be used to
schedule. SJF algorithm is therefore applicable in long-term scheduling.
But the SJF scheduling algorithm is provably optimal and thus serves as a
benchmark to compare other CPU scheduling algorithms.
Given below are the arrival and burst times of four processes P1, P2, P3
and P4.
Process Arrival time (msecs) Burst time (msecs)
P1 0 8
P2 1 4
P3 2 9
P4 3 5
If SJF preemptive scheduling is used, the following Gantt chart shows the
result.
P1 P2 P4 P1 P3
0 1 5 10 17 26
P1 P2 P4 P3
0 8 12 17 26
P2 P5 P1 P3 P4
0 1 6 16 18 19
Average waiting time = (6 + 0 + 16 + 18 + 1) / 5 = 41 / 5 = 8.2 msecs.
is preempted and CPU allocated to the new process. But in case of non-
preemptive algorithm, the new process having highest priority from among
the ready processes, is allocated the CPU only after the current process
gives up the CPU.
The ready queue in this case is a FIFO queue with new processes joining
the tail of the queue. The CPU scheduler picks processes from the head of
the queue for allocating the CPU. The first process at the head of the queue
gets to execute on the CPU at the start of the current time slice and is
deleted from the ready queue. The process allocated the CPU may have the
current CPU burst either equal to the time slice or smaller than the time slice
or greater than the time slice. In the first two cases, the current process will
release the CPU on its own and thereby the next process in the ready
queue will be allocated the CPU for the next time slice. In the third case, the
current process is preempted, stops executing, goes back and joins the
ready queue at the tail thereby making way for the next process.
Consider the same example explained under FCFS algorithm.
Process Burst time (msecs)
P1 24
P2 3
P3 3
Let the duration of a time slice be 4 msecs, which is to say CPU
switches between processes every 4 msecs in a round-robin fashion. The
Gantt chart below shows the scheduling of processes.
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Average waiting time = (4 + 7 + (10 – 4)) / 3 = 17/ 3 = 5.66 msecs.
If there are 5 processes in the ready queue that is n = 5, and one time slice
is defined to be 20 msecs that is q = 20, then each process will get 20
msecs or one time slice every 100 msecs. Each process will never wait for
more than (n – 1) x q time units.
The performance of the RR algorithm is very much dependent on the length
of the time slice. If the duration of the time slice is indefinitely large then the
RR algorithm is the same as FCFS algorithm. If the time slice is too small,
then the performance of the algorithm deteriorates because of the effect of
frequent context switching. A comparison of time slices of varying duration
and the context switches they generate on only one process of 10 time units
is shown below..
Process Time= 10
Quantum Context
switch
12 0
0 10
6 1
0 6 10
1 9
0 1 2 3 4 5 6 7 8 9 10
The above example shows that the time slice should be large with respect to
the context switch time, else, if RR scheduling is used the CPU will spend
more time in context switching.
Queues themselves have priorities. Each queue has absolute priority over
low priority queues, that is a process in a queue with lower priority will not
be executed until all processes in a queue with higher priority have finished
executing. If a process in a lower priority queue is executing (higher priority
queues are empty) and a process joins a higher priority queue, then the
executing process is preempted to make way for a process in the higher
priority queue.
If several identical processors are available, then load sharing can occur. It
would be possible to provide a separate queue for each processor. In this
case, however one processor could be idle, with an empty queue, while
another processor was very busy. To prevent this situation, we use a
common ready queue. All processes go into one queue and are scheduled
onto any available processor.
Some systems carry this structure one step further, by having all scheduling
decisions, I/O processing, and other system activities handled by one single
processor- the master server. The other processors only execute user code.
This asymmetric multiprocessing is far simpler than symmetric
multiprocessing, because only one processor accesses the system data
structures, alleviating the need for data sharing.
Real-time computing is divided into two types. Hard real-time systems and
soft real-time systems. Hard real time systems are required to complete a
critical task within a guaranteed amount of time. A process is submitted
along with a statement of the amount of time in which it needs to complete
or perform I/O. The scheduler then either admits the process, guaranteeing
that the process will complete on time, or rejects the request as impossible.
This is known as resource reservation. Such a guarantee requires that the
scheduler knows exactly how long each type of operating system function
takes to perform, and therefore each operation must be guaranteed to take
a maximum amount of time. Such a guarantee is impossible in a system
with secondary storage or virtual memory, because these subsystems
cause unavoidable and unforeseeable variation in the amount of time to
execute a particular process. Therefore, hard real-time systems are
composed of special purpose software running on hardware dedicated to
their critical process, and lack the functionality of modern computers and
operating systems.
Once the selection criteria have been defined, we use one of the
following different evaluation methods.
The average waiting times for FCFS, SJF, and RR are 28ms, 13ms, and
23ms respectively. Deterministic modeling is fast and easy, but it requires
specific known input, and the results only apply for that particular set of input.
However, by examining multiple similar cases, certain trends can be
observed. (Like the fact that for processes arriving at the same time, SJF
will always yield the shortest average wait time.)
average arrival of new jobs in the queue of Lambda, the these three terms
can be related by:
N = Lambda * W
3.4.3 Simulations
Another approach is to run computer simulations of the different proposed
algorithms (and adjustment parameters) under different load conditions, and
to analyze the results to determine the "best" choice of operation for a
particular load pattern. Operating conditions for simulations are often
randomly generated using distribution functions similar to those described
above. A better alternative when possible is to generate trace tapes, by
monitoring and logging the performance of a real system under typical
expected work loads. These are better because they provide a more
accurate picture of system loads, and also because they allow multiple
simulations to be run with the identical process load, and not just statistically
equivalent loads. A compromise is to randomly determine system loads and
then save the results into a file, so that all simulations can be run against
identical randomly determined system loads.
Although trace tapes provide more accurate input information, they can be
difficult and expensive to collect and store, and their use increases the
complexity of the simulations significantly. There are also some questions
as to whether the future performance of the new system will really match the
past performance of the old system. (If the system runs faster, users may
take fewer coffee breaks, and submit more processes per hour than under
the old system. Conversely if the turnaround time for jobs is longer,
intelligent users may think more carefully about the jobs they submit rather
than randomly submitting jobs and hoping that one of them works out.)
3.4.4 Implementation
Implementation
The only real way to determine how a proposed scheduling algorithm is
going to operate is to implement it on a real system. For experimental
algorithms and those under development, this can cause difficulties and
resistances among users who don't care about developing OS’s and are
only trying to get their daily work done. Even in this case, the measured
results may not be definitive, for at least two major reasons: (1) System
workloads are not static, but change over time as new programs are
installed, new users are added to the system, new hardware becomes
available, new work projects get started, and even societal changes. (For
example the explosion of the Internet has drastically changed the amount of
network traffic that a system sees and the importance of handling it with
Most modern systems provide some capability for the system administrator
to adjust scheduling parameters, either on the fly or as the result of a reboot
or a kernel rebuild.
3.5 Summary
In this chapter we have discussed CPU scheduling. The long-term
scheduler provides a proper mix of CPU-I/O bound jobs for execution. The
short-term scheduler has to schedule these processes for execution.
Scheduling can either be preemptive or non-preemptive. If preemptive, then
an executing process can be stopped and returned to ready state to make
the CPU available for another ready process. But if non-preemptive
scheduling is used then a process once allotted the CPU keeps executing
until either the process goes into wait state because of an I/O or it has
completed execution. Different scheduling algorithms have been discussed.
quantum. After q time units, if the process has not relinquished the CPU, it is
preempted and the process is put at the tail of the ready queue.
2. The time taken by the Dispatcher to stop one process and start another
running is known as _________________.
Structure
4.1 Introduction
Objectives
4.2 Interprocess Communication
Basic Structure
Naming
Direct Communication
Indirect Communication
Buffering
4.3 The Critical-section problem
Two Process Solution
Algorithm1
Algorithm 2
Algorithm 3
Multiple Process Solutions
4.4 Semaphores
4.5 Monitors
4.6 Hardware Assistance
4.7 Summary
4.8 Terminal Questions
4.9 Answers
4.1 Introduction
A co-operating process is one that can affect or be affected by the other
processes executing in the system. These processes may either directly
share a logical address space (that is, both code and data), or be allowed to
share data only through files. Concurrent access to shared data may result
in data inconsistency. Maintaining data consistency requires mechanism to
Sikkim Manipal University Page No. 63
Operating Systems Unit 4
Objectives:
At the end of this unit, you will be able to understand:
About Interprocess Communication, Critical Section Problem , Two process
and Multiple Process solution for the Critical Section problem, about
Semaphores , monitors and Hardware Assistance for Mutual Exclusion .
facility provides at least the two operations: send (message) and receive
(message).
receive, but not both, and each link has at least one receiver process
connected to it.
In addition, there are several methods for logically implementing a link and
the send/receive operations:
Direct or indirect communication
Symmetric or asymmetric communication
Automatic or explicit buffering
Send by copy or send by reference
Fixed-sized or variable-sized messages
4.2.2 Naming
Processes that want to communicate must have a way to refer to each other.
They can use either direct communication or indirect communication, as we
shall discuss in the next two subsections.
repeat
.....
produce an item in nextp
.....
send ( consumer, nextp );
until false;
This scheme exhibits a symmetry in addressing; that is, both the sender and
the receiver processes have to name each other to communicate. A variant
of this scheme employs asymmetry in addressing. Only the sender names
the recipient; the recipient is not required to name the sender. In this
scheme, the send and receive primitives are defined as follows:
send (p, message). Send a message to process P.
receive (id, message). Receive a message from any process; the
variable id is set to the name of the process with which communication
has taken place.
Now suppose that processes P1, P2, and P3 all share mailbox A. Process P1
sends a message to A, while P2 and P3 each execute a receive from A.
Which process will receive the message sent by P1 ? This question can be
resolved in a variety of ways:
Allow a link to be associated with at most two processes.
Allow at most one process at a time to execute a receive operation.
Allow the system to select arbitrarily which process will receive the
message (that is, either P2 or P3, but not both, will receive the message).
The system may identify the receiver to the sender.
There are various ways to designate the owner and users of a particular
mailbox. One possibility is to allow a process to declare variables of type
mailbox. The process that declares a mailbox is that mailbox's owner. Any
other process that knows the name of this mailbox can use this mailbox.
On the other hand, a mailbox that is owned by the operating system has an
existence of its own. It is independent, and is not attached to any particular
process. The operating system provides a mechanism that allows a
process:
To create a new mailbox
To send and receive messages through the mailbox
To destroy a mailbox
The process that creates a new mailbox is that mailbox's owner by default.
Initially, the owner is the only process that can receive messages through
this mailbox. However, the ownership and receive privilege may be passed
to other processes through appropriate system calls. Of course, this
provision could result in multiple receivers for each mailbox. Processes may
also share a mailbox through the process-creation facility. For example, if
4.2.3 Buffering
A link has some capacity that determines the number of messages that can
reside in it temporarily. This property can be viewed as a queue of
messages attached to the link. Basically, there are three ways that such a
queue can be implemented:
Zero capacity: The queue has maximum length 0; thus, the link cannot
have any messages waiting in it. In this case, the sender must wait until
the recipient receives the message. The two processes must be
synchronized for a message transfer to take place. This synchronization
is called a rendezvous.
Bounded capacity: The queue has finite length n; thus, at most n
messages can reside in it. If the queue is not full when a new message
is sent, the latter is placed in the queue (either the message is copied or
a pointer to the message is kept), and the sender can continue
execution without waiting. However, the link has a finite capacity. If the
link is full, the sender m1, must be delayed until space is available in the
queue.
Unbounded capacity: The queue has potentially infinite length; thus,
any number of messages can wait in it. The sender is never delayed.
Process Q executes
receive (P, message);
send (P, "acknowledgment");
Such processes are said to communicate asynchronously.
There are special cases that do not fit directly into any of the categories that
we have discussed:
The process sending a message is never delayed. However, if the
receiver has not received the message before the sending process
sends another message, the first message is lost. The advantage of this
scheme is that large messages do not need to be copied more than
once. The main disadvantage is that the programming task becomes
more difficult. Processes need to synchronize explicitly, to ensure both
that messages are not lost and that the sender and receiver do not
manipulate the message buffer simultaneously.
The process of sending a message is delayed until it receives a reply.
This scheme was adopted in the Tooth operating system. In this system
messages are of fixed size (eight words). A process P that sends a
message is blocked until the receiving process has received the
message and has sent back an eight-word reply by the reply (P,
message) primitive. The reply message overwrites the original message
buffer. The only difference between the send and reply primitives is that
entry section
Critical-section
exit section
Remainder section
until false;
Figure 4.1: General structure of a typical process pi
4.3.1.1 Algorithm 1
Let the processes share a common variable turn initialized to 0 (or 1). If turn
=i, then process pi is allowed to execute in its critical-section. The structure
of process pi is shown in figure 4.2.
This solution ensures that only one process at a time can be in its critical-
section. But it does not satisfy the progress requirement, since it requires
strict alternation of processes in the execution of the critical-section. For
example, if turn=0 and p1 is ready to enter its critical-section, p1 cannot do
so, even though p0 may be in its remainder section.
Repeat
Critical-section
turn= j;
Remainder section
until false;
4.3.1.2 Algorithm 2
The problem with algorithm 1 is that it does not retain sufficient information
about the state of each process; it remembers only which process is allowed
to enter that process critical-section. To remedy this problem, we can
replace the variable turn with the following array:
var flag: array[0..1] of Boolean;
the elements of the array are initialized to false. If flag[i] is true, this value
indicates that pi is ready to enter the critical-section. The structure of
process pi is shown in figure 4.3.
Repeat
flag[i]=true;
while flag[j] do no-op;
Critical-section
flag[i]= false;
Remainder section
until false;
4.3.1.3 Algorithm 3
By combining the key ideas of algorithm 1 and algorithm 2, we obtain a
correct solution to the critical-section problem, where all three requirements
are met. The processes share two variables;
var flag: array[0…1] of boolean;
turn; 0…1;
initially flag[0]=flag[1]=false, and the value of turn is immaterial (but it is
either 0 or 1). The structure of process pi is shown in figure 4.4. the eventual
value of turn decides which of the two processes is allowed to enter its
critical-section first.
Repeat
flag[i]=true;
turn=j;
while (flag[j] and turn=j) do no-op;
Critical-section
flag[i]= false;
Remainder section
until false;
Figure 4.4: The structure of process pi in algorithm 3
enter the critical-section. Since pi does not change the value of the variable
turn while executing the while statement, pi will enter the critical-
section(progress) after at the most one entry by pj (bounded waiting).
Thus it continues looping in the while statement until pi leaves the pi critical
section.
repeat
choosing[i]=true;
number[i]=max(number[0],number[1],….number[n-1])+1;
choosing[i]=false;
for j=0 to n-1
do begin
while choosing[j] do no-op;
while number[j] ≠ 0
and (number[j],j) <(number[i],i) do no-op;
end;
critical section
number[i]=0;
remainder section
until false;
Figure 4.5: The structure of process pi in the bakery algorithm.
4.4 Semaphores
Semaphores are the classic method for restricting access to shared
resources (e.g. storage) in a multi-processing environment. They were
invented by Dijkstra and first used in T.H.E operating system.
A semaphore is a protected variable (or abstract data type) which can only
be accessed using the following operations:
P(s)
Semaphore s;
{
while (s == 0) ;/* wait until s>0 */
s = s-1;
}
V(s)
Semaphore s;
{
s = s+1;
Init(s, v)
Semaphore s;
Int v;
{
s = v;
}
Semaphores are not provided by hardware. But they have several attractive
properties:
Machine independent.
Simple.
Powerful. Embody both exclusion and waiting.
Correctness is easy to determine.
Work with many processes.
Can have many different critical sections with different semaphores.
Can acquire many resources simultaneously (multiple P's).
Can permit multiple processes into the critical section at once, if that is
desirable.
4.5 Monitors
Another high-level synchronization construct is the monitor type. A
monitor is a collection of procedures, variables and data structures
grouped together. Processes can call the monitor procedures but cannot
access the internal data structures. Only one process at a time may be
be active in a monitor.
‘N’ which implies that a process is in its critical section. If the process comes
out of its critical section IND is set to ‘F’. Hence the TSL instruction is
executed only if IND has a value ‘F’ as shown below:
Begin
-------
Call Enter-critical-section
Critical section instructions
Call Exit-critical-section
-------
Call Enter-critical-section executes the TSL instruction if IND = F else waits.
Call Exit-critical-section sets IND = F. Any process producer / consumer can
be handled using the above algorithm. Demerits of the algorithm include the
use of special hardware that restricts portability.
4.7 Summary
This unit has brought out the information about inter-process communication
and process synchronization. Given a collection of co-operating processes
that share data, mutual exclusion should be provided.
Structure
5.1 Introduction
Objectives
5.2 System Model
5.3 Deadlock Characterization
Necessary Conditions for Deadlock
Resource-Allocation Graph.
5.4 Deadlock Handling
5.5 Deadlock Prevention.
5.6 Deadlock Avoidance
Safe State
Resource-Allocation Graph Algorithm
Banker’s Algorithm
Safety Algorithm
Resource Request Algorithm
5.7 Deadlock Detection
Single Instance of a Resource
Multiple Instances of a Resource
Recovery from Deadlock
5.8 Summary
5.9 Terminal Questions
5.10 Answers
5.1 Introduction
Several processes compete for a finite set of resources in a multi-
programmed environment. A process requests for resources that may not
be readily available at the time of the request. In such a case the process
goes into a wait state. It may so happen that this process may never change
state because the requested resources are held by other processes which
themselves are waiting for additional resources and hence in a wait state.
Sikkim Manipal University Page No. 84
Operating Systems Unit 5
Objectives:
At the end of this unit, you will be able to understand:
System model for Deadlocks, Deadlock Characterization, Deadlock
Handling, Deadlock prevention , how to avoid Deadlocks using Banker’s
Algorithm and Deadlock Detection.
A process requests for resources, uses them if granted and then releases
the resources for others to use. It goes without saying that the number of
resources requested shall not exceed the total of each type available in the
system. If a request for a resource cannot be granted immediately then the
process requesting the resource goes into a wait state and joins the wait
queue for the resource.
For example, there are 2 resources, 1 printer and 1 tape drive. Process P1
is allocated tape drive and P2 is allocated printer. Now if P1 requests for
printer and P2 for tape drive, a deadlock occurs.
P3 is holding R3.
The resource allocation gragh for a system in the above situation is as
shown below (Figure 5.1).
P1 R1 P3 R2 P1
The cycle above does not imply a deadlock because an instance of R1
released by P2 could be assigned to P1 or an instance of R2 released by P4
could be assigned to P3 there by breaking the cycle.
If none of the above two schemes are used, then deadlocks may occur. In
such a case, an algorithm to recover from the state of deadlock is used.
If the problem of deadlocks is ignored totally, that is, to say the system does
not ensure that a deadlock does not occur and also does not provide for
recovery from deadlock and such a situation arises, then there is no way out
of the deadlock. Eventually, the system may crash because more and more
processes request for resources and enter into deadlock.
actually used and hence not available for others to use as in the first
approach. The second approach seems applicable only when there is
assurance about reusability of data and code on the released resources.
The algorithms also suffer from starvation since popular resources may
never be freely available.
compared and to find out the precedence order for the resources. Thus F: R
N is a 1:1 function that maps resources to numbers. For example:
F (tape drive) = 1, F (disk drive) = 5, F (printer) = 10.
To ensure that deadlocks do not occur, each process can request for
resources only in an increasing order of these numbers. A process, to start
with in the very first, instance can request for any resource say Ri.
Thereafter it can request for a resource Rj if and only if F(Rj) is greater than
F(Ri). Alternately, if F(Rj) is less than F(Ri), then Rj can be allocated to the
process if and only if the process releases Ri.
If a system is in a safe state it can stay away from an unsafe state and thus
avoid deadlock. On the other hand, if a system is in an unsafe state,
deadlocks cannot be avoided.
At the instant t0, the system is in a safe state and one safe sequence is < P1,
P0, P2 >. This is true because of the following facts:
Out of 12 instances of the resource, 9 are currently allocated and 3 are
free.
P1 needs only 2 more, its maximum being 4, can be allotted 2.
Now only 1 instance of the resource is free.
When P1 terminates, 5 instances of the resource will be free.
P0 needs only 5 more, its maximum being 10, can be allotted 5.
Now resource is not free.
Once P0 terminates, 10 instances of the resource will be free.
P3 needs only 7 more, its maximum being 9, can be allotted 7.
Now 3 instances of the resource are free.
When P3 terminates, all 12 instances of the resource will be free.
Thus the sequence < P1, P0, P3 > is a safe sequence and the system is in a
safe state. Let us now consider the following scenario at an instant t1. In
addition to the allocation shown in the table above, P2 requests for 1 more
instance of the resource and the allocation is made. At the instance t1, a
safe sequence cannot be found as shown below:
Thus the system has gone from a safe state at time instant t 0 into an unsafe
state at an instant t1. The extra resource that was granted to P2 at the
instant t1 was a mistake. P2 should have waited till other processes finished
and released their resources.
Since resources available should not be allocated right away as the system
may enter an unsafe state, resource utilization is low if deadlock avoidance
algorithms are used.
The resource allocation graph has request edges and assignment edges.
Let there be another kind of edge called a claim edge. A directed edge P i
Rj indicates that Pi may request for the resource Rj some time later. In a
resource allocation graph a dashed line represents a claim edge. Later
when a process makes an actual request for a resource, the corresponding
claim edge is converted to a request edge Pi Rj. Similarly when a process
releases a resource after use, the assignment edge Rj Pi is reconverted
to a claim edge Pi Rj. Thus a process must be associated with all its claim
edges before it starts executing.
If a process Pi requests for a resource Rj, then the claim edge Pi Rj is first
converted to a request edge Pi Rj. The request of Pi can be granted only
if the request edge when converted to an assignment edge does not result
in a cycle.
If no cycle exists, the system is in a safe state and requests can be granted.
If not the system is in an unsafe state and hence in a deadlock. In such a
case, requests should not be granted. This is illustrated below (Figure 5.5a,
5.5b).
Figure 5.5: Resource allocation graph showing safe and deadlock states
Consider the resource allocation graph shown on the left above. Resource
R2 is currently free. Allocation of R2 to P2 on request will result in a cycle as
shown on the right. Therefore the system will be in an unsafe state. In this
situation if P1 requests for R2, then a deadlock occurs
A new process entering the system must make known a priori the maximum
instances of each resource that it needs subject to the maximum available
for each type. As execution proceeds and requests are made, the system
checks to see if the allocation of the requested resources ensures a safe
state. If so only are the allocations made, else processes must wait for
resources.
The following are the data structures maintained to implement the Banker’s
algorithm:
1. n: Number of processes in the system.
If the resulting state is safe, then process Pi is allocated the resources and
the above changes are made permanent. If the new state is unsafe, then Pi
must wait and the old status of the data structures is restored.
M = 3 < A, B, C >
Initially Available = < 10, 5, 7 >
To find a safe sequence and to prove that the system is in a safe state, use
the safety algorithm as follows:
Step Work Finish Safe sequence
0 3 3 2 FFFFF <>
1 5 3 2 FTFFF < P1 >
2 7 4 3 FTFTF < P1, P3 >
3 7 4 5 FTFTT < P1, P3, P4 >
4 7 5 5 TTFTT < P1, P3, P4, P0 >
5 10 5 7 TTTTT < P1, P3, P4, P0, P2 >
Now at an instant t2 Request4 = < 3, 3, 0 >. But since Request4 > Available,
the request cannot be granted. Also Request0 = < 0, 2, 0> at t2 cannot be
granted since the resulting state is unsafe as shown below:
Allocation Max Available Need
A B C A B C A B C A B C
P0 0 3 0 7 5 3 2 1 0 7 2 3
P1 3 0 2 3 2 2 0 2 0
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
Using the safety algorithm, the resulting state is unsafe since Finish is false
for all values of i and we cannot find a safe sequence.
Step Work Finish Safe sequence
0 2 1 0 FFFFF <>
The wait-for graph is a directed graph having vertices and edges. The
vertices represent processes and directed edges are present between two
processes, one of which is waiting for a resource held by the other. Two
edges Pi Rq and Rq Pj in the resource allocation graph are replaced by
one edge Pi Pj in the wait-for graph. Thus, the wait-for graph is obtained
by removing vertices representing resources and then collapsing the
corresponding edges in a resource allocation graph. An Illustration is shown
in Figure 5.6.
Data structures used are similar to those used in Banker’s algorithm and are
given below:
1. n: Number of processes in the system.
2. m: Number of resource types in the system.
3. Available: is a vector of length m. Each entry in this vector gives
maximum instances of a resource type that are available at the instant.
4. Allocation: is a n x m vector which at any instant defines the number of
resources of each type currently allocated to each of the m processes.
5. Request: is also a n x m vector defining the current requests of each
process. Request[i][j] = k means the ith process Pi is requesting for k
instances of the jth resource type Rj.
ALGORITHM
1. Define a vector Work of length m and a vector Finish of length n.
2. Initialize Work = Available and
For I = 1, 2, ….., n
If Allocationi != 0
Finish[i] = false
Else
Finish[i] = true
3. Find an i such that
a. Finish[i] = false and
b. Requesti <= Work
If such an i does not exist , go to step 5.
4. Work = Work + Allocationi
Finish[i] = true
Go to step 3.
5. If finish[i] = true for all i, then the system is not in deadlock.
Else the system is in deadlock with all processes corresponding to Finish[i]
= false being deadlocked.
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2
P2 3 0 3 0 0 0
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2
To prove that the system is not deadlocked, use the above algorithm as
follows:
Step Work Finish Safe sequence
0 0 0 0 FFFFF <>
1 0 1 0 TFFFF < P0 >
2 3 1 3 TFTFF < P0, P2 >
3 5 2 4 TFTTF < P0, P2, P3 >
4 5 2 6 TFTTT < P0, P2, P3, P4 >
5 7 2 6 TTTTT < P0, P2, P3, P4, P1 >
Now at an instant t1, Request2 = < 0, 0, 1 > and the new values in the data
structures are as follows:
Allocation Request Available
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2
P2 3 0 3 0 0 1
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2
To prove that the system is deadlocked, use the above algorithm as follows:
Step Work Finish Safe sequence
0 0 0 0 FFFFF <>
1 0 1 0 TFFFF < P0 >
The system is in deadlock with processes P1, P2, P3, and P4 deadlocked.
Based on these and many more factors, a process that incurs minimum cost
on termination becomes a victim.
In the second option some resources are preempted from some processes
and given to other processes until the deadlock cycle is broken. Selecting
the victim whose resources can be preempted is again based on the
minimum cost criteria. Parameters such as number of resources a process
is holding and the amount of these resources used thus far by the process
are used to select a victim. When resources are preempted, the process
holding the resource cannot continue. A simple solution is to abort the
process also. Better still is to rollback the process to a safe state to restart
later. To determine this safe state, more information about running
processes is required which is again an overhead. Also starvation may
occur when a victim is selected for preemption, the reason being resources
from the same process may again and again be preempted. As a result the
process starves for want of resources. Ensuring that a process can be a
victim only a finite number of times by having this information as one of the
parameters for victim selection could prevent starvation.
5.8 Summary
The concept of deadlock has highlighted the problem associated with multi-
programming. Since many processes compete for a finite set of resources,
there is always a possibility that requested resources are not readily
available. This makes processes wait. When there is a set of processes
where each process in the set waits on another from the same set for
release of a wanted resource, then a deadlock has occurred. We have the
Structure
6.1 Introduction
Objectives
6.2 Logical versus Physical Address Space
6.3 Swapping
6.4 Contiguous Allocation
Single partition Allocation
Multiple Partition Allocation
Fragmentation
6.5 Paging
Concept of paging
Page Table Implementation
6.6 Segmentation
Concept of Segmentation
Segmentation Hardware
External Fragmentation
6.7 Summary
6.8 Terminal Questions.
6.9 Answers
6.1 Introduction
The concept of CPU scheduling allows a set of processes to share the CPU
thereby increasing the utilization of the CPU. This set of processes needs to
reside in memory. The memory is thus shared and the resource requires to
be managed. Various memory management algorithms exist, each having
its own advantages and disadvantages. The hardware design of the system
plays an important role in the selection of an algorithm for a particular
system. That means to say, hardware support is essential to implement the
memory management algorithm.
Objectives:
At the end of this unit, you will be able to understand:
Logical Address Space, Physical Address Space, Swapping, allocation
methodologies, paging and page table implementation and about
segmentation concepts.
6.3 Swapping
A process to be executed needs to be in memory during execution. A
process can be swapped out of memory in certain situations to a backing
store and then brought into memory later for execution to continue. One
such situation could be the expiry of a time slice if the round-robin CPU
scheduling algorithm is used. On expiry of a time slice, the current process
is swapped out of memory and another process is swapped into the memory
space just freed because of swapping out of a process (Figure 6.2). Every
time a time slice expires, a process is swapped out and another is swapped
in. The memory manager that does the swapping is fast enough to always
provide a process in memory for the CPU to execute. The duration of a time
slice is carefully chosen so that it is sufficiently large when compared to the
time for swapping.
Processes are swapped between the main memory and the backing store
when priority based CPU scheduling is used. The arrival of a high priority
process will be a lower priority process that is executing to be swapped out
to make way for a swap in. The swapping in this case is sometimes referred
to as roll out / roll in.
A process that is swapped out of memory can be swapped in either into the
same memory location or into a different memory location. If binding is done
at load time then swap in has to be at the same location as before. But if
binding is done at execution time then swap in can be into a different
memory space since the mapping to physical addresses are completed
during execution time.
The main memory is usually divided into two partitions, one of which has the
resident operating system loaded into it. The other partition is used for
loading user programs. The operating system is usually present in the lower
memory because of the presence of the interrupt vector in the lower
memory (Figure 6.3).
The disadvantage with this scheme where partitions are of fixed sizes is the
selection of partition sizes. If the size is too small then large programs
cannot be run. Also, if the size of the partition is big then main memory
space in each partition goes a waste.
A variation of the above scheme where the partition sizes are not fixed but
variable is generally used. A table keeps track of that part of the memory
that is used and the part that is free. Initially, the entire memory of the user
area is available for user processes. This can be visualized as one big hole
for use. When a process is loaded a hole big enough to hold this process is
searched. If one is found then memory enough for this process is allocated
and the rest is available free as illustrated in Figure 6.5.
Given the memory map in the illustration above, P1, P2, P3 can be allocated
memory immediately. A hole of size (2160 – (600 + 1000 + 300)) = 260K is
left over which cannot accommodate P4 (Figure 6.6a). After a while P2
terminates creating the map of Figure 6.6b. P4 is scheduled in the hole just
created resulting in Figure 6.6c. Next P1 terminates resulting in Figure 6.6d
and P5 is scheduled as in Figure 6.6e.
The operating system finds a hole just large enough to hold a process and
uses that particular hole to load the process into memory. When the process
terminates, it releases the used memory to create a hole equal to its
memory requirement. Processes are allocated memory until the free
memory or hole available is not big enough to load another ready process.
In such a case the operating system waits for some process to terminate
and free memory. To begin with, there is one large big hole equal to the size
of the user area. As processes are allocated into this memory, execute and
terminate this hole gets divided. At any given instant thereafter there are a
set of holes scattered all over the memory. New holes created that are
adjacent to existing holes merge to form big holes.
The problem now is to satisfy a memory request of size n from a list of free
holes of various sizes. Many solutions exist to determine that hole which is
the best to allocate. Most common strategies are:
1. First-fit: Allocate the first hole that is big enough to hold the process.
Search can either start at the beginning of the set of holes or at the point
where the last search terminated.
2. Best-fit: Allocate the smallest hole that is big enough to hold the
process. Here the entire list has to be searched or an ordered list of
holes by size is to be maintained.
3. Worst-fit: Allocate the largest hole available. Here also, the entire list
has to be searched for the biggest hole or an ordered list of holes by
size is to be maintained.
The size of a process is very rarely an exact size of a hole allocated. The
best-fit allocation always produces an optimal allocation where the hole left
over after allocation is the smallest. The first-fit is the fastest method of
allocation when compared to others. The worst-fit allocation is the worst
among the three and is seldom used.
6.4.3 Fragmentation
To begin with, there is one large hole for allocation to processes. As
processes are loaded into memory and terminate on completion, this large
hole is divided into a set of smaller holes that are scattered in between the
processes. There may be a situation where the total size of these scattered
holes is large enough to hold another process for execution but the process
cannot be loaded, as the hole is not contiguous. This is known as external
fragmentation. For example, in Figure 6.6c, a fragmented hole equal to
560K (300 + 260) is available. P5 cannot be loaded because 560K is not
contiguous.
There are situations where only a few bytes say 1 or 2 would be free if a
process were allocated a hole. Then, the cost of keeping track of this hole
will be high. In such cases, this extra bit of hole is also allocated to the
requesting process. If so then a small portion of memory allocated to a
process is not useful. This is internal fragmentation.
400K 400K
P5
P5
900K 900K
1000K P4
4p
P4
1600K
1700K
1900K P3
2000K
P3 660k
2300K
2560K 2560k
Figure 6.7: Compaction
6.5 Paging
Contiguous allocation scheme requires that a process can be loaded into
memory for execution if and only if contiguous memory large enough to hold
A logical address generated by the CPU consists of two parts: Page number
(p) and a page offset (d). The page number is used as an index into a page
table. The page table contains the base address of each frame in physical
memory. The base address is combined with the page offset to generate the
physical address required to access the memory unit.
a i
b j
0 1 k
c
d l
e m
1 f 0 2 n
g 5 o
h p
1
i
6
2 jj 2 3
k 1
l 3
m
2
3 4
n
o Page table
p
o a
5 b
c
Logical Memory d
6 e
f
g
h
7
Physical Memory
Page size: 4 bytes
Physical memory: 32 bytes = 8 pages
Logical address 0 0 + 0 (5 x 4) + 0 physical address 20
3 0 + 3 (5 x 4) + 3 physical address 23
4 1 + 0 (6 x 4) + 0 physical address 24
13 3 + 1 (2 x 4) + 1 physical address 9
Thus, the page table maps every logical address to some physical address.
Paging does not suffer from external fragmentation since any page can be
loaded into any frame. But internal fragmentation may be prevalent. This is
because the total memory required by a process is not always a multiple of
the page size. So the last page of a process may not be full. This leads to
internal fragmentation and a portion of the frame allocated to this page will
be unused. On an average one half of a page per process is wasted due to
internal fragmentation. Smaller the size of a page, lesser will be the loss due
to internal fragmentation. But the overhead involved is more in terms of
number of entries in the page table. Also known is a fact that disk I/O is
more efficient if page sizes are big. A trade-off between the above factors is
used.
14 15
13 13 Free frame list
18 1
14
20
0
15 15
15
Free frame list
0 0 14
18 2
1 1 13
2 2 18
20
3
3 3 20
When allocation is made, pages are allocated the free frames sequentially
(Figure 6.9). Allocation details of physical memory are maintained in a frame
table. The table has one entry for each frame showing whether it is free or
allocated and if allocated, to which page of which process.
entry in the table. Thus, a hit will reduce one memory access and speed up
address translation (Figure 6.10).
6.5 Segmentation
Memory management using paging provides two entirely different views of
memory – User / logical / virtual view and the actual / physical view. Both
are not the same. In fact, the user’s view is mapped on to the physical view.
6.7 Summary
In this chapter we have learnt how a resource called memory is managed by
the operating system. The memory in question is the main memory that
holds processes during execution. Memory could be contiguously allocated
by using any one of the best-fit or first-fit strategies. But one major
disadvantage with this method was that of fragmentation. To overcome this
problem we have seen how memory is divided into pages / frames and the
processes are considered to be a set of pages in logical memory. These
pages are mapped to frames in physical memory through a page table. We
have also seen user’s view of memory in the form of segments. Just like a
page table, a segment table maps segments to physical memory.
7.1 Introduction
Memory management strategies like paging and segmentation helps to
implement the concept of multi-programming. But they have a few
disadvantages. One problem with the above strategies is that they require
the entire process to be in main memory before execution can begin.
Another disadvantage is the limitation on the size of the process. Processes
whose memory requirement is larger than the maximum size of the memory
available, will never be able to be run, that is, users are desirous of
executing processes whose logical address space is larger than the
available physical address space.
Virtual memory is a technique that allows execution of processes that may
not be entirely in memory. In addition, virtual memory allows mapping of a
Sikkim Manipal University Page No. 129
Operating Systems Unit 7
large virtual address space onto a smaller physical memory. It also raises
the degree of multi-programming and increases CPU utilization. Because of
the above features, users are freed from worrying about memory
requirements and availability.
Objectives:
At the end of this unit, you will be able to understand:
Virtual Memory technique, its need, Demand Paging, different Page
replacement Algorithms, Thrashing and its causes.
Many a time, the entire process need not be in memory during execution.
The following are some of the instances to substantiate the above
statement:
Code used to handle error and exceptional cases is executed only in
case errors and exceptional conditions occur, which is usually a rare
occurrence, may be one or no occurrences in an execution.
Static declarations of arrays lists and tables declared with a large upper
bound but used with no greater than 10% of the limit.
Even though entire program is needed, all its parts may not be needed
at the same time because of overlays.
All the examples show that a program can be executed even though it is
partially in memory. This scheme also has the following benefits:
If the valid-invalid bit is set, then the corresponding page is valid and also in
physical memory. If the bit is not set, then any of the following can occur:
Process is accessing a page not belonging to it, that is, an illegal
memory access.
Process is accessing a legal page but the page is currently not in
memory.
If the same protection scheme as in paging is used, then in both the above
cases a page fault error occurs. The error is valid in the first case but not in
the second because in the latter a legal memory access failed due to non-
availability of the page in memory which is an operating system fault. Page
faults can thus be handled as follows (Figure 7.4):
1. Check the valid-invalid bit for validity.
2. If valid, then the referenced page is in memory and the corresponding
physical address is generated.
3. If not valid then, an addressing fault occurs.
4. The operating system checks to see if the page is in the backing store. If
present, then the addressing error was only due to non-availability of
page in main memory and is a valid page reference.
5. Search for a free frame.
6. Bring in the page into the free frame.
7. Update the page table to reflect the change.
8. Restart the execution of the instruction stalled by an addressing fault.
In the initial case, a process starts executing with no pages in memory. The
very first instruction generates a page fault and a page is brought into
memory. After a while all pages required by the process are in memory with
a reference to each page generating a page fault and getting a page into
memory. This is known as pure demand paging. The concept, never bring in
a page into memory until it is required’.
When a page fault occurs and no free frame is present, then a swap out and
a swap in occurs. A swap out is not always necessary. Only a victim that
has been modified needs to be swapped out. If not, the frame can be over
written by the incoming page. This will save time required to service a page
fault and is implemented by the use of a dirty bit. Each frame in memory is
associated with a dirty bit that is reset when the page is brought into
memory. The bit is set whenever the frame is modified. Therefore, the first
choice for a victim is naturally that frame with its dirty bit which is not set.
Illustration:
Address sequence: 0100, 0432, 0101, 0612, 0102, 0103, 0104, 0101, 0611,
0102, 0103, 0104, 0101, 0610, 0102, 0103, 0104, 0101,
0609, 0102, 0105
Page size: 100 bytes
Reference string: 1 4 1 6 1 6 1 6 1 6 1
To determine the number of page faults for a particular reference string and
a page replacement algorithm, the number of frames available to the
process need to be known. As the number of frames available increases the
number of page faults decreases. In the above illustration, if frames
available were 3 then there would be only 3 page faults, one for each page
reference. On the other hand, if there were only 1 frame available then there
would be 11 page faults, one for every page reference.
heavily used variable in constant use. Such a page swapped out will cause
a page fault almost immediately to be brought in. Thus, the number of page
faults increases and results in slower process execution. Consider the
following reference string:
Reference string: 1 2 3 4 1 2 5 1 2 3 4 5
Memory frames: 1, 2, 3, 4, 5
The chart below gives the number of page faults generated for each of the 1,
2, 3, 4 and 5 memory frames available.
Illustration:
Reference string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Memory frames: 3
Page faults: 7 7 7 2 2 2 2 2 7
0 0 0 0 4 0 0 0
1 1 3 3 3 1 1
Number of page faults = 9.
Ignoring the first three page faults that do occur in all algorithms, the optimal
algorithm is twice as better than the FIFO algorithm for the given string.
But implementation of the optimal page replacement algorithm is difficult
since it requires future a priori knowledge of the reference string. Hence the
optimal page replacement algorithm is more a benchmark algorithm for
comparison.
Illustration:
Reference string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Memory frames: 3
Page faults: 7 7 7 2 2 4 4 4 0 1 1 1
0 0 0 0 0 0 3 3 3 0 0
1 1 3 3 2 2 2 2 2 7
Number of page faults = 12.
The LRU page replacement algorithm with 12 page faults is better than the
FIFO algorithm with 15 faults. The problem is to implement the LRU
algorithm. An order for the frames by time of last use is required. Two
options are feasible:
By use of counters
By use of stack
In the first option using counters, each page table entry is associated with a
variable to store the time when the page was used. When a reference to the
page is made, the contents of the clock are copied to the variable in the
page table for that page. Every page now has the time of last reference to it.
According to the LRU page replacement algorithm the least recently used
page is the page with the smallest value in the variable associated with the
clock. Overheads here include a search for the LRU page and an update of
the variable to hold clock contents each time a memory reference is made.
In the second option a stack is used to keep track of the page numbers. A
page referenced is always put on top of the stack. Therefore the top of the
stack is the most recently used page and the bottom of the stack is the LRU
page. Since stack contents in between need to be changed, the stack is
best implemented using a doubly linked list. Update is a bit expensive
because of the number of pointers to be changed, but there is no necessity
to search for a LRU page.
LRU page replacement algorithm does not suffer from Belady’s anomaly.
But both of the above implementations require hardware support since
either the clock variable or the stack must be updated for every memory
reference.
7.6 Thrashing
When a process does not have enough frames or when a process is
executing with a minimum set of frames allocated to it which are in active
use, there is always a possibility that the process will page fault quickly. The
page in active use becomes a victim and hence page faults will occur again
and again . In this case a process spends more time in paging than
executing. This high paging activity is called thrashing.
The locality model states that as a process executes, it moves from one
locality to another, where a locality is a set of active pages used together.
These localities are strictly not distinct and overlap. For example, a
subroutine call defines a locality by itself where memory references are
made to instructions and variables in the subroutine. A return from the
subroutine shifts the locality with instructions and variables of the subroutine
no longer in active use. So localities in a process are defined by the
structure of the process and the data structures used therein. The locality
model states that all programs exhibit this basic memory reference structure.
Allocation of frames enough to hold pages in the current locality will cause
faults for pages in this locality until all the required pages are in memory.
The process will then not page fault until it changes locality. If allocated
frames are less than those required in the current locality then thrashing
occurs because the process is not able to keep in memory actively used
pages.
Let WSSi be the working set for a process Pi. Then D = ∑ WSSi will be the
total demand for frames from all processes in memory. If total demand is
greater than total available, that is, D>m then thrashing has set in.
The operating system thus monitors the working set of each process and
allocates to that process enough frames equal to its working set size. If free
frames are still available then degree of multi-programming can be
increased. If at any instant D>m then the operating system swaps out a
The working set model prevents thrashing while the degree of multi-
programming is kept as high as possible there by increasing CPU utilization.
When thrashing has set in page fault is high. This means to say that a
process needs more frames. If page fault rate is low, the process may have
more than necessary frames to execute. So upper and lower bounds on
page faults can be defined. If the page fault rate exceeds the upper bound,
then another frame is allocated to the process. If it falls below the lower
bound then a frame already allocated can be removed. Thus monitoring the
page fault rate helps prevent thrashing.
7.7 Summary
In this chapter we have studied a technique called virtual memory that
creates an illusion for the user that he/she has a large memory at his/her
disposal. But in reality, only a limited amount of main memory is available
and that too is shared amongst several users. We have also studied
demand paging which is the main concept needed to implement virtual
memory. Demand paging brought in the need for page replacements if
required pages are not in memory for execution. Different page replacement
algorithms were studied. Thrashing, its cause and ways of controlling it were
also addressed.
Self Assessment Questions
1. ____________ is a technique that allows execution of processes that
may not be entirely in memory.
2. Virtual Memory is implemented using _____________ .
3. ___________ is basic to demand paging.
4. ___________ algorithm produces the lowest page fault rate of all
algorithm.
5. ______________ raises the degree of multi-programming and increases
CPU utilization.
Linear List
Hash Table
8.8 Summary
8.9 Terminal Questions
8.10 Answers
8.1 Introduction
The operating system is a resource manager. Secondary resources like the
disk are also to be managed. Information is stored in secondary storage
because it costs less, is non-volatile and provides large storage space.
Processes access data / information present on secondary storage while in
execution. Thus, the operating system has to properly organize data /
information in secondary storage for efficient access.
The file system is the most visible part of an operating system. It is a way for
on-line storage and access of both data and code of the operating system
and the users. It resides on the secondary storage because of the two main
characteristics of secondary storage, namely, large storage capacity and
non-volatile nature.
Objectives:
At the end of this unit, you will be able to understand:
The concepts of Files, Different File access methods. Different directory
structures, disk space allocation methods, how to manage free space on the
disk and implementation of directory.
from the physical properties of its storage devices to define a logical storage
unit called a file. These files are then mapped on to physical devices by the
operating system during use. The storage devices are usually non-volatile,
meaning the contents stored in these devices persist through power failures
and system reboots.
All these attributes of files are stored in a centralized place called the
directory. The directory is big if the numbers of files are many and also
requires permanent storage. It is therefore stored on secondary storage.
If an operating system can recognize the type of a file then it can operate on
the file quite well. For example, an attempt to print an executable file should
be aborted since it will produce only garbage. Another use of file types is the
capability of the operating system to automatically recompile the latest
version of source code to execute the latest modified program. This is
Operating system support for multiple file structures makes the operating
system more complex. Hence some operating systems support only a
minimal number of files structures. A very good example of this type of
operating system is the UNIX operating system. UNIX treats each file as a
sequence of bytes. It is up to the application program to interpret a file. Here
maximum flexibility is present but support from operating system point of
view is minimal. Irrespective of any file structure support, every operating
system must support at least an executable file structure to load and
execute programs.
File access is always in terms of blocks. The logical size, physical size and
packing technique determine the number of logical records that can be
packed into one physical block. The mapping is usually done by the
operating system. But since the total file size is not always an exact multiple
of the block size, the last physical block containing logical records is not full.
Some part of this last block is always wasted. On an average half a block is
wasted. This is termed internal fragmentation. Larger the physical block size,
greater is the internal fragmentation. All file systems do suffer from internal
fragmentation. This is the penalty paid for easy file access by the operating
system in terms of blocks instead of bits or bytes.
A two-level directory structure has one directory exclusively for each user.
The directory structure of each user is similar in structure and maintains file
information about files present in that directory only. The operating system
has one master directory for a partition. This directory has entries for each
of the user directories (Figure 8.2).
Files with same names exist across user directories but not in the same
user directory. File maintenance is easy. Users are isolated from one
another. But when users work in a group and each wants to access files in
another users directory, it may not be possible.
Access to a file is through user name and file name. This is known as a path.
Thus a path uniquely defines a file. For example, in MS-DOS if ‘C’ is the
partition then C:\USER1\TEST, C:\USER2\TEST, C:\USER3\C are all files in
user directories. Files could be created, deleted, searched and renamed in
the user directories only.
Usually the user has a current directory. User created sub directories could
be traversed. Files are usually accessed by giving their path names. Path
names could be either absolute or relative. Absolute path names begin with
the root and give the complete path down to the file. Relative path names
begin with the current directory. Allowing users to define sub directories
allows for organizing user files based on topics. A directory is treated as yet
another file in the directory, higher up in the hierarchy. To delete a directory
it must be empty. Two options exist: delete all files and then delete the
directory or delete all entries in the directory when the directory is deleted.
Deletion may be a recursive process since directory to be deleted may
contain sub directories.
Directory:
File Start Length
a.c 0 2
per 14 3
hop 19 6
b 28 4
f 6 2
MS-DOS uses a variation of the linked allocation called a file allocation table
(FAT). The FAT resides on the disk and contains entry for each disk block
and is indexed by block number. The directory contains the starting block
address of the file. This block in the FAT has a pointer to the next block and
so on till the last block (Figure 8.6). Random access of files is possible
because the FAT can be scanned for a direct block address.
allocation solves this problem by bringing all pointers together into an index
block. This also solves the problem of scattered pointers in linked allocation.
Each file has an index block. The address of this index block finds an entry
in the directory and contains only block addresses in the order in which they
are allocated to the file. The ith address in the index block is the ith block of
the file (Figure 8.7). Here both sequential and direct access of a file are
possible. Also it does not suffer from external fragmentation.
Indexed allocation does suffer from wasted block space. Pointer overhead is
more in indexed allocation than in linked allocation. Every file needs an
index block. Then what should be the size of the index block? If it is too big,
space is wasted. If it is too small, large files cannot be stored. More than
one index blocks are linked so that large files can be stored. Multilevel index
blocks are also used. A combined scheme having direct index blocks as well
as linked index blocks has been implemented in the UNIX operating system.
Some systems support both contiguous and linked allocation. Initially all files
have contiguous allocation. As they grow a switch to indexed allocation
takes place. If on an average files are small, than contiguous file allocation
is advantageous and provides good performance.
Illustration: If blocks 2, 4, 5, 9, 10, 12, 15, 18, 20, 22, 23, 24, 25, 29 are free
and the rest are allocated, then a free-space list implemented as a bit vector
would look as shown below:
00101100011010010010101111000100000………
Bit vectors are inefficient if they are not in memory. Also the size of the
vector has to be updated if the size of the disk changes.
8.6.3 Grouping
Another approach is to store ‘n’ free block addresses in the first free block.
Here (n-1) blocks are actually free. The last nth address is the address of a
block that contains the next set of free block addresses. This method has
the advantage that a large number of free block addresses are available at a
single place unlike in the previous linked approach where free block
addresses are scattered.
8.6.4 Counting
If contiguous allocation is used and a file has freed its disk space then a
contiguous set of ‘n’ blocks is free. Instead of storing the addresses of all
these ‘n’ blocks in the free-space list, only the starting free block address
and a count of the number of blocks free from that address can be stored.
This is exactly what is done in this scheme where each entry in the free-
space list is a disk address followed by a count.
8.8 Summary
In this chapter the operating system as a secondary resource manager has
been studied. Data / information stored in secondary storage has to be
managed and efficiently accessed by executing processes. To do this the
operating system uses the concept of a file. A file is the smallest allotment of
secondary storage. Any information to be stored needs to be written on to a
file. We have studied file attributes, operations on files, types and structure
of files, File access methods, File Allocation methods and implementation
of a file. We have also learnt the concept of a directory, its various
structures for easy and protected access of files and its implementation.
9.10 Summary
9.11 Terminal Questions
9.12 Answers
9.1 Introduction
Earlier were the days of centralized computing. With the advent of micro and
mini computers, distributed processing is becoming more and more popular.
Merely having a large central computer with a number of remote terminals
connected to it or with a number of computers at different locations with no
connection among them do not constitute a distributed processing because
neither processing nor data is distributed in any sense.
Objectives:
At the end of this unit, you will be able to understand:
Characteristics of Distributed Processing, parallel processing and
centralized processing.
Achitecture of Network Operating System(NOS) and functions of NOS.
About Global Operating System, Remote Procedure Call and Distributed
File Management.
In horizontal distribution all computers are at the same level implying that all
the computers are capable of handling any functionality. Examples include
office automation and reservation systems where many computers in a
network are able to reserve, cancel or enquire. Application with all its
programs is duplicated at almost all the computers.
analysis at branch level and sales analysis at zonal level may generate
summaries in different formats.
In centralized data, data resides only at one central computer that can be
accessed or shared by all other computers in the network. For example,
master database. This central computer must run an operating system that
implements functions of information management. It must keep track of
users and their files and handle data sharing, protection, disk space
allocation and other related issues. It must also run a front-end software for
receiving requests / queries from other computers for data. These requests
are then serviced one by one. It is because of this software that this central
computer is called a server. Computers connected to the server can have
their own local data but shared data has to necessarily reside in the server.
In a distributed environment, part of the master database could be
centralized and the rest distributed among the connecting computers.
duplicated. For example, information about train timings and fares would
need replication because this information is needed at all terminals which
cater to train bookings / reservations / enquires, the reason being frequency
of changes to this particular database is very low.
9.6.1 Redirection
Redirection software normally resides on the client and also on the server.
On the server also because, if it is not a dedicated one then user of the
server machine may want access to other computers. When does the
redirection software actually work? An interrupt is executed by a system call
generated, say for an I/O. It is at the time of execution of the interrupt that
redirection software intercepts to check if the I/O is local / remote. If it is
local, processing continues. If it is remote the redirection software has to
generate a request to the server. But generating a request to the server has
problems. The operating system running on the server may be different from
that on the local machine generating the request. Also system architecture
of the server may be different from the client. Therefore some conversion is
necessary.
Information management
Process / object management
Memory management
Communication management
Network management
A typical GOS environment is depicted in the figure below (Figure 9.2). Part
of the kernel of a GOS is duplicated at all sites. This kernel contains
software to control hardware. Resources like information, memory, etc are
managed by software that need not be replicated.
The first option is similar to the approach of a file server whereas the second
is similar to a database server. Software for sending the full file is simple.
But the network will be loaded and in case the file is updated at site X, the
entire file has to be again sent back to Y. If only required portions of a file
are sent then network load is less but software to handle this is complex.
Depending on requests for remote data, the GOS may migrate portion of
data from one node to another or may replicate data to improve
performance. This also brings with it the problems of data integrity.
Sometimes a process may be scheduled on a node that does not have the
necessary requirements for the process because of which the process does
not complete execution but is waiting in a blocked state for a long time.
Since it was the only processor at the time of allocation it runs the process.
Now that another processor with higher capacity is free, the GOS should be
able to migrate the process to the new processor. There exists a tradeoff
between the gain in performance of the migrated process and the
overheads involved.
In the blocking scheme, the process on the client that has requested for
service from the server gets blocked until it receives back the data, whereas
in the non-blocking scheme, the process requesting for service continues
without waiting.
9.8.3 RPC
RPC can be viewed as an enhancement of a reliable blocking message-
passing scheme to execute a remote procedure on another node. The
message in this case is not a general one but specifies the procedure to be
executed on the remote node along with required parameters.
9.8.6 Ports
If a server provides multiple services then normally a port number is
associated with each service. For example, port number 1154 for listing
current users, port number 2193 for opening a file and so on. RPC makes
use of these port numbers. This simplifies communication. Hence a
message sent as a RPC to a remote node contains among other information
the port number and parameters for the service. The interface module on
the remote node reads the port number and then executes the appropriate
service.
Each node in the network runs its own local operating system and thus has
its own file system. This local file system (LFS) is responsible for allocating
space to a file, maintaining buffers, tables like FAT and so on. Services for
file creation, deletion, read and write are provided by it. It maintains the
directory structure and associated files. The functions of the LFS on a
remote file are carried out by the distributed file system (DFS). It allows the
users to see an entire structure of files and directories present in all the
nodes put together as a hierarchy. An important implementation
consideration in the design of DFS is the policy to be used to implement file
UNIX has a feature called RFS that is a DFS for UNIX. SUN has its NFS
that is again a DFS and is part of the SunOS operating system. NetWare-
386 can support multiple machines and multiple networks / distributed file
systems at the same time.
9.10 Summary
We have studied what distributed processing is all about. We have seen
how applications / data / control can be distributed. We have also seen the
architecture of typical NOS and its functions. A GOS is necessary for
optimal use of memory and processing power in all computers in a network.
We have learnt what a RPC is and how it is executed. In addition to this an
overview of Distributed File Management has also been discussed.
Structure
10.1 Introduction
Objectives
10.2 Attacks on Security
Authentication
Browsing
Invalid Parameters
Line tapping
Improper Access Controls
Rogue Software
10.3 Computer Worms
10.4 Computer Virus
Types of Viruses
Infection Methods
Mode of Operation
Virus detection
Virus Removal
Virus Prevention
10.5 Security Design Principles
10.6 Authentication
10.7 Protection Mechanism
10.8 Encryption
10.9 Security in Distributed Environment
10.10 Summary
10.11 Terminal Questions
10.12 Answers
10.1 Introduction
Personal computers were designed and intended for individual use. Hence
security and protection features were minimal. No two users could
simultaneously use the same machine. Locking the room physically which
housed the computer and its accessories could easily protect data and
stored information. But today hardware costs have reduced and people
have access to a wide variety of computing equipment. With a trend towards
networking, users have access to data and code present locally as well as
at remote locations. The main advantages of networking like data sharing
and remote data access have increased the requirements of security and
protection. Security and protection are the two main features that motivated
development of a network operating system (example Novell NetWare).
Objectives:
At the end of this unit, you will be able to understand:
Attacks on Security, Meaning of Authentication and Confidentiality.
Computer Viruses and types of viruses.
Computer worms.
Security Design principles.
Protection Mechanisms and Security in Distributed Environment.
10.2.1 Authentication
Authentication is verification of access to system resources. Penetration is
by an intruder who may :
Guess / steal somebody’s password and use it
Use vendor supplied password usually used by system administrator for
purposes of system maintenance
10.2.2 Browsing
Browsing through system files could get an intruder information necessary
to access files with access controls which are very permissive thus giving
the intruder access to unprotected files / databases.
The above mentioned were some common ways in which a security system
could be attacked. Other ways in which a security system can be attacked
may be through Trap doors, Electronic data capture, Lost line, Waste
recovery and Covert channels.
A computer worm does not harm any other program or data but spreads,
thereby consuming large resources like disk storage, transmission capacity,
etc. thus denying them to legal users. A worm usually operates on a network.
A node in a network maintains a list of all other nodes on the network and
also a list of machine addresses on the network. A worm program accesses
this list and using it copies itself to all those address and spreads. This large
continuous transfer across the network eats up network resources like line
capacity, disk space, network buffers, tables, etc.
Worm consumes only system resources but virus causes direct harm to the
system by corrupting code as well as data.
10.6 Authentication
Authentication is a process of verifying whether a person is a legal user or
not. This can be by either verification of users logging into a centralized
The password is generally not echoed on the screen while being keyed in.
Also it is stored in encrypted form. It cannot be deciphered easily because
knowing the algorithm for deciphering will not suffice as the key is ought to
be known for deciphering it.
The operating system allows different access rights for different objects. For
example, UNIX has read, write and execute (rwx) rights for owners, groups
and others. Possible access rights are listed below:
No access
Execute only
Read only
Append only
Update
Modify protection rights
Delete
0 R R W
D W
O 1 R R W
M W
A X
I 2 W R W
N W
S X
3 W R
Since the matrix has many holes, storing the entire matrix is waste of space.
Access control list is one way of storing the matrix. Only information in the
columns is stored and that too only where information is present that is each
file has information about users and their access rights. The best place to
maintain this information is the directory entry for that file.
Capability list is another way of storing the access control matrix. Here
information is stored row wise. The operating system maintains a list of files
/ devices (objects) that a user can access along with access rights.
A combination of both access control list and capability list is also possible.
10.8 Encryption
Encryption is an important tool in protection, security and authentication.
The process involves two steps (Figure 10.2):
Encryption: the original message is changed to some other form
Decryption: the encrypted message is restored back to the original
In transposition ciphers the contents of the data are not changed but the
order is changed. For example, a message could be sent in reverse order
like:
I am fine enif ma I
Railfence cipher is a method that belongs to this class. The method is slow
because the entire message is to be stored and then encrypted. It also
requires more storage space when messages are long.
Ceasar cipher is a popular method of this type. This method is fast and
requires less memory because characters can be changed as they are read
and no storage is required.
Variations of this scheme are used for bit streams. Encryption in this case
involves adding a key to every bit stream and decryption is removing the key
from the cipher text.
An alternate is the public key encryption. Keys used for encryption and
decryption are not the same. Key K1 is used for encryption and another key
K2 is used for decryption. A message encrypted using K1 can be decrypted
only using K2 and not K1. One of the keys is publicly known. Hence the
name public key encryption. Decryption is done using a private key and
hence information cannot leak out. Interchange of keys K1 and K2 is
possible, that is, K2 to encrypt and K1 to decrypt.
Each user has two keys, one public and one private (Figure 10.3). The
private key is a secret but the user publishes the public key to a central key
database. The database maintains public keys of different users.
The problem here is that of authentication. B does not know who has sent
the message to it because everybody knows B’s public key. In the
conventional encryption method a single key is used between two parties
and hence the receiver knows the sender. But it suffers from the problem of
key distribution. In public key encryption method, for ‘n’ nodes in the network
only 2xn keys (1 public and 1 private for each of the nodes) are required.
There need be no agreement. Private key is chosen and a public key is
made known. Key distribution is really not necessary. Key leakage and
tapping are minimal. Protection is ensured but authentication is not provided.
This is based on the concept that public key encryption algorithm works by
using either of the keys to encrypt and the other for decryption. A encrypts
Sikkim Manipal University Page No. 203
Operating Systems Unit 10
the message to be sent to B using its private key. At the other end B
decrypts the received message using A’s public key which is known to
everybody. Thus B knows that A has sent the message. Protection is not
provided as anyone can decrypt the message sent by A.
The two keys are used as shown. At points 2 and 4 the cipher text is the
same. Similarly at points 1 and 5 the text is the same. Authentication is
possible because between 4 and 5 decryption is done by A’s public key and
is possible only because A has encrypted it with its private key. Protection is
also guaranteed because from point 3 onwards only B can decrypt with its
private key. This is how digital signatures work.
Figure 10.5: Public key Encryption for both authentication and protection
10.10 Summary
This unit looks into an important part of any operating system – security and
protection. These were trivial matters in earlier systems since computers
were centralized systems accessed only by knowledgeable users. With
Structure
11.1 Introduction
Objectives
11.2 Advantages of Multiprocessors
11.3 Multiprocessor classification
11.4 Multiprocessor Interconnections
Bus-Oriented Systems
Crossbar-Connected Systems
Hyper cubes
Multistage switch-based Systems
11.5 Types of Multi-processor operating Systems
Separate supervisors
Master / slave
Symmetric
11.6 Multiprocessor Operating System functions and requirements
11.7 Operating System design and implementation issues
Process Management and scheduling
Memory Management
11.8 Summary
11.9 Terminal Questions
11.10 Answers
11.1 Introduction
There are basically two ways of increasing the speed of computer hardware.
They are by using:
High speed components
New architectural structures
Objectives:
At the end of this unit, you will be able to understand:
Advantages of Multiprocessors
Multiprocessor classification
Multiprocessor Interconnections
Types of Multi-processor operating Systems
Multiprocessor Operating System functions, requirements and
Implementation issues.
Sikkim Manipal University Page No. 208
Operating Systems Unit 11
SIMD: Single Instruction Stream, Multiple Data Stream. These are vector
processors / array processors where a single instruction operates on
different data in different execution units at the same time.
MISD: Multiple Instruction Streams, Single Data Stream. Multiple
instructions operate on a single data stream. Not a practical viability.
MIMD: Multiple Instruction Streams, Multiple Data Stream. This is the
most general classification where multiple instructions operate on
multiple data stream simultaneously. This is the class that contains
multiprocessors of different types.
This classification may not be very rigid and multiprocessor systems have
both shared memory as well as local memory.
Hybrid systems have both local and global memories. Some loosely coupled
systems also allow access of global memory in addition to local memory.
P P P P
Cache Cache Cache Cache
Shared memory
Processors communicate with each other and the shared memory through
the shared bus. Variations of this basic scheme are possible where
processors may or may not have local memory, I/O devices may be
attached to individual processors or the shared bus and the shared memory
itself can have multiple banks of memory.
The bus and the memory being shared resources there is always a
possibility of contention. Cache memory is often used to release contention.
Cache associated with individual processors provides a better performance.
A 90% cache hit ratio improves the speed of the multiprocessor systems
nearly 10 times as compared to systems without cache.
M0 M1 M2 Mn-1
P0
P1
M2
Mn-1
Contention occurs when more than one processor attempts to access the
same memory at the same time. Careful distribution of data among the
different memory locations can reduce or eliminate contention.
Since „n‟ processors and „n‟ memory locations are fully connected, n2 cross
points exist. The quadratic growth of the system makes the system
expensive and limits scalability.
010 Topology
011
100 101
000 001
Each processor at a node has a direct link to log2N nodes where N is the
total number of nodes in the hypercube. For example, in a 3-dimensional
hypercube, N = 8 and each node is connected to log28 = 3 nodes.
Hypercube can be recursive structures with high dimension cubes
containing low dimension cubes as proper subsets. For example, a 3-
dimensional cube has two 2-dimensional cubes as subsets. Hypercube
have a good basis for scalability since complexity grows logarithmically
where as it is quadratic in the previous case. They are best suited for
problems that map on to a cube structure, those that rely on recursion or
exhibit locality of reference in the form of frequent communication with
adjacent nodes. Hypercube form a promising basis for large-scale
multiprocessors.
Routing is fixed and is based on the destination address and the source
address. In general to go from source S to destination D the ith stage switch
box in the path from S to D should be set to swap if Si Di and set to
straight if Si = Di.
P0 M0
P1 M1
P2 M2
P3 M3
P4 M4
P5 M5
P6 M6
P7 M7
Illustration: If S = 000 and D = 000 then Si = Di for all bits. Therefore all
switches are straight.
Master / slave
Symmetric
11.5.2 Master/Slave
In this approach, one processor – the master is dedicated to execute the
operating system. The remaining processors are slaves and form a pool of
computational processors. The master schedules and controls the slaves.
This arrangement allows parallelism in an application by allocating to it
many slaves.
11.4.5 Symmetric
All processors are functionally identical. They form a pool of resources.
Other resources such as memory and I/O devices are available to all
processors. If they are available to only a few then the system becomes
asymmetric.
The operating system is also symmetric. Any processor can execute it. In
response to workload requirements and processor availability, different
processors execute the operating system at different times. That processor
which executes the operating system temporarily is the master (also called
floating master).
A tradeoff exists between the two. The former affects throughput while the
latter affects speedup. Depending on an application if speedup is given
priority then a large portion of the processors is dedicated to the application.
On the other hand if throughput is to be increased then several applications
are scheduled each availing fewer processors. The two main facts of
operating system support for multiprocessor are:
Flexible and efficient inter-process and inter-processor synchronization
mechanisms.
Efficient creation and management of a large number of threads /
processes.
11.8 Summary
We have studied the advantages of using multiprocessor systems and their
classification. We have also studied the different standard interconnection
4. Multistage switch
5. virtual processes
References:
1. “Operating System Concepts” by Abraham Silberschatz & Peter Baer
Galvin
2. “Operating Systems: Design and Implementation” by Andrew S.
Tanenbaum
3. “Modern Operating Systems” by Andrew S. Tanenbaum