OS Module 1
OS Module 1
1
Introduction
An operating system (0S) is different things to different users. Each user's view is
called an abstract view because it emphasizes features that are important from the
viewer's perspective, ignoring all other features. An operating system implements
an abstract view by acting as an intermediary between the user and the computer
system. This arrangement not only permits an operating system to provide several
functionalities at the same time, but also to change and evolve with time. We discuss
how abstract views are also useful while designing an operating system, and during
itsoperation.
An operating system has twOgoalsefficient use of a computer system and user
convenience. Unfortunately, user convenience often conflicts with efficient use of a
computer system. Consequently, an operating system cannot provide both. It typi
cally strikes a balance between the two that is most effective in the environment in
which a computer system is used efficient use is important when a computer system
is shared by several users while user convenience is important in personal comput
ers. We use the term effective utilization for the balance between efficiency and user
convenience that best suits an environment. We discuss facets of efficient use and
user convenience in this chapter.
The primary concern of an OS is to support execution of user programs to ensure
user convenience and efficient use of resources. In this chapter, we describe the
functions performed by it to address these concerns.
" For a person using an application package, an OS is simply the software that
makes it possible for him to use the package.
For atechnician in a computerizedchemical plant, the OSis the invisible com
ponent of a computer system that controls the plant.
The answers differ because a user's perception about an OS depends on three factors:
the purpOse for which a conputer is being used, the computing environment, i.e., the
environment in which the computer system is used, and the degree of identity of the
computer system with the purpose being served.
For the student, the sole purpose of the computer system might be to use an
Internet browser. The OS helps in achieving this, so it is identified with use of the
computer system for Internet browsing. A programmer wishes to use a computer
system for general purpose program development, so theability touse a compiler for
a specifhc language is of paramount importance. For a person using an application
package, the OS is simply ameans to the use of the package. Such a user is oblivious
to other capabilities of an OS. Atechnician in a computerizedchemical plant simi
larly views the OS as everything in the control system of the plant. An OS
will doubtless have a different perception of what is an OS. designer
A common thread in all these perceptions is the
utilization of a
for a specific purpose or a set of purposes. The purposes in the computer system
above
different, so perceptions of the operating system's role are also different.examples are
From these examples it is clear that a user perceives an OS as
the software that
helps him in achieving an intended use of a conputer
of the computer system and its environment do not seemsystem-other capabilities
to matter. Thus, the OS
is simply a means of achieving an intended
purpose. A user
permits him to achieve hispurpose in the simplest and fastest will prefer an OS that
a user's perspective is always one of possiblemanner. Thus,
None of the four views of an OS convenience
and speed in computer utilization.
described at the start of this Section (and illus
trated in Figure 1.1)is complete, but each view is
a user to understand how to use an correct and useful because it helps
OS. Such views are called abstract
abstract view focuses on essential views. An
characteristics of an entity from the
of a viewer. Consequently, an
abstract view contains some elements ofperspective
reality but
ignores other elements.
1.1.1 Uses of Abstract Views
INTERNEP
STOCKINVEST
Use Description
Gathering system A user's abstract view indicates important services which a
requirements system should provide. Acollection of abstract views can be
used to compose a specification of system requirements.
Design of a Use of abstract views permits a designer to focus on a specific
system part of a system. Details of other parts are 'hidden'; these
parts can be assumed to be available. This approach helps to
controlcomplexity of the design process.
Implementation A part whose details were hidden in a design view becomes
of a system amodule, which can be called from other modules. This fact
leads to a modular implementation.
Figure 1.2 contains an abstract view of the structure of an OS, which shows three
main parts of an OS. Each part consists of a number of programs. The kernel is the
core of the OS. It controls operation of the computer and provides a set of functions
and services to use the CPU and resources of the computer. Non-kernel programs
implement user commands. These programs do not interact with the hardware, they
use facilities provided by kernel programs. Programs in the user interface part either
provide a command line interface or a graphical user interface (GUI) to the user.
These programs use facilities provided by non-kernel programs. A user interacts with
4 Operating Systems
User interface
Non-kernel programs
Kernel
Computer hardware
Fig. 1.2 A designer's abstract view of an OS
The abstract view of Figure 1.2 has interesting properties. It contains ahierar
chical arrangement of program layers in which programs in a higher layer use the
facilities provided by programs in the layer below it. In fact, each layer takes an
abstract view of the layer below it. In this view the lower layer appears as a
that is capable of executing certain commands. It could even be a system
machine that is
capable of performing certain operations. The fact that the lower layer consists of
aset of programs rather than a computer system makes no
layer. Each layer extends capabilities of the machine provideddifference to the higher
by the lower layer.
The machine provided by the user interface layer
understands the commands in the
command language of the OS. This abstract view helps to understand the
an OS. design of
(a) (b)
Big. 1.3 Logical and physical views of execution of a program
An operating system must not only ensure efficient use of a computer system, but
also provide user convenience. However, these considerations often conflict. For
of
example, providing Tast service to one user's request could mean that other users
remain
the system have to be neglected. It could also mean that resources should
allocated to auser's program even when the program is not using them, which would
lead to under-utilization of resources. In such cases, the OS designer must make a
with
conscious decision to trade off a part of convenience and speed for one user
Accordingly, the
that of other users or with efficient use of the computer system.
combination of efficient use and user
key goal of an operating system is to provide a which it is used. This is the notion of
convenience that best suits the environment in
effective utilization of a computer system.
in use because each one of them
We find alarge number of operating systems
At one extreme we have OSs that
provides adifferent flavor of effective utilization.
provide fast service required by command and control applications, while at the other
computer resources to provide low-cost com
we have OSs that make efficient use of
the middle, we have OSs that provide different combinations fast service
puting. In use and
we discuss several aspects of efficient
and efficient use. In the following, effective utilization.
understand the notion of
user convenience to
utilization
and effective utilization of computer systems The notion of effective
OS user-centric
considerations. At one end of the spectrum are
spansa broad spectrum of and fast service to user requests. They
are
such as user convenience
considerations,
support interactive computing or time critical
important in operating systems that
4 Operating Systems
programs in the user interface--lypically with the command interpreter-to request
use of resources and services provided by the system.
User interlace
Non-kernel programs
Kernel
Computer hardware
Fig. 1.2 A designer's abstract view of an OS
The abstract view of Figure 1.2 has interesting properties. It contains ahierar
Chical arrangement of program layers in which programs in a higher layer use the
facilities provided by programs in the layer below it. In fact, each layer takes an
abstract view of the layer below it. In this view the lower layer appearS as a system
that is capable of executing certain commands. It could even be a machine that is
capable of performing certain operations. The fact that the lower layer consists of
a set of programs rather than a computer system makes no difference to the higher
layer. Each layer extends capabilities of the machine provided by the lower layer.
The machine provided by the user interface layer understands the
commands in the
command language of the OS. This abstract view helps to understand the design of
an OS.
from info, manipulates it, and prints its results. This view includes the disk on
which info is recorded and the printer on which P's results are to be printed, the
memory of the computer system and the CPU to execute P's instructions.
Memory
ProgramP O)
info
OS
Instructions
+ data space
of P Printer
Data Results
CPU
Other
programs
(a) (b)
Facet Examples
Necessity Ability to exccute programs, use the file system
GoodService Speedy response to computational requests
User friendly OS Easy-to-use commands, Graphical user interface (GUI)
New programming model Concurrent programming
Features for experts Means to set up complex computational structures
Web-oriented features Means to set up Web-enabled servers
Evolution Ability to add new features, use new computers
1.3 OPERATION OF AN OS
of its users with the
An operating system implements computational requirementsdescribed in Table l.3.
help of resources of the computer system. Its key concerns are
Table 1.3 Key concerns of an operating system
Concern OS responsibility
Programs Initiation and termination of programs. Providing convenient
methods so that several programs canwork towards acommongoal.
Resources Ensuring availability of resources in the system and allocating them
to programs.
Scheduling Deciding when, and for how long, to devote the CPUto a program.
Protection Protect data and programs against interference from other users and
their programs.
To realize execution of a program, an operating system must ensure that resources
8 Operating Systems
Iike memoryand I/Odevices are available to it. It must also provide sufficient CPU
attention to a program's execution. This function is calledscheduling. A user may
employ severalprograms to fulfill a computational requirement, so an OS must pro
Vide means to ensure harmonious working of such programs. To win the trust of
Users, an OS must provide a guarantee that their data would not be illegally used
or lost, and that execution of their programs would not face interference from other
programs in the system.
An operating system performs several housckeeping tasks to support the func
tions of creation and termination of programs, resource allocation, scheduling and
protection. An operating system also performs other tasks to implement its notion of
effective utilization. Table 14describes commonly performed OS tasks.
Table 1.4 Common tasks performed by operating systems
1.3.1 Programs
Acomputational structure is a configuration of one or more programs that work
towards acommon goal. It is created by issuing one or more commands specify
relationships betweenprograms and to initiate their execution. Some typical compu
Introduction 9
tational structures are:
" A single
" A program
sequence of single programs
Co-executing programs.
These computational structures wil be defined and
their salient features are described here to described in later chapters; only
them. Table 1.5 summarizes OS illustrate user convenience provided by
responsibilities for these computational structures.
Table 1.5 Computational structures and OS responsibilities
C
linker demo
compiler
Figure 1.4 illustrates the three computations. Note that each program in the sequence
must make its own arrangements to communicate its results toother programs. This
Is (ypically achieved by using some file naming conventions, e.g., the output of the
Ccompiler may be put into a file named alpha .obj so that linker can pick it up
from there. The command interpreter is unaware of these arrangements; it Simply
implements the commands issued to it.
Semantics of a sequence of programs dictate that linker would be executed only if
the compilation of the C program was successful, and that demo would be executed
only if linking was successful. This would not have been the case if the same three
programs were initiated as three single programs.
Co-executing programs Auser initiates co-executing programs by indicatingtheir
names in a single command. Co-execution semantics require that the
should execute at the same time, rather than one after another as in a programs
sequence of
programs, and interact with one another during their execution. The nature of inter
action is specific to a co-execution command. The OS provides
faces between the co-executing programs. Example 1.2 discussesappropriate inter
programs in Unix. co-execution of
Example 1.2 The Unix command
cat names sort |unigwc -1
number of resources and programs in the system and decides hoW many
each kind would be allocated to a program. For resources of
example, an OS may decide that a
program can be allocated 1MB of memory. 2000 disk blocks and a
collection of monitor. Such a
resources called apartition.
is
In thepool-based allocation approach. OS consults the resource table
program makes a request for a resource, and allocates when a
of aresource class exist in the accordingly. When many units
system, a resource request only
class and the OS checks if any unit of that class is available indicates
for
the resource
based allocation incurs overhead of allocation. Pool
ally; however, it avoids both allocating and deallocating resources individu
by adapting the allocation to problems faced by the resource partitioning approach
resource requirements of programs.
Resource
pool
Partition 1 Partition n
P1 P2
(a)
Fig. 1.6 Resource (b)
partitioning and pool based allocation
Figure 1.6(a) shows a set of partitions that are
resource table contains entries for resource defined during boot time. The
resources. A free partition is allocated to eachpartitions rather than for individual
program before its execution is ini
tjated. Figure I.6(b) illustrates pool based
a monitor, a disk area of 2000 blocks allocation. Program Pl has been allocated
andTMB of memory. Program P2 has been
allocated a monitor and 2 MB of memory: disk area is not
not request it. Thus pool based allocation avoids allocated because P2 did
allocation of resources that are not
Introduction 13
Preempted progranm
Partition
A A
B
3 B
Pool of
Unused
memory
4
(a) (b)
Fig. 1.8 Memory allocation schematics: (a)
partitioned allocation, (b) pool-based allocation
Figure 1.8 illustrates the approaches to memory
titioned approach the memory is divided a priori intoallocation.
many
In the fixed par
allocated to aprogram at its initiation. Figure 1.8(a) illustratesareas.
the
A partition is
memory has been divided into equal sized partitions and two of situation when
cated to programs A and B. Two partitions are them have been allo
is smaller than the size of the currently free. Note that the size of B
partition, so some memory allocated to it remains un
used. Figure 1.8(b) illustrates the pool based
allocated memory from the pool. Each program approach. Newly initiated programs are
is allocated only as much
as requested by it, so allocated memory is not wasted. memory
Disk sharing Different parts of a disk
can be treated as
Both partitioning and pool based
approaches are
independent resources.
show a preference for the pool based feasible; however, modern OSs
by an operating system; approach. Disk preemption is not
individual users can preempt their disk areas bypracticed
their files onto tape cartridges. copying
1.3.2.1 Virtual Resources
A virtual resource is a fictitious
through use of areal resource. Anresourceit is an illusion
OS may use the same realsupported by an Os
several virtual resources. This way, it can resource to suppo
number resources than it actually does.
of give the impression of having a largei
the use of an appropriate real resource. In Each use of a virtual resource
that sense, a results l
view ofa resource taken by a virtual resource is an abstract
Jseof virtual resources computation.
Started with the use of virtual devices. To
interference between programs, it was a good idea to allocate a deviceprevent mutua
exclusively
Introduction 15
TOr use by one program. However, a computer system did not poSsess many real
devices, SO virtual devices were used. An OS would create a virtual device when a
user needed an I/O device. Thus, the disk areas called disk 1l and disk2 in Table 1.6
could be viewed as small virtual disks based on the real disk. Virtual devices are used
incontemporary operating systems as well. Aprint server is a common example of
a virtual device. When a program wishes to print a file, the print server simply
copies the file into the print queue. The program requesting the print goes on with
its operation as if the printing had been performed. The print server continuously
examines the print queue and prints any file it finds in the queue.
Mostoperating systems provide a virtual resource called virtual memory, which
is an illusion of a memory that is larger in size than the real memory of a computer.
Its use enables a programmer to execute a program whose size may exceed the size
of real memory.
Some operating systems create virtual machines (VMs) sothat each machine can
be allocated to a user. The virtual machines are created by partitioning the memory
and I/O devices of a real machine. The advantage of this approach is twofold. AI
location of avirtual machine to each user eliminates mutual interference between
users. lt also permits each user to select an OS of his choice to execute on his virtual
machine. Ineffect, this arrangement permits users to use differentoperating systems
on the same computer system simultaneously (see Section 14.5).
Security Resourcs
Intruder threats
Protection
threats
Internet
Programs
Authentication A Users
instruction.
Table 2.4 indicates some generic types of system calls and lists a few examples
Type Examples
Resource Allocateldeallocate resource, check resource availability
Program Setvawait timer interrupt,execute/terminate program
File Open/close a file, read/writea file
Information Get time and date, get OS information, get resource information
Communication Send/receive message, setup/terminate connection
Computation Description
Program Aprogram is a set of functions or modules, including some func
tions or modules obtained from libraries.
Job Ajob is a sequence of job steps, where each job step is comprised
of the execution of one program. It is not meaningful to execute
the program in ajob step unless programs in the previous job steps
were successfully executed (see Section 1.3.1).
Process A process is an execution ofa program.
Subrequest A subrequest is the presentation of a computational require
ment by a user to a process. Each subrequest produces a single
response, which iseither a set of results or a set of actions.
Table 2.5 describes the job, program, process and subrequest computations.
Notions of system performance and user convenience in an operating system depend
on the nature of computations. We discuss this issue in the next section.
2.2.2 Measuring Efficiency, System Performance and User Convenience
Measurement provides a quantitative basis for comparing alternative techniques used
in the design and implementation of an OS. However, several practical difficulties
arise in making quantitative comparisons. Some atuributes of an OS may be intan
gible hence numerical comparisons may not be possible, or techniques may possess
different attributes hence comparisons may not be meaningful.
48 Operating Systems
We encounter both difficulties when we consider
venience in different classes of operating systems.
intertaces provide intangible conveniences, and
efficifeatures
Some ency of likeuse annd user
different computing User con
use ditterent notions of cficiency and user convenience. Howeverthe
marized in Table 2.6 are useful to understand the impact of a tcchniquemeasures sum frie
environmentndiy
aspccific class. We use these measures in the
Svstems of'
Table .6 Measures of eticieney and user convenience following sectioonns.operating
Attribute Concept
Efficiency of use CPUefficiency Description
Percent utilization of the CPU.
System performance Throughput Amount of 'work' done per unit time.
User service Turn around time Time to complete a job or
Response time Time to process.
between aimplement
oneinteraction
user and his/her process.
Definition 2.4 (Response time) The response time provided to a subrequest is the time
between the subnission of the subrequest by a user and the formulation of the pro
cess's response to it.
2.3 CLASSES OF OPERATING SYSTEMS
2.3.1 Key Features of Different Classes of Operating Systems
Table 2.7 summarizes key features of five fundamental classes of operating systems.
Table 2.7 Key features of classes of operating systems
The periodcolumn shows the period when operating systems of that class first
came into widespread use. Interestingly, key features of the early OS classes can
be found in today's operating systems as well! In fact, that is why we study them
today. The prime concern column of Table 2.7 shows the fundamental effectiveness
criterion that motivated development of that OS class. The key concepts column
indicates concepts that were evolved to help in implementing the prime concerns of
an OS.
Batch processing and multiprogramming systems Acursory look at the prime con
cerns in different classesof operating systems reveals an interesting trend. The first
twoOS classes,viz. batch processing and multiprogramming, were concerned with
efficient use of a computer system. In batch processing, the concern was limited to
CPUefficiency, so avoiding wastage of CPU time was the prime concern. In multi
programming, the concernwas broadened to include other resources, mainly memory
and the /O subsystem, so a balanced utilization of all resources in the system was
those
the prime concern. These concerns arose from the high cost of hardware in
days, and satisfying these concerns did not provide any direct benefits to users.
Time sharing and real timne systems In mid-seventies, the focus shifted from effi
was
cient use of a computer system to productivity of computer users. This shift
necessitated by the clamor for efficient service by users, and it became practical due
to reducing costs of hardware. Time sharing systems focused on providing a quick
50 Operaling Systems
Distributed systenms In the 1990s, declining hardware costs led to the develop
ment of disributed systems that consisted of several computer systems with varying
nunber and sophistication of resources. Adistributed system permits resource shar
ing across the boundariesof individual computer systems. Thus, a user of a low cost
computer system can use expensive resources existing in other computer systems.
Somefeatures of resource sharing resemble efficient use of resources. However, it
possesses other important features like fault tolerance that have much to do with user
Convenience.
Multi
\programming
Time Distributed
sharing OS
Efficicnc y
Real
time OS
Batch
processing
Computer systems of the 1960's used punched cards as the primary input mediun.
A program and its data consisted of a deck of cards. A programmer would submit a
program at a counter in the computer center. The computer center staff would handle
the card decks and eventually the onthe
execution of a program would be set up
and
computer by a computer operator. The operator too had to handle the card decksSome
perform physical actions like loading them into the card reader and pressing
switches on the console toinitiate processing of a program. The CPUofthe compuler
system was idle while the CPUtime was
operator
performed these actions. Alot of
wasted in this manner. Batch processing was introduced to avoid this wastage.
batch
Abatch is a sequence of user jobs formed for the bya
purpose of processing
structure of a
processing operating system. Note that abatch is not a computational ypically
user. Each job in the batch is of other jobs in the batch; jobs setof
independent
belong different users. A computer
to organizing a and
operator forms a batch by Start
user jobs in a sequence and inserting special indicate the thebatch
end of the batch. The marker cards to by
operator submits a batch as a unit of processing
Overview of Operating Systems 53
processing operating system. The primary function of the batch processing system
is to service the jobs in abatch one after another without requiring the operator's
intervention. This is achieved by automating the transition from execution of one job
to that of the next job in the batch.
Batch processing is implemented by the kernel (also called the batch monitor),
which resides in one part of the computer's memory. The remaining memory is used
for servicing a user jobthe current job in the batch. When the operator gives a
command to initiate the processing of abatch, the batch monitor sets up the process
ing of the first job of the batch. At the end of the job, it performs job termination
processing and initiates execution of the next job. At the end of the batch, it performs
batch termination processing and awaits initiation of the next batch by the operator.
Thus the operator needs to intervene only at the start and end of a batch.
System Batch
area Monitor
1 job job; jobn ‘
User Current 'Start of batch' End of batch
area
Job of card card
the batch
Figure 2.12 shows a schematic of a batch processing system. The batch consists
of n jobs, jobj, job. job,,, one of which is currently in execution. The figure
depicts a memory map showing the arrangement of the batch monitor and the current
job of the batch in the computer's memory. The part of memory occupied by the
batch monitor is called the system area, and the part occupied by the user job is
called the user area.
Batch processing systems used the notion of virtual devices described in Sec
tion 1.3.2.1 to conserve the CPUtime of a powerful computer system as follows:
The computer system used virtual devices for input and outputtypically tapes or
disks instead of punched cards and printers. To make this feasible, a program first
recorded a batch of jobs on a magnetic tape. The batch processing system processed
these jobs and wrote theirresults on another magnetic tape. The contents of this mag
netic tape were then printed by another program. The two spooling operations, called
inspooling and outspooling, respectively, were typically performed on asmaller com
puter system having a slow CPU. The main computer used the faster magnetic tape
mediahence it suffered smaller CPU idle imes. Results of ajob were not released to
auser immediately afer the job was processed: they were released only after printing
wascompleted.
$4 Operating Systenms
2.4.1 User Service
The notion of turn-around time is used to quantify user service in a bateh processing
system. Duc to spooling, the turn-around time of ajobjob; processed in a batch
processing system includes the following time intervals:
1. Time until a batch is formed (i.e., time until the jobs jobi+|, . job, are sub
mitted)
2. Time spent in executing alljobs of the batch
5. Time spent in printing and sorting the results belonging to different jobs.
Thus, the turn-around time for job; is a function of many factors, its own execution
time being only one of them. It is clear that use of batch processing does not guaran
tee improvements in the turn-around times of jobs. In fact, the service to individual
users would probably deteriorate due to the three factors mentioned above. This is
not surprising because batch processing does not aim at improving user service-it
aims at improving CPU utilization.
Example 2.5 Figure 2.13 illustrates different components in the turn-around times
of a job. The user submits the job at time tÍ. However, the batch is not formed
immediately. The operations staff of the computer center form a batch only after a
sufficient number of jobs have been submitted. Consequently, the batch actually gets
formed at time f. Itsprocessing starts at time and ends at t,. Printing of the results
is commenced at time l4 and completes at t_. The results are returned tothe user only
at time to. Thus the turn-around time of the job is (t6 to). It has no direct relation to
its own execution time.
Batch Result
execution printing
t2 t6
To exercise effecive control over the batch processing environment, the batch mon
itor performs three functions-scheduling, memory management, and sharing a
protection. The first two functions are trivial. Scheduling is implicit in formation o!
a batch, while memory allocation is performed at system boot time by allocating all
memory not used by the OS to the processing of user jobs. The memory is shared
sequentially by user jobs.
Overvicw of Operating Systems 55
The protection function is more complex. User jobs cannot interfere with each
other's execution directly because they never coexist in acomputer's memory. How
ever. contrary to one's intuition, even sequential sharing of resources can lead to loss
of protection. This problem is discussed in the following.
Protection problems in card based systems As mentioned at the start of this Sec
tion, early batch processing systems were card-based systems of the 1960's. These
systems possessed few secondary memory units like tapes and disks, so commands,
user programs, and data were all derived from a single input source-the card reader.
This feature could lead to interference between consecutive jobs in a batch. Exam
ple 2.6 illustrates how this can happen.
Example 2.6 A and B are consecutive jobs in a batch. Each job consists of a program
and its data. The program of job A requires ten data cards whereas the user who
submitted job A has included only five data cards in it. When job A executes, it reads
its five data cards and the first five cards of job B as its own data. When job B is
processed, the compiler finds many errors since the first five cards of B are missing.
Thus job A has interfered with the execution of job B.
Pawal
proyran
Data for
Pascal
progran
, 'Endof data' staterneit
'End of job' statement
Fig. 2.14 Control statements in lM
360/370 sysem%
Concurrency of operation between the CPUand the I/O subsystem (see Section 2.Il)
can be cxploitedto get more work donein the system. The OS can put
programs in thememory, and let the CPU execute instructions of one many user
the I/)subsystem is busy with an l/O operation for program while
iscalled multiprogramming. another program. This technique
Figure 2. 15 illustrates operation of a
tains three programs. An I/O operation is inmultiprogramming OS. The memory con
CXCCuling progran,. The CPUis switched toprogress for program1. while the CPUIs
program when program; initiates an
1/0operalion, and it is switched to program when
pletes. The multiprogramming kernel performs program 's I/O operation com
and I/0management. It uses a simple scheduling. memory management
scheduling
Section 2.5,3,1, and performs simple partitioned orpolicy, which we will discuss in
ory and I/0 devices. pool-based allocation of mem
(Scheduling, memory management and I/O management are
discussedin detail in Chapters 4, 5-6, and 7-12,
ure 2.12, cach program in the respectively.) As shown in Fig
memory could be a program in the current job of a
Overview of Operating Systems 57
Multiprogramming
Kenel
Multiprogramming
Kernel
Multiprogramming
Kernel
|/O
Program| program CPU progran|
5 b := a+5;
and UBR by using these instructions, a program interrupt would be raised becausa
the CPUis in the user mode while exceuting user programs; the kernel would abor
the program while servicing this interrup1.
Table 2.9 Architeural support for multiprogranning
Feature Description
DMA The CPUinitiates an I/O operation when an l/Oinstruc
tion is executed. The DMA implements the data transfer
involved in the l/O operation without involving the CPU,
and raises an l/O interrupt when the data transfer completes.
Memory protection Ensures that a program does not access or destroy contents
of memory areas occupied by other programs or the OS.
Privileged mode Certain instructions, called privileged instructions, can be
of CPU performed only when the CPUisin the privileged mode. A
program interrupt is raised if a program tries to execute a
privileged instruction when the CPU is in the user mode.
Since several programs are in memory at the same time, the instructions, data,
and VO operations of one program should be protected against interference by other
programs. It is achieved simply by putting the CPUin the user mode while executing
user programs.
2.5.2 User Service
Scheduling is performed after servicing every interrupt (see Figure 2.8). Mul
liprogramming systems use a simple priority based scheduling scheme described in
the next Section. Functions 2 and 3 involve allocation of memory and I/O devices.
Simple partitioned or pool-based allocation can be used for this purpose. Resource
sharing necessitates protection against mutual interference--the instructions, datla,
and 1/Ooperations of one program should be protected against interference by other
59 hardware
pro programs.processing
memory to
throughput,over programs
CPU, andin anddiffer
based.
interrupt. than de following. be
Systems other taken activities
concepts eXe
in
programs
programs throughput
the computation lot
larger of priority in
memory pro in
CPU
tinme computa al it. preempted prog
bursts.
userits Interrupt
protection time on
several number VO-bound a use
always
Operating to outside an is be their the
involving
long
to and
allocated instructions the the small
executingcaused OS totalprocessesn may actual using
in a little wishesCPU. prog1
uses keeps usesfor isCPU is
multiprogramming in muchoverlapsufficient
techniques in CPU
situated the This and program CPU veryCPU the of
of Memory interrupt.
that activities It that
However,systemexecution OS The theuse mix Let
Overview memory and CPU-boundI/O.
while program that-to). executehow can the
Description
the involves
operation.the program
on to
locations processed a littleuses priority. m=2.
a that uses wishes proper
executing
this. mode an OS n/(tf because i.e.,kernel keeps and
multiprogramming is
very
with to mayoperations. their programs program it program
It priority
processed, concepts I/O
achieve the
leads multiprogramming
is system of andis, I/O, aassigned program a with
non-privileged
memory mix where
interfering
terminate a programs tr system program the overlaps an
bursts-that program keep
of computation of
CPU-bound starting
I/0-bound highest system
now at well user a lot
performance ends VO The these memory,
keeps prioritymust
to a isprogram
Every
used instruction,
access System processingbeing how and of before and thepriority OS multiprogram
from simply of and simultaneouslyoneperform a 2.10. discuss The
number
multiprogramming time.
any
at The
kernel long
andthroughput,
programs memory An tion to higher
numberatto in A of
are theto Multiprogramming a grams located
low an
program Table "
in program
provisions interrupts of of starts programs perform,
We a why
put privileged Throughputbatch A if
measure
the in in scheduling. see
is that of programs
thedescribed Concept/Technique
a CPU user of a nature
they in
multiprogramming To
prevent these ratio time of other optimize techniques preemptive
and
Priority-based a
Two mix consider
thea a appropriate throughput place I/O Program
mix
by use a the of
them. the of preemptive ofDegree scheduling Program
for of some much techniques
to andetfort
programs. to period
is process take on To kinds and
Performance
usedgrams,or routines which pends cution,
Anyarea, An maywhile howtime. ent Concepts
is thethe
2.10
2.5.3.1
Table
60 Operating Systems
programs are heavily
the two programs under processing. Let us assume that both
CPU-bound and prog1 is currently executing. Being CPU-bound. prog1 performs
along burst of CPUactivity before performing an /O operation. CPUis
given to
of
prog: when prog1 initiates an I/O operation. prog2 also perlorms a long burst
CPU activity before perfornming an l/Ooperation. prog1 would have finished its J/O
operation by this time, so it can use the CPU for another burst of compuation. In
this manner the CPU is kept busy most of the time. I remains idle only when both
programs simultancously perform I/O. The /O subsystem is underloaded. In fact.
it is idle most of the time because programs contain long CPUbursts, so periods of
concurrent CPUand /O activities are rare. Consequently, the throughput is low.
To analyze the throughput of this multiprogramming system, we will compare
it with a batch processing system processing the same two programs. The batch
processing system would service the programs one after another, i.e., either in the
sequence prog1. prog2 or in the sequence prog:. prog1. The throughput would be
identical in both cases. For comparing the throughput of the batch processing and
multiprogramming systems, we introduce the notion of progress of a program. A
program 'makes progress when either the CPU is executing its instructions or its
VOoperation is inprogress. Throughput would be higher if several programs make
progress concurrently.
In our example. progi and prog2 make progress concurrently only when one of
them performs I/O and the other executes on the CPU, ie., only when the CPUand
the VO subsystem execute concurrently. Such periods are rare, so periods when both
programs make progress are also rare. Consequently. throughput of the multipro
gramming system is likely to be much the same as the batch processing system.
A practical way to improve the throughput is to select amix of programs that
contains some CPU-bound programs and some I/O-bound programs. For example,
let a multiprogramming system with n=2contain the following programs:
Example 2.9 The timing chart of Figure 2.16 depicts operation of the system when
prog¢b, the CPU bound program, has higher priority. Note that the chart is not to
scale. The CPU activity of progiob and the I/O activitiesof both programs have been
exaggerated for clarity.
CPUidle
CPU progiob
activity
proßcb
progiob
activity
progcb
|WOidle
0 I|| 12 t|3l14
time
Fig. 2.16 Timing chart when CPU-bound program has higher priority
From observation 3 it is clear that most of the time only one of the two pro
grams is able to make progress, so the throughput is not much better than in a batch
processing system. Attempts to improve the throughput by increasing the degree of
multiprogramming meet with litle success. For example, let us increase the degree
Overview of Operating Systems 63
of multiprogramming (n) to 3 and introduce a
ority between those of progch and progiab. ThisCPU-bound programprog3 with a pri
action improves the CPU utilization
since the new program can keep the CPU busy over
been idle if m was 2 (see interval t1p-a). However., itintervals where it would have
of the I/Outilization because prog,ob leads to further deterioration
receives
of an /0-bound program (say, proga) instead lesser opportunity to execute. Adoluon
of proga makes little difference to the
CPUand I/O utilization because progA Would have the lowest
get much opportunity to execute. priority, so it does not
CPUidle
CPU
progiob
activity |
progeb.
progiob
activity
progcb
VO idle
I22 I23
time
Fig. 2.17 Timing chart when O-bound program has higher priority
Throvghput
1 3
Degree of multiprogramming
Fig. 2.18 Variation of throughput with degree of
multiprogramming
When m= 1,the throughput is dictated by the elapsed time of the lone program
Overview of Operating Systems 65
User service is characterized in terms of the time taken to service a subrequest, 1.e.,
the response time (rt). Benefits of good response times are best seen during program
development. Auser engaged in program development compiles and tests a program
repeatedly. Atypical request issued by the user concerns compilation of a statement
or an execution of a program on given data. The response consists of a message from
the compiler or results computed by a program. Auser issues the next request after
receiving the response to the previous request. Good response times would lead to an
improvement in the productivity of the user. Any application in which a user has to
interact with a computation would derive similar benefits from good response times.
Emphasis on good response times, rather than on efficient use or throughput,
requires use of new design principles and techniques. The notion of a job is no
longer relevant, an interactive user interface has to be designed, and new scheduling
and memory management techniques are needed to provide good response times to
a large number of users. These changes are discussed in the following Sections.
2.6.2 Scheduling
User service in a time sharing system is characterized by response times to user
requests, so the time sharing kernel must provide good response times to all users. To
realize this goal all users must get an equal opportunity to present their computational
requests and have them serviced. Each user must also receive reasonable service.
Two provisions are made to ensure this.
1. Programs are not assigned priorities because assignment of priorities may deny
oS attention to low priority programs. Instead, programs are executed by turn.
66 Operating Systems
amounts of CPUtime
2. Aprogram is preventcd from consuming unreasonable will
when scheduled to exccute. This provision ensures that every request
receive OS attention without unreasonable delays.
These provisions are implemented using the techniques of round-rob1n scheduling
and time slicing, respectively.
Round-robin scheduling When a user makes a computational request to his pro
gram, the program is added to the end of a scheduling list. The scheduler always
removes the first program from the scheduling list and gives the CPU to it. When
aprogram hnishes computing its response to a request, it is removed from the CPU
and the first program in the new list is selected for execution. When the user makes
another request, the program is once again added to the end of the scheduling list.
Time slicing The notion of a time slice is used to prevent monopolization of the
CPUby a program.
Definition 2.7 (Tme slice) The time slice is the largest amount of CPUtime any
program can consume when scheduled to execute on the CPU.
Time slicing is an implementation of the notion of a time slice. Every program is
subjected to the time limit specified by the time slice. A program exceeding this limit
is preempted. Figure 2.19 illustrates a schematic of round-robin scheduling with time
slicing. Apreempted program is added to the end of the scheduling list. A program
may be scheduled and preempted a few times before it produces a response.
Preempted program
time slice
Over
Scheduler CPU
In Step Sthe preempted program is put at the end of the scheduling list. If a
program does not consume ðseconds of CPUtime, e.g., if it starts an VOoperation,
the kernel simply schedules the next program. When an I/O completion interrupt is
raised the kernel identifies the program whose VO operation has completed and adds
the program at the end of the scheduling list.
Example 2.11 Figure 2.20 illustrates operation of Algorithm 2.1 in a time sharing
system using time slice . It is assumed that scheduling overhead of the OS is o
seconds. Figure 2.20(a) depicts the situation when the time slice elapses during exe
cution of a program. The kernel preempts this program and schedules another pro
gram for execution. The new program therefore starts executing o seconds after the
time slice elapses. In Figure 2.20(b), the program executing on the CPU makes an
VO request. After starting the VO operation, the kernel schedules another program
for execution. If we ignore the 0S overhead in initiating an I/O operation, the newly
scheduled program starts executing Gseconds after the VO request was made.
Program is Program is Program is Program is
scheduled scheduled scheduled scheduled
(a) (b)
after recciving response to theprevious request, the response time fr ) and the CPU
efticiency () are given by
n.(8+o) (2.2)
(2.3)
The actual response time may be different from the value ofr predicted by Eg.
(2.2). There are several reasons for this. First, the value of rt may bc smaller than
that predicted by Eq. (2.2) because all users may not have made requests to their
programs. Hence rt would not be influenced by n, the total number of users in the
system; it would be influenced by the number of active users (a), ng K n. Second,
user requests do not require exactlyÓ CPæ seconds to produce a response, so the
relationship of rt and n with Õ
is more complex than shown in Eqs. (2.2) and (2.3).
Table 2.12 summarizes the effect of small or large values ofð. Fromn this one can
conclude that rt may not be small for small ð and n may not be large for large ò,
which makes the choice of Ó a sensitive design decision.
Table 2.12 Influence ofð on response time
CPU
(a)
/O
(b)
CPU P)
I/O
CPU P
P2
(c) VO P
P2
50 100 150 200
time
Fig. 2.21 Execution of programs P and P by themselves, and together
of operation of the system. Now P2 gets two consecutive time slices (separated, of
course, by OS overhead for actions that first preempt program P and then schedule
it again because no other program in the system needs the CPU). P's VO operation
completes at 125 msec. P2 starts an I/Ooperation at 45 msec, which completes at 105
msec. Thus, the response times are 125 msec and 105 msec, respectively. Table 2.13
shows the scheduling list and scheduling decisions of the kernel between 0 and 105
msec assuming scheduling overhead to be negligible.
70 Operating Systems
2.6.3 Memory Management
In Example 2.12, the CPU was idle between 45 msec and 105 msec, so the sveters
can service a few more user programs. However:, the computer system
must poSseSs a
large memory to accommodate all these programs, which is an expensive proposition
The technique of swapping provides an alternative whereby acomputer system can
Supporta large number of users without having topossess a large memory.
Definition 2.8 (Swapping) Swapping is the technique of temporarily emoving
inactive programs from the memory of a computer system.
An inactive program is one which is neither executing on the CPU, nor perform
ing an I/Ooperation. Figure 2.22 illustrates swapping as used in a practical situation.
The programs existing in the memory are classified into three categories:
1. Active programs-one active program executes on the CPU while others
perform VO.
2. Programs being swapped out of the memory.
3. Programs being swapped into the memory.
Kernel
Programs being
swapped out
Program in Swapped out
execution
programs
Programs being
swapped in
Definition 2.9 (Real time application) Areal time application is a program that
responds to activities in an external system within amnaxinum time determined by
the external system.
If the application takes too long to respond to an activity, a failure can occur in
the externalsystem. We use the termresponse requirement of a system to indicate the
largest value of response time for which the system can function perfectly; a timely
response isone whose response time is smaller than the response requirement of the
system.
Consider a system that logs data received from asatellite remote sensor. The
satellite sends digitized samples to the earth station at the rate of 10000 samples
per second. The application process is required to simply store these samples in a
file. Since anew sample arrives every 100 microseconds, the computer must respond
of a
to every "store the sample" request in less than 100 microseconds, or arrival
new sample would wipe out the previous sample in the computer's memory. This
less than 100
system 1S areal time application because asample must be stored in
microseconds to prevent a failure. Its response requirement is 99,9 microseconds.
the action
The deadline of an action in a real time application is the time by which
should be performed. In the above example, if a new samplemicroseconds.is received from the
satellite at time t, the deadline for storing it on disk ist +99.9
command
Examples of real time applications can be found in missile guidance, sampling
traffic control, data
and control applications like process control and air
in automobiles, multimedia sys
and data acquisition systems like display systems systems that are based on use
banking
tems, and applications like reservations and
requirements of these systems vary from a few
of real time data bases. The response systems to a few seconds for
microseconds or milliseconds for guidance and control
reservations and banking systems.
2.7.1 Hard and Soft Real Time Systems
maximum
advantage of the features of real time systems while achieving
To take have evolved. Ahard real time
cost-effectiveness, two kinds of real time systems provably meets
processing real time applications, and
system is typically dedicated to application under all conditions. Asoftreal time sys
an
the response requirement of meet time application
theresponserequirement of a real
tem makes the best effort to able to meet it under all conditions. Typically, it
will be
but cannot guarantee that it some probabilistic manner, say, 98 percent
of the
requirements in time
meets the response
control applications fail if they cannot meet the response
time. Guidance and Appli
they are typically serviced using hard real time systems.
applications
requirement,hence quality of service, e.g., multimedia failure. so
cations that aim at providing good
have a notion of
applications like reservations and banking, do not
and
72 Operating Systems
they may be serviced using soft real time systems-the picture quality provided bw
a video on demand system may deteriorate occasionally, but one can still watch tha
video!
Areal time OS provides the special fcatures summarized in Table 2.14, Areal
time application can be coded such that thc 0S can execute its parts concurrently
When priority-based scheduling is used, we have a situation analogous to multi
programming within the application--if one part of the application initiates an /O
operation, the OS would schedule another part of the application. Thus, CPUand
I/O activities of the application can be overlapped with one another, which helps to
reduce the worst-case response time to the application. Deadline scheduling is a spe
cial scheduling technique that helps an application meet its deadline. Some aspects
of deadline scheduling are described later in Section 4.2.
Table 2.14 Features of a real time operating system
(RTOS)
28 DISTRIBUTEDOPERATING SYSTEMS
A distributed computer system consists of several individual computer systems Con
nected through anetwork. Thus, many resources of a kind, e.g.., many memories,
CPUs and I/Odevices, exist in the distributed system. Adistributed operating sys
tem explots the multiplicity of resources and the presence of a network to provide
the advantages of resource sharing across computers, reliability of operation, speed
up of applications, and communication between users. However, the possibility of
network failures or failures of individual computer systems complicates functioning
of the operating system and necessitates use of special techniques in its design. Users
also need to use special techniques to access resources over the network. We discuss
these aspects in Section 2.8.1.
Table 2.15 Features of distributed operating systems
Feature Description/Implication
Resource sharing Improves resource utilization across boundaries of
individual computer systems.
Reliability Availability of resources and services despite failures.
Computation speed-up Parts of a computation can be executed in different
computer systems to speed-up the computation.
Communication Provides means of communication between remote
entities.
Incremental growth Capabilities of a system (e.g., its processing power)
can be enhanced at a price proportional to the nature
and size of the enhancement.
systems. Resource
Table 2.15 summarizes advantages of distributed operating
operating systems. The
sharing has been the traditional motivation for distributed operating system,
earliest form of a distributed operating system was a network
resources by geograph
which enabled the use of specialized hardware and softwareimportant aspect of dis
to be an
ically distant users. Resource sharing continues
of disribution and sharing of
tributed operating systems today, although the nature technology. Sharing of
networking
resources has changed due to advances in the
equally meaningful in a local area network (LAN), Thus. low-cost
resources is now
laboratory can share some expensive
computers and workstations in an office or a
resources like laser printers.
aspect of reliability is availab1lity of a resource despite failures in a sys
One
74 Operating Systems
'Technique Description
Disributed control A conrolfunction is performed through participation of sev
eralnodes, possibly all nodes, in a distributed system.
Transparency A resource or service can be accessed without having to
know its location in the distributed system.
Remote procedure Aprocess calls aprocedure that is located in a different com
call (RPC) puter system. The procedure call is analogous to a procedure
or function callin a programming language, except that It is
the OS that passes parameters to the remote procedure and
relurns its results. Operation of the process making the call
is resumed when results are returned to it.
ransparency, a distributed file system may move a file to the node that contains a
computation using the file, so that the delays involved in accessing the file over the
network would be eliminated. The remote procedure call (RPC) is used by an The
ap
plication to execute a procedure in another computer in the distributed system.
remote procedure may perform a part of the computation in the application, or it may
use a resource located in that computer.