Operating Systems
Operating Systems
Operating Systems
OPERATING SYSTEM
Subject: OPERATING SYSTEM Credits: 4
SYLLABUS
Importance
Importance of Operating Systems, Basic Concepts and Terminology, An Operating System Resource
Manager
Management Processes
Concept, Processes and Threads. Process Model and Thread Model. Job Scheduler, Process Scheduling,
operation on process,.
Overview of Inter-process communication: Race Conditions, Critical Regions, Mutual Exclusion with busy
waiting etc.
CPU Scheduling
Introduction to Scheduling, Scheduling criteria, Scheduling Algorithms, Algorithm Evaluation and Scheduling
in different Systems.
Process Synchronization
Synchronization Hardware, Semaphores, and Classical Problem of Synchronization, Monitors and Atomic
Transaction DEADLOCKS Introduction to Deadlocks: Resources, conditions for Deadlocks and Deadlock
modeling, Deadlock Characterization.
With one Resource of each type and With Multiple Resource of each type.
Deadlocks Prevention
Attacking the Mutual Exclusion, Hold and Wait, No Preemption and Circular conditions. STORAGE
MANAGEMENT Basic Memory Management Partition of Memory. Multiprogramming with fixed
partitions. Logical versus Physical Address Space, Swapping, Contiguous Allocation
Virtual Memory:
Demand Paging, Page Replacement, Page Replacement Algorithms, and Allocation of Frames, Thrashing,
and Demand Segmentation INFORMATION MANAGEMENT Introduction; File Concept, Directory
Structures, Protection, Overview of File-System Structure, Allocation Method, Free-Space Management,
Directory Implementation
Suggested Readings:
COURSE OVERVIEW
The course aims at facilitating students to obtain professional c) Desire to studiously go through the study material and
research books, Net, etc. to gain significant knowledge.
knowledge and develop an understanding of the properties and
d) Ability to present his point view systematically/logically.
application of Operating Systems e) Ability to take criticism.
Through this unit we get the Basic Concepts and Terminology, f) Approach adopted to find solution to a given problem.
g) Communication skills.
Memory Management function, Processor Management
Function, device and information Management Function. Syndicate
It refers to the group of students who are assigned same tasks
This course give the basic as well as the advance concept of the
to be performed. In our system the assignments are executed
Operating System that are required by every computer literate.
by the Syndicates. This helps in inculcating the culture of team
Summary of outcomes work. It also helps those who are not as good in the subject as
Upon the completion of the course, students should be able to
some of their other colleagues are. The Syndicate accomplishes
Examine the concepts of Operating Systems
the assignment as under:
Concept of Process Management
a) Initial discussion to identify the job description.
Concept of Storage Management
Completion of the assigned job within the allocated time
Concept of File-System Management frame.
b) Integration of the inputs to an unified Syndicate solution
Course Requirements
Prerequisite: Assignments
Each student is expected to submit two assignments per
Lecture: 4 Practical: 0 Credit: 4
subject during the semester. The system of assignment follows
Class Participation: the procedure given below:
It forms the backbone of the system of Continuous
a) Different assignment is given to different Syndicate.
evaluation. The students are expected to have gone through the b) Each member of the Syndicate is expected to participate
pre-study material and come prepared for discussion. We equally to solve the given problem.
c) All students of the syndicate are expected to submit the
visualize that the quantum and quality of learning through
assignment individually. While they are expected to present
discussion would be much superior to simple delivery of the common solution, they have the opportunity to express
themselves as individuals and demonstrate their exceptional
course material in the classroom. The process is intended to
ability. They may recommend deletion/modification/
identify the following aspects in a student: addition to the syndicate solution.
a) Commitment to learning. d) Students may furnish additional data / information
downloaded from the Internet/other literature and put up
b) Regularity to attend classes.
diverse views away from to syndicate solution.
i
e) Each student is required to make self and peer evaluation in
OPERATING SYSTEMS
student is expected to meet the attendance requirement of 75% to increase processing speed.
ii
OPERATING SYSTEMS
real-time system - a computer which has a very narrowly The operating system is the first component of the systems
defined set of response times which it must meet. This is programs that interests us here. Systems programs are
common in time critical operations programs written for direct execution on computer hardware in
soft real-time system - the system gives a real-time task high order to make the power of the computer fully and efficiently
priority but does not guarentee the system reaction time. This accessible to applications programmers and other computer
is common with multimedia and network servers users. Systems programming is different from application
hard real-time system - the system gives a guarenteed programming because the requires an intimate knowledge of
response time and is dedicated to the task. Common in the computer hardware as well as the end users needs.
robotics and medical systems.Introduction into Operating Moreover, systems programs are often large and more complex
system than application programs, although that is not always the case.
An operating system is a program that acts as an interface Since systems programs provide the foundation upon which
between a user of a computer and the computer hardware. The application programs are built, it is most important that
purpose of an operating system is to provide an environment systems programs are reliable, efficient and correct.
1.1 Definition
in which a user may execute programs.
In a computer system the hardware provides the basic
An operating system is an important part of almost every
computing resources. The applications programs define the
computer system. A computer system can roughly be divided
way in which these resources are used to solve the computing
into three components :
problems of the users. The operating system controls and
The hardware (memory, CPU, arithmetic-logic unit, various
bulk storage, I/O, peripheral devices... ) coordinates the use of the hardware among the various
Systems programs ( operating system, compilers, editors, systems programs and application programs for the various
loaders, utilities...) users.
Application programs ( database systems, business
programs... ) The basic resources of a computer system are provided by its
hardware, software and data. The operating system provides
A computer system can be described or shown in Figure. 1.1 the means for the proper use of these resources in the
operation of the computer system. It simply provides an
environment within which other programs can do useful work.
Figure 1.1 Conceptual view of a computer system for their tasks. Since there may be many, possibly conflicting,
requests for resources, the operating system must decide which
The central processing unit ( CPU) is located on chips inside the
requests are allocated resources to operate the computer system
system unit. The CPU is the brain of the computer. This is the
fairly and efficiently. An operating system is a control program.
place where the computer interprets and processes information.
This program controls the execution of user programs to
prevent errors and improper use of the computer.
iii
OPERATING SYSTEMS
Operating systems exist because they are a reasonable way to Though systems programs such as editor and translators and
solve the problem of creating a usable computing system. The the various utility programs (such as sort and file transfer
fundamental goal of a computer system is to execute user program) are not usually considered part of the operating
programs and solve user problems. system, the operating system is responsible for providing access
to these system resources.
The primary goal of an operating system is a convenience for
the user. Operating systems exit because they are supposed to
make it easier to compute with an operating system than
without an operating system. This is particularly clear when you
look at operating system for small personal computers.
iv
OPERATING SYSTEMS
OPERATING SYSTEM
CONTENT
. Lesson No. Topic Page No.
vi
OPERATING SYSTEMS
OPERATING SYSTEM
CONTENT
Lesson 25 99
Lesson 26 103
Lesson 27 110
Lesson 28 113
vii
UNIT 1
LESSON-1
OPERATING SYSTEMS
Hello,students, it is your first class and I will introduce you to the different stages of execution.
basic concepts of an operating system - Why should you need an Operating System?
You will understand what is an operating system. The feature of operating system is to execute multiple programs
Why should you learn Operating System. in interleaved fashion or different time cycle is called multiple
programming systems. Some of the important reasons why do
To understand an Operating Systems ,you need to know what is
you need an Operating System are as follows:
an Operating System
User interacts with the computer through operating system in
An Operating System is system software which may be viewed
order to accomplish his/her task since it is his primary interface
as an organized collection of software consisting of procedures
with a computer.
for operating a computer and providing an environment for
execution of programs. It acts as an interface between users and It helps the user in understand the inner functions of a
the hardware of a computer system. computer very closely.
Now ,I will explain you the main purpose of an Operating Many concepts and techniques found in operating system have
System general applicability in other applications.
Convenience: transform the raw hardware into a machine that An operating system is an essential component of a computer
is more amiable to users. system. The primary objectives of an operating system are to
Efficiency: manage the resources of the overall computer make computer system convenient to use and utilizes computer
system hardware in an efficient manner.
Operating system can also be defined as: An operating system is a large collection of software which manages
resources of the computer system, such as memory, processor,
System software which may be viewed as an organized collection rite system and input/output devices. It keeps track of the status
of software consisting of procedures for operating a computer of each resource and decides who will have a control over computer
and providing an environment for execution of programs. resources, for how long and when. The positioning of operating
A large collection of software which manages resources of the system in overall computer system is shown in figure 1.
computer system, such as memory, processor, file system and
input/output devices. It keeps track of the status of each
resource and decides who will have a control over computer
resources, for how long and when.
It acts as an interface between users and hardware of a computer
system.
Colloquially, the term is most often used to mean all the software
which comes with a computer system before any applications
are installed.
Examples of operating systems
UNIX
GNU/Linux
Mac OS
MS-DOS
Let us discuss the fundamental goal of a Computer System
The fundamental goal of computer system is to solve user
problems. Accordingly to achieve this goal has been designed.
Since hardware alone cannot be used to solve the user problems
softwares are developed. These programs required certain common
operations. The common operations for controlling and allocating
resources are then brought together into one piece of software i.e.
operating system. An operating system may process its tasks
sequentially or concurrently. It means that the resources of the
computer system may be dedicated to a single program until its
1
Figure 1: Component of computer system To see what operating systems are and what operating systems
OPERATING SYSTEMS
From the diagram, it is clear that operating system directly controls do, let us consider how they have evolved over the years. By tracing
computer hardware resources. Other programs rely on facilities that evolution, you can identify the common elements of
provided by the operating system to gain access to computer system operating systems and examine how and why they have developed
resources. There are two ways one can interact with operating as they have.
system: OS and Hardware Development
By means of Operating System Call in a program OS development has gone hand-in-hand with hardware
Directly by means of Operating System Commands development:
Interrupts drive data transfer (using multiple CPUs, one
System Call:
designed exclusively for I/O processing)
System calls provide the interface to a running program and the
operating system. User program receives operating system services Direct-memory-access (DMA) data transfer
through the set of system calls. Earlier these calls were available in Hardware memory protection (to validate addresses)
assembly language instructions but now a days these features are Hardware instruction protection (only special users can execute
supported through high-level languages like C, Pascal etc., which some machine instructions)
replaces assembly language for system programming. The use of
Support for other interrupts: clock.
system calls in C or Pascal programs very much resemble pre-
defined function or subroutine calls. Old days: busy wait, e.g. printing:
2
. . | |
OPERATING SYSTEMS
. . 60000 ++
. . | J3 |
300 | yyyy < SW to handle interrupt type 1 | |
. . | |
. . | |
. . 90000 ++
HW support: for each interrupt type (e.g. clock interrupt, IO | J4 |
completion, change to supervisor state, invalid instruction) the | |
HW changes to program counter to a prewired memory address
| |
(in the above example, 100 for interrupt type 0, 101 for interrupt
type 1, etc.) This results in the specific code to handle that interrupt ++
being executed. |/////////////|
Examples: |/////////////|
1. Suppose clock interrupts are wired to memory location 100. ++
Then in a typical RR system, the interrupt causes a transfer to 2. Limit register: make sure user does not reference beyond
code which checks the cause of the timer interrupt. If the cause allocation memory size. Load limit register with size of memory
is that a process has gotten its time slice then scheduling allocated to process. HW traps (that is causes an interrupt) if
code will save the state of the current process, maybe do the process attempts to use an address larger than limit register
accounting, pick the next process to execute, restore its state, contents.
and start it. Note: this is NOT checked in software (much too slow). It must
2. Suppose memory location 102 is associated with the invalid be done in hardware as a side effect of addressing memory SO
instruction interrupt. What then? THAT NOTHING SLOWS MEMORY REFERENCES
Well, for one thing, this allows things the same machine code to DOWN. THE SAME GOES FOR THE USE OF THE BASE
be used in machines that dont have quite the same instruction REGISTER. If memory references are validated, the
sets (say, across a product line from cheap slow processors to mechanism must be very fast.
expensive fast processors). (Homework: explain how this might How does the OS get around this? Two basic approaches:
be done.) some machines allow interrupts to be turned off, or
Once the hardware supports this, then I/O can be handled much interrupt handler can check to see who is trying to do memory
more efficiently. It is also used for security. If some instructions reference.
are privileged, then if a normal process attempts to execute
them, the OS (through interrupt code) can validate what is Review Exercise:
happening. 1. Define an Operating System?
The point has been to do things FAST. So that things are only ______________________________________________________________________________
checked when they need to be. This requires a combination of ______________________________________________________________________________
HW and SW support.
______________________________________________________________________________
Memory Protection:
______________________________________________________________________________
1. Base register: contents of base register are automatically added
______________________________________________________________________________
(by HW) to each address. Not done by SW since this would be
too slow. ______________________________________________________________________________
Main Memory ______________________________________________________________________________
0 ++ ______________________________________________________________________________
| | To switch from J1 to J3, OS changes 2. Explain the need for an Operating System?
| OS | base register contents of 10000 to ______________________________________________________________________________
| | 60000. ______________________________________________________________________________
10000 ++ ______________________________________________________________________________
| | ______________________________________________________________________________
| J1 | This simplifies much system software. ______________________________________________________________________________
| | For example, compilers can now pretend ______________________________________________________________________________
40000 ++ that all code is loaded starting at ______________________________________________________________________________
| J2 | addr 0. ______________________________________________________________________________
3
Reference Books:
OPERATING SYSTEMS
Notes
4
LESSON-2
OPERATING SYSTEMS
Today I will explain you the evolution of an operating system and sequencing of operations involved in program execution and in
various types of operating systems the mechanical aspects of program development Programs With
similar requirements were batched together and 11m through the
Evolution of an Operating system: computer as a group.
As the need for better processing raised due to the increase in
demand for better processing speed and efficiency the operating Example:
systems have been enhanced with extra features. Operator received one FORTRAN program, one COBOL program
and another FORTRAN program. If he runs in that order ,he
Let us see what is Serial Processing?
would have to load FORTRAN compiler tapes, then COBOL
Instructions and data are feeded into the computer by means of
program Compiler and fma11y FORTRAN compiler again. If he
console switches or perhaps through a hexadecimal keyboard.
runs the two FORTRAN programs as a batch to save time.
Programs used to be started by loading the program counter register
with the address of the first instruction of a program and its With batch processing utilization of system resources has
result used to be examined by the contents of various registers improved quite a bit
and memory locations of the machine. Therefore programming Let us see,what happens when a job is stopped?
in this style caused a low utilization of both users and machine. When the job is stopped, the operator would have to notice that
With the advent of input output devices such as punched cards, fact by observing the console, determines why the program is
paper tapes and language translators (compiler) assembler) bought stopped and then loads the card reader or paper tape reader for the
significant computer system utilization. Programs were coded into next job and restarts the computer.
programming languages and then they are changed into object
Problems in batch Processing
code (binary code) by translator and then automatically loaded
into memory by a program called loader. Then the control is The CPU sits idle when there is a job transition.
transferred to loaded program, the exhibition of a program begins Speed discrepancy between fast CPU and comparatively slow
and its result gets displayed or printed. Once in memory, the input/output devices such as card reader, printers.
program may be re run with a different set of input data. The fist problem i.e. idle time of CPU can be overcomes by a
Let us have the look on the various Problems faced: The small program called a resident monitor will be created, which
process of development and preparation of a program in such resides always in the memory.
environment is slow and cumbersome due to serial processing
Resident Monitor:
and numerous manual processing.
It acts according to the directives given by a programmer through
In typical programming environment the following steps are control earth-which contain commands belonging to job control
performed. languages such as information like marking of jobs beginning and
The source code is created in the editor by writing a user ending, commands for loading and executing programs etc...
program. Example:
The source code is converted into binary code by the translator $COB - Execute the FORTAN compiler
and $JOB - First card of a job.
The loader is called to load executable programs into main $END - Last card of a job.
memory for execution. If syntax error is detected, the whole
$Load - Load program into memory.
program must be restarted from the beginning.
$RUN - Execute the user program.
The next evolution was the replacement of card - decks with
standard input output with some useful library programs, Card Deck for Simple COBAL batch program
which were further linked with user program through system
software called linker. While there was a definite improvement
overt machine language approach, the serial mode of operation
is obviously not very efficient. This results in low utilization of
resources.
Next Batch Processing has been evolved.
Batch Processing:
During the time that tapes were being mounted or programmer
was operating the console, the CPU sets idle. The next step in the
logical evaluation of operating system was to automate the
5
The second problem has been overcomes over the years through Spooling allows CPU to overlap the input of one job with the
OPERATING SYSTEMS
the technological improvement resulted in faster I/O devices. But computation and output of other jobs. Even in a simple system,
CPU speed increased even faster. Therefore, the need was to the spooler may be reading the input of one job while printing
increase the throughput and resource utilization by overlapping the output of a different job. Compared to buffering approach
I/O and processing operations. Dedicated I/O processors, spooling is better.
peripheral controllers brought a major development.
Multi-Programming
The development of Direct Memory Access(DMA) chip Was a Buffering and spooling improve system performance by
major achievement, which directly transfer the entire block of data overlapping the input, output and computation of a single job,
from its own memory buffer to main memory without but both of them have limitations. A single user cannot always
intervention of CPU .DMA can transfer data between high speed keep CPU or I/O devices busy at all times. Multiprogramming
I/O devices and main memory ,while the CPU is executing. CPU offers a more efficient approach to increase system performance. It
requires to be interrupted per block only by DMA. Apart from refers to a computer systems ability to support more than one
DMA, there are other two approaches to improve system process (program) at the same time. Multiprocessing operating
performance by overlapping input/output and processing. These systems enable several programs to nm concurrently. This is a
are: kind of parallel processing. More number of programs competing
Buffering for system resources which lead to better utilization of system
Spooling. resources. The idea is implemented as follows. The main memory
of a system contains more than on program as shown in the
1. Buffering:
figure.
It is a method of overlapping input/output and processing of a
single job. The idea is quite simple. After data has been read and
the CPU starts operating on it, the input device is instructed to
begin the next input immediately. The CPU and the input device
are both busy. The CPU can begin the processing of the newly
read data, while the input device starts to read the following data.
Similarly, this can be done for output In this case; the CPU creates
data that is put into buffer until an output device can accept it.
Now ,I will explain you the situation ,what happens if the CPU
is fast?
In the case of input, the CPU finds an empty buffer and has to
wait for the input device.
In Case of output, the CPU can proceed at full speed until,
eventually all system buffers are full .Then the CPU waits for
the output device. This situation occurs with input/output
bound jobs where the amount of input/output relation to
computations very high. Since the CPU is faster than the input/
output device, the speed of execution is controlled by the input/
output device, not by the speed of the CPU.
2. Spooling:It stands for simultaneous peripheral operation on
line. It is essentially use the disk as a large buffer for reading and
for storing output files as shown in the figure.
Multiprogramming
The operating system picks one of the programs and start
executing. During execution process program 1 may need some I/
6
O operation to complete. In a sequential Execution environment, Memory is usually divided into two areas. One of them is
OPERATING SYSTEMS
the CPU would sit idle. In a Multiprogramming system, operating permanently fixed for containing operating system routines and
system will simply switch over the next program. When that the other part contains only user programs to be executed; when
program needs to wait for some I/O operation, it switches over to one Program is over, the new program is loaded into the same
program 3 and so OIL if there is no other new program left in the area.
main memory, the CPU will pass its control back to the previous Since there is only one Program in the execution at a time, there is
programs. no competition for 110 devices, therefore, allocation and de-
Compared to operating system which supports only sequential allocation for 1/0 devices is very trivial.
execution, multiprogramming system requires some form of CPU Access to files is also serial and there is hardly a need of Protection
and memory management strategies. and file access control mechanism.
With each new generation of operating systems, you are introduced 2. Multiprogramming Operating System :
to new ways of thinking about how our computers work. To Multiprogramming operating systems compared to batch
simplify things for the user, you must deploy a consistent interface operating systems are fairly sophisticated. As illustrated in figure
in which they can do their work. It is equally important to extend 5, multiprogramming has a significant potential for improving
this consistency to programmers, so they too can benefit. As an system throughput and resource utilization with very minor
operating system ages, it gradually becomes burdened with a differences. Different forms of multiprogramming operating
plethora of interfaces which break the simplicity of its original system are multitasking, multiprocessor and multi-user operating
architecture. UNIX originally followed the everything is a file systems. In this section, we will briefly discuss the main features
mantra, only to lose sight of that design with numerous task- and functions of these systems.
specific APIs for transferring files (FTP, HTTP, RCP, etc.), graphics
(X11, svgalib), printers (lp, lpr), etc. Plan 9, introduced in 1989, Multitasking Operating Systems:
and demonstrated how even a GUI can be represented as a set of A running state of a program is called a process or a task. A
files, revitalizing the everything is a file idea. multitasking operating system (also called multiprocessing
operating system) supports two or more active processes
Let us discuss the Types of an Operating System
simultaneously. Multiprogramming operating system is operating
1. Batch Operating System: system which, in addition to supporting multiple concurrent
As discussed earlier during batch processing environment it requires process (several processes in execution states simultaneously)
grouping of similar jobs which consist of programs, data and allows the instruction and data from two or more separate
system commands. processes to reside in primary memory simultaneously.
The suitability of this type of processing is in programs with large Note that multiprogramming implies multiprocessing or
computation time with no need of user interaction/involvement. multitasking operation, but multiprocessing operation (or
Some examples of such programs include payroll, forecasting, multitasking) does not imply multiprogramming. Therefore,
statistical analysis and large scientific number crunching programs., multitasking operation is one of the mechanism that
Users are not required to wait while the job is being processed. multiprogramming operating system employs in managing the
They can submit their programs to operators and return later to totality of computer related resources like CPU, memory and I/O
collect them. devices.
But it has two major disadvantages: The simplest form of multitasking is called serial multitasking or
Non-interactive environment context switching. This is nothing more than stopping one
temporarily to work on another. If you have used sidekick, then
Off-line debugging
you have used serial multitasking. While a program is running,
Non-interactive environment: There are some difficulties with a you decide that you want to use the calculator, so you pop it and
batch system from the point of view of programmer or user. use it. When you stop using the calculator, the Program continues
Batch operating systems allow little or no interaction between running.
users and executing programs. The turn around time taken
Multiuser operating system allow simultaneous access to a
between job submission and job completion in batch operating
computer system through or more terminals. Although frequently
system is very high. Users have no control over intermediate results
associated with multiprogramming, multiuser operating system
of a program. This type, of arrangement does not create flexibility
does, not imply multiprogramming or multitasking. A dedicated
in software development.
transaction processing system such as railway reservation system
The second disadvantage with this approach is that programs that hundreds of terminals under control of a single program is
must be debugged which means a programmer cannot correct an example of multiuser operating system. On the other hand,
bugs the moment it occurs. general purpose time sharing systems (discussed later in this
Process scheduling (i.e. allocation strategy for a process to a section) incorporate features of both multiuser and
processor), memory management file management and I/O multiprogramming operating system. Multiprocess operation
management in batch processing are quite simple. without multiuser support can be found in the operating system
Jobs are typically processed in the order of submission, that is, in of some advanced personnel computers and in real systems
the first come, first served basis. (discussed later).
Time Sharing System:
7
It is a form of multiprogrammed Operating system which operates each process is assigned a certain level of priority according to the
OPERATING SYSTEMS
in an interactive mode with a quick response time. The user types relative importance of the even it processes. The processor is
a request to the computer through a keyboard. The computer normally allocated to the highest priority process among those
processes it and a response (if any) is displayed on the users which are ready to execute. Higher priority process usually pre-
terminal. A time sharing system allows the many users to emptive execution of lower priority processes. This form of
simultaneously share the computer resources. Since each action or scheduling called, priority based pre- emptive scheduling, is used
command in a time-shared system take a very small fraction of by a majority of real-time systems.
time, only a little CPU time is needed for each user. As the CPU
Memory Management:
switches rapidly from one user to another user, each user is given
In real-time operating system there is a little swapping of program
impression that he has his own computer, while it is actually one
between primary and secondary memory. Most of die time,
computer shared among many users.
processes remain in primary memory in order to provide quick
Most time sharing system use time-slice (round robin) scheduling response, therefore, memory management in real-time system is
of CPU. In this approach, Programs are executed with rotating less demanding compared to other types of multiprogramming
priority that increases during waiting and drops after the service is system. On the other hand, processes in real- time system tend to
granted. In Order to prevent a program from monopolising the cooperate closely thus providing feature for both protection and
processor, a program executing longer than the system defined sharing of memory.
time-slice in interrupted by the operating system and placed at the
I/O Management:
end of the queue of waiting program.
Time-critical device management is one of the main characteristics
Memory management in time sharing system Provides for the of real-time systems. It also provides sophisticated form of
protection and separation of user programs. Input/output interrupt management and I/O buffering.
management feature of time-sharing system must be able to handle
multiple users (terminals). However, the processing of terminals File Management:
interrupts are not time critical due to the relative slow speed of The primary objective of file management in real-time systems is
terminals and users. As required by most multiuser environment usually the speed of access rather than efficient utilisation of
allocation and deallocation of devices must be performed in a secondary storage. In fact, some embedded real-time systems do
manner that preserves system integrity and provides for good not have secondary memory. However, where provided file
performance. management of real-time system must satisfy the same
requirement as those found in time sharing and other
The words multiprogramming, multiprocessing and multitasking
multiprogramming systems.
are often confused. There are, of course, some distinctions between
these similar, but distinct terms. 3. Network Operating System
A network operating system is a collection of software and
The term multiprogramming refers to the situation in which a
associated protocols that allow a set of autonomous computers
single CPU divides its time between more than one job. Time
which are interconnected by a computer network to be used
sharing is a special case of multiprogramming, where a single
together in a convenient and cost-effective manner. In a network
CPU serves a number of users at interactive terminals.
operating system, the users are aware of existence of multiple
In multiprocessing, multiple CPUs perform more than one job at computers and can log in to remote machines and copy files from
one time. Multiprogramming and multiprocessing are not one machine to another machine.
mutually exclusive. Some mainframes and super mini computers
Some of typical characteristics of network operating systems which
have multiple CPUs each of which can juggle several jobs.
make it different from distributed operating system (discussed in
The term multitasking is described any system that runs or appears the next section) are the followings:
to run more than one application program one time. An effective
Each computer has its own private operating system instead
multitasking environment must provide many services both to
of running part of a global system wide operating system.
the user and to the application program it runs. The most
important of these are resource management which divides the Each user normally works on his/her own system; using a
computers time, memory and peripheral devices among competing different system requires some kind of remote login, instead
tasks and inter-process communication, which lets tasking of having the operating system dynamically allocate processes
coordinate their activities by exchanging information. to CPUs.
Users are typically aware of where each of their files are kept and
Real-time Systems:
must move file from one system to another with explicit file
It is another form of operating system which is used in
transfer commands instead of having file placement managed
environments where a large number of events mostly external to
by the operating system.
computer systems, must be accepted and processed in a short
time or within certain deadlines. Examples of such applications The system has little or no fault tolerance; if 5% of the personnel
are flight control, real time simulations etc. Real time systems are computers crash, only 5% of the users is out of business.
also frequently used in military application. Network operating system offers many capabilities including:
A primary objective of real-time system is to provide quick Allowing users to access the various resources of the network
response times. User convenience and resource utilization are of hosts
secondary concern to real-time system. In the real-time system
8
Controlling access so that only users in the proper authorisation The second approach to process location is to allow users to run
OPERATING SYSTEMS
are allowed to access particular resources. jobs on any machine by first logging in there. In this model,
Making the use of remote resources appear to be identical to processes on different machines cannot communicate or exchange
the use of local resources data, but a simple manual load balancing is possible.
Providing up-to-the minute network documentation on-line. The third approach is a special command that the user types at a
terminal to cause a program to be executed on a specific machine.
As we said earlier, the key issue that distinguishes a network A typical command might be
operating system from a distributed one is how aware the users
are of the fact that multiple machines are being used. This visibility remote vax4 who
occurs in three primary areas; file system, protection and program to run the who program on machine vax4. In M arrangement, the
execution. environment of the new process is the remote machine. In other
words, if that process tries to read or write files from its current
File System: working directory, it will discover that its working directory is on
The important issue in file system is related to how a file is placed the remote machine, and that files that were in the parent processs
(accessed) on one system from another in a network. Mere are directory are no longer present. Similarly, files written in the
two important approaches to this problem. working directory will appear on the remote machine, not the local
Running a special file transfer program one.
Specifying a path name The fourth approach is to provide the CREATE PROCESS
Running a special file transfer program: system call with a parameter specifying where to run the new
When connecting two or more systems together, the first issue process, possibly with a new system call for specifying the default
that must be faced is how to access the rile system available on site. As with the previous method, the environment will generally
some other system. To deal with this issue user runs a special file be the remote machine. In many cases, signals and other forms of
transfer program that copies the needed remote file to the local inter-process communication between processes do not work
machine, where they can then be accessed normally. Sometimes properly among processes on different machines.
remote printing and mail is also handled this way. One of the best Now let us see how file system protection and program execution
known examples of network that primarily support file transfer are supported in distributed operating systems.
and mail via special programs is the UNIXs UUCP (user to user 4. Distributed Operating System
control program) program and its network USENET. A distributed operating system is one that looks to its users like
Path name specification: an ordinary centralized operating system but runs on multiple
The second approach in this direction is that programs from one independent CPUs. The key concept here is transparency. In other
machine can open files on another machine by providing a path words, the use of multiple processors should be invisible to the
name telling where the file is located. user. Another way of expressing the same idea is to say that user
views the system as virtual uniprocessor but not as a collection of
distinct machines. In a true distributed system, users are not aware
of where their programs are being run or where their files are
residing; they should all be handled automatically and efficiently
by the operating system.
Distributed operating systems have many aspects in common
with centralized ones but they also differ in certain ways. Distributed
operating system, for example, often allow programs to run on
several processors at the same time, thus requiring more complex
processor scheduling (scheduling refers to a set of policies and
mechanisms built into the operating systems that controls the
order in which the work to be done is completed) algorithms in
order to achieve maximum utilisation of CPUs time.
A (virtual) subdirectory above the root directory provides Fault-tolerance is another area in which distributed operating
access to remote tiles protection: systems are different. Distributed systems are considered to be
more reliable than uniprocessor based system. They perform even
Execution Location if certain part of the hardware is malfunctioning. This additional
Program execution is the third area in which machine boundaries
feature, supported by distributed operating system has enormous
are visible in network operating systems. When a user or a running
implications for the operating system.
program wants to create a new process, where is the process created?
At least four schemes have been used thus far. The first of these I will tell you the Advantages of Distributed Operating Systems
is that the user simply says CREATE PROCESS in one way or There are three important advantages in the design of distributed
another, and specifies nothing about where. Depending on the operating system:
implementation, this can be the best or worse Way to do it. 1. Major breakthrough in microprocessor technology: Micro-
processors have become very much powerful and cheap,
compared with mainframes and minicomputers, so it has
9
become attractive to think about designing large systems An important difference between network and distributed
OPERATING SYSTEMS
consisting of small processors. These distributed systems clearly operating system is how they are implemented. A common way
have a price/performance advantages over more traditional to realize a networking operating system is to put a layer of software
systems. on top of the native operating system of the individual machines.
2. Incremental Growth: The second advantage is that if there is For example one could write a special library package that could
a need of 10 per cent more computing power, one should just intercept all the system calls and decide whether each one was local
add 10 per cent more processors. System architecture is crucial or remote. Although most system calls can be handled this way
to the type of system growth, however, since it is hard to give without modifying kernel (kernel is that part of operating system
each user of a personal computer another 10 per cent. that manages all resources of computer).
3. Reliability: Reliability and availability can also be a big Historical Development of Operating Systems
advantage; a few parts of the system can be down without 1. Open shop
disturbing people using the other parts; On the minus side, Each user was allocated a block of time to load and run his/her
unless one is very careful, it is easy for the communication program, which was input from punch cards.
protocol overhead to become a major source of inefficiency.
Debugging consisted of inspecting the internal machine states
Now let us see how file system, protection and program and patching them directly.
execution are supported in distributed operating system.
Device drivers (device-specific routines), functions, compilers,
File System: and assemblers had to be explicitly loaded.
Distributed operating system supports a single global file system 2. operator-driven shop
visible from all machines. When this method is used, there is one
The computer operator loaded the jobs and collected output.
directory for executable programs (in UNIX, it is bin directory),
one password file and so on. When a program wants to read the Users debugged programs by inspecting a core dump, which
password file it does something like was a hexadecimal listing of the exact contents of memory.
Open (*/etc/password, READ-ONLY) The operator could batch jobs or rearrange them according to
priority, run time, etc.
without reference to where the file is. It is upto the operating
system to locate the file and arrange for transport of data as they 3. Offline input/output or simple batch system
are needed. A separate computer was used for I/O.
The convenience of having a single global name space is obvious. Several programs were first loaded onto tape, and then the full
In addition, this approach means that operating system is free to tape was read into the main computer.
move files around among machines to keep all the disks generally Program output and dumps were written to tape, and then
full and busy and that the system can maintain replicated copies printed from the tape by the auxiliary computer.
of files if it chooses. When the user or program must specify the
A small resident monitor program reset the main computer
machine name, the system cannot decide on its own to move a file
after each job, interpreted some simple command language,
to a new machine because that would change the (user visible)
performed some simple accounting, and did device-
name used to access the file. Thus in a network operating system,
independent input and output.
control over file placement must be done manually by the users,
whereas in a distributed operating system it can be done 4. Spooling systems = multiprogrammed batch systems
automatically by the system itself. treated separately in text (Sections 1.3.2.2 and 1.4), but were
developed approximately simultaneously
Protection:
In a true distributed system there is a unique UID for every user, Example: IBM OS/360
and that UID should be valid on all machines without any spool: simultaneous peripheral operations on line
mapping. In this way no protection problems arise on remote Disks were used for intermediate storage: faster than tapes and
access to files; a remote access can be treated like a local access with allowed jobs to be processed in any order.
the same UID. There is a difference between network operating
A nucleus (or kernel) contained routines to manage processes (
system and distributed operating system in implementing
jobs) and device interrupts.
protection issue. In networking operating system, there are various
machines, each with its own user to UID mapping but in Used interrupts to perform I/O (device tells computer when it
distributed operating system there is a single system wide mapping is finished a task)
that is valid everywhere. Device drivers included in the nucleus
10
to restart the resident monitor if it failed or was overwritten by WindowsNT, v.4 - 1996
OPERATING SYSTEMS
a program Windows98 - 1998
Could do multiprogramming = multitasking: have more than one Windows 2000 - 2000
process somewhere between starting and finishing
Review Exercise:
5. interactive multiprogramming ( timeshared system)
1. You explain the difference between Contrast Serial Processing,
Examples: CTSS, MULTICS, UNIX Batch Processing and Multiprogramming?
Users interact with the computer directly through a command ________________________________________________________________________
language at a terminal
________________________________________________________________________
A command interpreter defines interface
________________________________________________________________________
A session lasts from logon to logoff
________________________________________________________________________
Text editors allow users to create programs, text files, and data
files online instead of with cards or tape ________________________________________________________________________
User has the illusion that he/she is the only user of the ________________________________________________________________________
computer, but there may actually be many simultaneous users ________________________________________________________________________
recent PC operating systems, such as OS/2 and Windows 95,
are single-user interactive multiprogrammed systems 2. What is Buffering and Spooling?
6. interactive uniprogramming ________________________________________________________________________
One user, one process at a time: personal computers ________________________________________________________________________
Examples: CP/M (Control Program for Microcomputers), ________________________________________________________________________
DOS (derived from Seattle Computing Products SCP-DOS ________________________________________________________________________
clone of CP/M 1981)
________________________________________________________________________
Processes can terminate and stay resident in memory, later to
________________________________________________________________________
be reactivated by interrupts from the keyboard (primitive
multiprogramming) - Large amounts of processing time can ________________________________________________________________________
be devoted to providing a graphical user interface, since only ________________________________________________________________________
one process is active at a time ________________________________________________________________________
7. distributed computing ________________________________________________________________________
Communication between processes on different processors,
e.g., e-mail, ftp, finger
Separate computers share devices (printers)
3. List the main differences between Network operating systems
A user may execute processes on a different machine from the and Distributed operating systems.
one he/she is on
________________________________________________________________________
Allows load sharing: automatic movement of processes to
________________________________________________________________________
other sites
________________________________________________________________________
Increased fault tolerance for data and processes
________________________________________________________________________
Tightly coupled system: processors share a main memory ...
also called parallel system ________________________________________________________________________
Loosely coupled system: processors have their own memory ________________________________________________________________________
and communicate by exchanging messages ... what is usually ________________________________________________________________________
meant by a distributed system ________________________________________________________________________
Release Dates for Recent Operating Systems ________________________________________________________________________
UNIX - 1973 ________________________________________________________________________
DOS 1.0 - 1981 ________________________________________________________________________
MacOS - about 1984 ________________________________________________________________________
MacOS, System 5 - 1986 ________________________________________________________________________
OS/2 1.0 - 1987 Reference Books:
Windows3.0 - 1990 Author Dahmke, Mark.
Windows3.1 - 1991 Main Title Microcomputer Operating Systems / Mark Dahmke.
Windows95 - 1995 Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
WindowsNT - 1993
11
Author Deitel, Harvey M., 1945-
OPERATING SYSTEMS
12
LESSON-3
OPERATING SYSTEMS
Objective: their operating systems, these six tasks define the core of nearly all
Dear students after learning about the different types of operating operating systems. Lets look at the tools the operating system
systems , lets us now discuss the different functions and services uses to perform each of these functions.
of an operating system. Processor Management
Today I will discuss briefly the services and Functions of an The heart of managing the processor comes down to two related
Operating System. They are listed as follows: issues:
Processor management Ensuring that each process and application receives enough of
Memory management the processors time to function properly.
Device management Using as many processor cycles for real work as is possible
Storage management The basic unit of software that the operating system deals with in
Application interface scheduling the work done by the processor is either a process or
a thread, depending on the operating system.
User interface
Its tempting to think of a process as an application, but that gives
With the different types of operating systems in mind, its time to
an incomplete picture of how processes relate to the operating
look at the basic functions provided by an operating system.
system and hardware. The application you see (word processor or
When the power to a computer is turned on, the first program spreadsheet or game) is, indeed, a process, but that application
that runs is usually a set of instructions kept in the computers may cause several other processes to begin, for tasks like
read-only memory (ROM) that examines the system hardware communications with other devices or other computers. There
to make sure everything is functioning properly. This power-on are also numerous processes that run without giving you direct
self test (POST) checks the CPU, memory, and basic input-output evidence that they ever exist. A process, then, is software that
systems (BIOS) for errors and stores the result in a special memory performs some action and can be controlled by a user, by other
location. Once the POST has successfully completed, the software applications or by the operating system.
loaded in ROM (sometimes called firmware) will begin to activate
It is processes, rather than applications, that the operating system
the computers disk drives. In most modern computers, when
controls and schedules for execution by the CPU. In a single-
the computer activates the hard disk drive, it finds the first piece
tasking system, the schedule is straightforward. The operating
of the operating system: the bootstrap loader.
system allows the application to begin running, suspending the
The bootstrap loader is a small program that has a single function: execution only long enough to deal with interrupts and user input.
It loads the operating system into memory and allows it to begin Interrupts are special signals sent by hardware or software to the
operation. In the most basic form, the bootstrap loader sets up CPU. Its as if some part of the computer suddenly raised its
the small driver programs that interface with and control the hand to ask for the CPUs attention in a lively meeting. Sometimes
various hardware subsystems of the computer. It sets up the the operating system will schedule the priority of processes so
divisions of memory that hold the operating system, user that interrupts are masked that is, the operating system will ignore
information and applications. It establishes the data structures the interrupts from some sources so that a particular job can be
that will hold the myriad signals, flags and semaphores that are finished as quickly as possible. There are some interrupts (such as
used to communicate within and between the subsystems and those from error conditions or problems with memory) that are
applications of the computer. Then it turns control of the so important that they cant be ignored. These non-maskable
computer over to the operating system. interrupts (NMIs) must be dealt with immediately, regardless of
The operating systems tasks, in the most general sense, fall into the other tasks at hand.
six categories: While interrupts add some complication to the execution of
Processor management processes in a single-tasking system, the job of the operating
Memory management system becomes much more complicated in a multi-tasking system.
Now, the operating system must arrange the execution of
Device management
applications so that you believe that there are several things
Storage management happening at once. This is complicated because the CPU can only
Application interface do one thing at a time. In order to give the appearance of lots of
User interface things happening at the same time, the operating system has to
switch between different processes thousands of times a second.
While there are some who argue that an operating system should
Heres how it happens.
do more than these six tasks, and some operating-system vendors
do build many more utility programs and auxiliary functions into
13
A process occupies a certain amount of RAM. It also makes must divide the workload among the CPUs, trying to balance the
OPERATING SYSTEMS
use of registers, stacks and queues within the CPU and operating demands of the required processes with the available cycles on the
system memory space. different CPUs.
When two processes are multi-tasking, the operating system Asymmetric operating systems use one CPU for their own needs
allots a certain number of CPU execution cycles to one program. and divide application processes among the remaining CPUs.
After that number of cycles, the operating system makes copies Symmetric operating systems divide themselves among the
of all the registers, stacks and queues used by the processes, various CPUs, balancing demand versus CPU availability even
and notes the point at which the process paused in its execution. when the operating system itself is all thats running.
It then loads all the registers; stacks and queues used by the Even if the operating system is the only software with execution
second process and allow it a certain number of CPU cycles. needs, the CPU is not the only resource to be scheduled. Memory
management is the next crucial step in making sure that all
When those are complete, it makes copies of all the registers,
processes run smoothly.
stacks and queues used by the second program, and loads the
first program. Memory and Storage Management
All of the information needed to keep track of a process when When an operating system manages the computers memory, there
switching is kept in a data package called a process control block. are two broad tasks to be accomplished:
The process control block typically contains: Each process must have enough memory in which to execute,
An ID number that identifies the process and it can neither run into the memory space of another process
nor be run into by another process.
Pointers to the locations in the program and its data where
processing last occurred The different types of memory in the system must be used
properly so that each process can run most effectively.
Register contents
The first task requires the operating system to set up memory
States of various flags and switches
boundaries for types of software and for individual applications.
Pointers to the upper and lower bounds of the memory
As an example, lets look at an imaginary system with 1 megabyte
required for the process
(1,000 kilobytes) of RAM. During the boot process, the operating
A list of files opened by the process system of our imaginary computer is designed to go to the top of
The priority of the process available memory and then back up far enough to meet the
The status of all I/O devices needed by the process needs of the operating system itself. Lets say that the operating
system needs 300 kilobytes to run. Now, the operating system
When the status of the process changes, from pending to active,
goes to the bottom of the pool of RAM and starts building up
for example, or from suspended to running, the information in
with the various driver software required to control the hardware
the process control block must be used like the data in any other
subsystems of the computer. In our imaginary computer, the
program to direct execution of the task-switching portion of the
drivers take up 200 kilobytes. So after getting the operating system
operating system.
completely loaded, there are 500 kilobytes remaining for application
This process swapping happens without direct user interference, processes.
and each process gets enough CPU cycles to accomplish its task in
When applications begin to be loaded into memory, they are loaded
a reasonable amount of time. Trouble can come, though, if the
in block sizes determined by the operating system. If the block
user tries to have too many processes functioning at the same
size is 2 kilobytes, then every process that is loaded will be given a
time. The operating system itself requires some CPU cycles to
chunk of memory that is a multiple of 2 kilobytes in size.
perform the saving and swapping of all the registers, queues and
Applications will be loaded in these fixed block sizes, with the
stacks of the application processes.
blocks starting and ending on boundaries established by words
If enough processes are started, and if the operating system hasnt of 4 or 8 bytes.
been carefully designed, the system can begin to use the vast majority
These blocks and boundaries help to ensure that applications
of its available CPU cycles to swap between processes rather than
wont be loaded on top of one anothers space by a poorly calculated
run processes. When this happens, its called thrashing, and it
bit or two. With that ensured, the larger question is what to do
usually requires some sort of direct user intervention to stop
when the 500-kilobyte application space is filled.
processes and bring order back to the system.
In most computers, its possible to add memory beyond the
One way that operating-system designers reduce the chance of
original capacity. For example, you might expand RAM from 1 to
thrashing is by reducing the need for new processes to perform
2 megabytes. This works fine, but tends to be relatively expensive.
various tasks. Some operating systems allow for a process-lite,
It also ignores a fundamental fact of computing - most of the
called a thread, that can deal with all the CPU-intensive work of a
information that an application stores in memory is not being
normal process, but generally does not deal with the various types
used at any given moment. A processor can only access memory
of I/O and does not establish structures requiring the extensive
one location at a time, so the vast majority of RAM is unused at
process control block of a regular process. A process may start
any moment. Since disk space is cheap compared to RAM, then
many threads or other processes, but a thread cannot start a process.
moving information in RAM to hard disk can greatly expand
So far, all the scheduling weve discussed has concerned a single
CPU. In a system with two or more CPUs, the operating system
14
RAM space at no cost. This technique is called virtual memory is suspended. Then, when the process needing input is made
OPERATING SYSTEMS
management. active once again, the operating system will command the buffer
Disk storage is only one of the memory types that must be managed to send data.
by the operating system, and is the slowest. Ranked in order of This process allows a keyboard or a modem to deal with external
speed, the types of memory in a computer system are: users or computers at a high speed even though there are times
High-speed cache - This is fast, a relatively small amount of when the CPU cant use input from those sources.
memory that are available to the CPU through the fastest Managing all the resources of the computer system is a large part
connections. Cache controllers predict which pieces of data the of the operating systems function and, in the case of real-time
CPU will need next and pull it from main memory into high- operating systems, may be virtually all the functionality required.
speed cache to speed up system performance. For other operating systems, though, providing a relatively simple,
Main memory - This is the RAM that you see measured in consistent way for applications and humans to use the power of
megabytes when you buy a computer. the hardware is a crucial part of their reason for existing.
Secondary memory- This is most often some sort of rotating Interface to the World
magnetic storage that keeps applications and data available to Application Interface
be used, and serves as virtual RAM under the control of the Application program interfaces (APIs) let application
operating system. programmers use functions of the computer and operating system
The operating system must balance the needs of the various without having to directly keep track of all the details in the CPUs
processes with the availability of the different types of memory, operation. Lets look at the example of creating a hard disk file for
moving data in blocks (called pages) between available memory as holding data to see why this can be important.
the schedule of processes dictates.
A programmer writing an application to record data from a scientific
Device Management instrument might want to allow the scientist to specify the name
The path between the operating system and virtually all hardware of the file created. The operating system might provide an API
not on the computers motherboard goes through a special function named MakeFile for creating files. When writing the
program called a driver. Much of a drivers function is to be the program, the programmer would insert a line that looks like this:
translator between the electrical signals of the hardware subsystems MakeFile [1, %Name, 2]
and the high-level programming languages of the operating system
In this example, the instruction tells the operating system to create
and application programs. Drivers take data that the operating
a file that will allow random access to its data (1), will have a name
system has defined as a file and translate them into streams of
typed in by the user (%Name), and will be a size that varies
bits placed in specific locations on storage devices, or a series of
depending on how much data is stored in the file (2). Now, lets
laser pulses in a printer.
look at what the operating system does to turn the instruction
Because there are such wide differences in the hardware controlled into action.
through drivers, there are differences in the way that the driver
1. The operating system sends a query to the disk drive to get the
programs function, but most are run when the device is required,
location of the first available free storage location.
and function much the same as any other process. The operating
system will frequently assign high-priority blocks to drivers so 2. With that information, the operating system creates an entry in
that the hardware resource can be released and readied for further the file system showing the beginning and ending locations of
use as quickly as possible. the file, the name of the file, the file type, whether the file has
been archived, which users have permission to look at or modify
One reason that drivers are separate from the operating system is
the file, and the date and time of the files creation.
so that new functions can be added to the driver and thus to the
hardware subsystems - without requiring the operating system 3. The operating system writes information at the beginning of
itself to be modified, recompiled and redistributed. the file that identifies the file, sets up the type of access possible
and includes other information that ties the file to the
Through the development of new hardware device drivers,
application.
development often performed or paid for by the manufacturer of
the subsystems rather than the publisher of the operating system, In all of this information, the queries to the disk drive and
input/output capabilities of the overall system can be greatly addresses of the beginning and ending point of the file are in
enhanced. formats heavily dependent on the manufacturer and model of
the disk drive.
Managing input and output is largely a matter of managing queues
and buffers, special storage facilities that take a stream of bits Because the programmer has written her program to use the API
from a device, perhaps a keyboard or a serial port, hold those bits, for disk storage, she doesnt have to keep up with the instruction
and release them to the CPU at a rate slow enough for the CPU to codes, data types, and response codes for every possible hard disk
cope with. and tape drive.
This function is especially important when a number of processes The operating system, connected to drivers for the various hardware
are running and taking up processor time. The operating system subsystems, deals with the changing details of the hardware - the
will instruct a buffer to continue taking input from the device, but programmer must simply write code for the API and trust the
to stop sending data to the CPU while the process using the input operating system to do the rest.
15
APIs have become one of the most hotly contested areas of the secondary-storage management
OPERATING SYSTEMS
16
________________________________________________________________________
OPERATING SYSTEMS
Notes
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
Reference Books:
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
Author Deitel, Harvey M., 1945-
Main TitleAn Introduction To Operating Systems / Harvey M.
Deitel.
Edition Rev. 1st Ed.
PublisherReading, Mass : Addison-Wesley Pub. Co., C1984.
Author Lister, A. (Andrew), 1945-
Main Title Fundamentals Of Operating Systems / A.M. Lister.
Edition 3rd Ed.
Publisher London : Macmillan, 1984.
Author Gray, N. A. B. (Neil A. B.)
Main Title Introduction To Computer Systems / N.A.B. Gray.
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
1987.
Author Peterson, James L.
Main TitleOperating System Concepts / James L. Peterson,
Abraham Silberschatz.
Edition 2nd Ed.
Publisher Reading, Mass. : Addison-Wesley, 1985.
Author Stallings, William.
Main Title Operating Systems / William Stallings.
Edition 6th Ed.
Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
Author Tanenbaum, Andrew S., 1944-
Main Title Operating Systems : Design And Implementation /
Andrew S. Tanenbaum, Albert S. Woodhull.
Edition 2nd Ed.
Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
Author Nutt, Gary J.
Main Title Operating Systems : A Modern Perspective /
Gary J. Nutt.
Publisher Reading, Mass. : Addison-Wesley, C1997.
Author Silberschatz, Abraham.
Main Title Operating System Concepts / Abraham Silberschatz,
Peter Baer Galvin.
Edition 6th Ed.
Publisher Reading, Mass. : Addison Wesley Longman, C1998.
17
LESSON 4:
Objective:
Today I will describe you the Operating Systems Structure When a user program executes an I/O operation, it executes a
system call that is traped to the I/O Layer, which in turn calls
Since you all know operating system is a very large and complex
the memory management layer, which in turn calls the CPU-
software, it must be engineered carefully, if it is to be functioned
scheduling layer, which is then passed to the hardware. At each
properly and to be modified easily. It should be developed as a
layer , the parameters may be modified, data may need to be
collection of several smaller modules with carefully defined inputs,
passed, and so on. Each layer adds overhead to the system call,
outputs and functions rather than a single piece of software.
thus system call takes longer time when compared to a non-
Let us now examine different types of operating systems. layered system.
1. Simple Structure: OS/2 Operating System Layer
This type of structures is not well defined .Such type of operating OS/2 is the descendant of MS-DOS adds additional features such
system are as : as multitasking and dual-mode operation and other addition
Small features. In OS/2 fewer layers with more functionality are designed,
Simple. providing most of the advantages of modularized code while
Limited systems. avoiding the difficult problems of layer definition and interaction.
The advantage in this type of operating system is ,direct access to
Grew beyond their scope.
low-level facilities is not allowed, providing the operating system
Example 1: with more control over the hardware and more knowledge of
MS-DOS was written to provide the most functionality in the which resources each user program is using.
least space. 3. Kernel approach: The kernel is the heart of the operating system.
not divided into modules It is the part of operating system which directly makes interface
Although MS-DOS has some structure, its interfaces and levels with hardware system. When the system is booted, the kernel
is read into the memory. It stays in memory while the system is
of functionality are not well separated.
running .Its main functions are:
MS-DOS Layer Structure To provide a mechanism for creation and deletion of processes.
2. Layered Approach:The operating system architecture based To provide process scheduling, memory management and I/
on layered approach is divided into a number of layers (levels), O management.
each built on top of lower layers. The bottom layer (layer 0), is
To provide mechanism for synchronization of process so that
the hardware; the highest (layer N) is the user interface. Higher
processes synchronize their actions.
level layers uses the functions (operations) and services of
only lower-level layers. To provide mechanism for interprocess communication.
An Operating System Layer The UNIX operating system is based on kernel approach .It
consists of two parts:
Example of Windows 2000.
Advantages: Kernel
System Program:Programs and commands call on the kernels
As the system is divided into layers/modules verification and
services. The kernel, in turn, consults its data tables as it
debugging of the system is easy/simple.
schedules users programs, allocates resources to the program,
Easy to find and rectify the errors ,as we can find in which layer and manages the low-level exchange of data with the computers
the error has occurred. hardware.
A layer need now the operations implemented by the lower For example, when a program requests file services, the program
layer, thus hides the existence of certain data structures, gives the kernel a system call. The kernel oversees the accessing of
operations and hardware. the disk drive where the file resides. The kernel gets the data and
Let us discuss the Difficulties for designing layered approach: transfers it to the buffer. The data is then picked up by the parts of
The layered approach involves careful definition of the layers, the kernel can be configured to accommodate variations in hardware
since the higher level layer uses the services of the lower level .The kernel contains a changeable set of device drivers to
layer. accommodate numerous devices.
For Example, the device driver for the secondary memory must
be a lower level than memory management routines since memory
management requires the ability to use the backing store.
18
Making a system call. In virtual multiprogramming system, a single real machine gives
OPERATING SYSTEMS
An illustration of UNIX kernel built on the systems hardware an illusion of several virtual machines, each having its own virtual
core. processor, storage and I/O devices possibly with much larger
With in the kernel, individual segments of programs or routines, capacity. Process scheduling can be used to share the CPU and
carry out the kernels work. The routines allocate memory resources, make it appear that users have their own processors. Virtual
schedule CPU time, and manage access to system resources. memory organization technique can create illusion of very large
memory for program execution.
The kernel also monitors the system for error conditions and
hardware problems. At higher level, the routines provide programs Lets us now cover the advantages and disadvantages of Virtual
with entry points to kernel services. All UNIX programs use the Machines
kernels system call. Advantages :
4. Virtual Machine: A virtual machine takes the layered approach The virtual-machine concept provides complete protection of
to its logical conclusion. It treats hardware and the operating system resources since each virtual machine is isolated from all
system kernel as though they were all hardware. A virtual other virtual machines.
machine provides an interface identical to the underlying bare A virtual-machine system is a perfect vehicle for operating-
hardware. The operating system creates the illusion of multiple systems research and development. System development is
processes, each executing on its own processor with its own done on the virtual machine, instead of on a physical machine
(virtual) memory. and so does not disrupt normal system operation.
The resources of the physical computer are shared to create the The higher degree of separation between independent virtual
virtual machines. machine aids in ensuring aids privacy and security.
CPU scheduling can create the appearance that users have their
Disadvantages
own processor.
permits no direct sharing of resources.
Spooling and a file system can provide virtual card readers and
The virtual machine concept is difficult to implement due to
virtual line printers.
the effort required to provide an exact duplicate to the underlying
A normal user time-sharing terminal serves as the virtual machine.
machine operators console.
5. Client-Server Model: A trend in the modern operating system
Protection is excellent, but no sharing possible. is to take moving code up into the higher layers even further,
Virtual privileged instructions are trapped. and remove as much as possible from the operating system,
Useful for running different OS simultaneously on the same leaving a minimal kernel. The usual approach is to implement
machine. most of the operating system functions in user processes. To
request a service, such as reading a block of a file, a user process
Virtual System Models
(now known as client process) sends the request to a server
From the users point of view, virtual machine can be made to
process, which then does the work and sends back the answer.
appear to very similar to existing real machine or they can be entirely
different. An important aspect of this technique is that each user In this model, the kernel does all the communication between
can run operating system of his own choice. the clients and servers by splitting the operating system into
parts, each of which only handles:
To understand this concept, let us try to understand the difference
File service
between conventional multiprogramming system and virtual
machine multiprogramming. In conventional multiprogramming Process service
processes are allocated a portion of the real machines resources. Terminal service
The same machine resources are distributed among several Memory service.
processes.
This way, each part becomes small and manageable. Furthermore,
because all the servers run as user-mode processes, and not in
kernel mode, they do not have direct access to the hardware. As a
consequence, if a bug in the file server is triggered, the file service
may crash, but this will not usually bring the whole system down.
19
The Client-Server Model ________________________________________________________________________
OPERATING SYSTEMS
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
4. Explain the following with an example?
Layered Approach.
________________________________________________________________________
Advantages :
________________________________________________________________________
It is adaptable in distributed systems. If a client communicates
with a server by sending it messages, the client need not know ________________________________________________________________________
whether the message is handled locally in its own machine, or Kernel Approach.
whether it was sent across a network to a server on a remote ________________________________________________________________________
machine. As far as the client is concerned, the same thing happens
________________________________________________________________________
in both cases, request was sent and a reply came back.
________________________________________________________________________
Message from Client to Server
Reference Books:
Machine 1 Machine 2 Machine 3 Machine 4
Author Dahmke, Mark.
The picture painted above of a kernel that handles only the
transport of messages from clients to servers and back is not Main Title Microcomputer Operating Systems / Mark Dahmke.
completely realistic. Some operating system functions (such as Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
loading commands into the physical I/O device registers) are Author Deitel, Harvey M., 1945-
difficult, if not impossible, to do from user-space programs. Here Main Title An Introduction To Operating Systems / Harvey M.
are two ways of dealing with this problem. Deitel.
Is to have some critical server processes (eg:- I/O device drivers) Edition Rev. 1st Ed.
actually run in kernel mode, with complete access to all the
hardware, but still communicate with other processes using Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
the normal message mechanism. Author Lister, A. (Andrew), 1945-
Is to build a minimal amount of mechanism into the kernel, but Main Title Fundamentals Of Operating Systems / A.M. Lister.
leave the policy decisions up to servers in user space. For example, Edition 3rd Ed.
the kernel might recognize that a message sent to a certain special Publisher London : Macmillan, 1984.
address means to take the contents of that message and load in
into the I/O device registers for some disk, to start a disk read. In Author Gray, N. A. B. (Neil A. B.)
this example, the kernel would not even inspect the bytes in the Main Title Introduction To Computer Systems / N.A.B. Gray.
message to see if they were valid or meaningful; it would just Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
blindly copy them into the disks device registers. (Obviously some 1987.
scheme for limiting such message to authorized processes only Author Peterson, James L.
must be used). The split between mechanism and policy is an
important concept; it occurs again and again in operating Main Title Operating System Concepts / James L. Peterson,
Abraham Silberschatz.
Systems in various contexts.
Edition 2nd Ed.
Exercise:
Publisher Reading, Mass. : Addison-Wesley, 1985.
1. Contrast Multiprogramming with Client-Server Model?
Author Stallings, William.
________________________________________________________________________
Main Title Operating Systems / William Stallings.
________________________________________________________________________
Edition 6th Ed.
________________________________________________________________________
Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
________________________________________________________________________
Author Tanenbaum, Andrew S., 1944-
Main Title Operating Systems : Design And Implementation /
2. Explain the difficulties in designing a layered approach? Andrew S. Tanenbaum, Albert S. Woodhull.
________________________________________________________________________ Edition 2nd Ed.
________________________________________________________________________ Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
________________________________________________________________________ Author Nutt, Gary J.
________________________________________________________________________ Main Title Operating Systems : A Modern Perspective / Gary J.
3. Write the advantages and disadvantages of Virtual Machine? Nutt.
________________________________________________________________________
20
Publisher Reading, Mass. : Addison-Wesley, C1997. Notes
OPERATING SYSTEMS
Author Silberschatz, Abraham.
Main Title Operating System Concepts / Abraham Silberschatz,
Peter Baer Galvin.
Edition 6th Ed.
Publisher Reading, Mass. : Addison Wesley Longman, C1998.
System Services
Windows
MGR
& GDI
Windows 2000 Kernel
Hardware Abstraction Layer (HAL)
IO
Manager
Graphics
Device
Drivers
VM
Manager
Security
Reference
Monitor
Process
Manager
User Program
(Requests Services)
UNIX System Kernel
(Provides Services)
Call
Request Service
Type
Details
Data
Return
Service complete
Status
Data
Job N
Job 2
Virtual Machine
Operating System
Virtual
Machine 1
Virtual
Machine N
Virtual
Machine 2
21
LESSON-5
Objectives:
OPERATING SYSTEMS
22
appears as a small angled arrow. Text -processing applications, Its protection against access or destination file can not create
OPERATING SYSTEMS
however, use an I-beam pointer that is shaped like a capital I. because there is already a file with this name.
Pointing Device:A device, such as a mouse or trackball, that Read the source file
enables you to select objects on the display screen. Write into the destination file.
Icons:Small pictures that represent commands, files, or Display status information regarding various read/write error
windows. By moving the pointer to the icon and pressing a conditions
mouse button, you can execute a command or convert the icon
Close both files after the entire file is copied
into a window. You can also move the icons around the display
screen as if they were real objects on your desk. For example:
Desktop: The area on the display screen where icons are grouped Program may find that the end of file has been reached or there
is often referred to as the desktop because the icons are intended was a hardware failure. The write operation may encounter various
to represent real objects on a real desktop. errors, depending upon the output device (no disk space, printer
out of paper etc.)
Windows: You can divide the screen into different areas. In
each window, you can run a different program or display a From the above observation we can say that a user program takes
different file. You can move windows around the display heavy use of the operating system. All interactions between the
screen, and change their shape and size at will. program and its environment must occur as a result of request
from that program to the operating system.
Menus: Most graphical user interfaces let you execute commands
by selecting a choice from a menu. Let see the three general methods are used to pass parameters
between a running program and the operating system.
CLIs often can double as scripting languages (see shell script)
and can perform operations in a batch processing mode without Pass parameters in registers.
user interaction. That means that once an operation is analyzed Store the parameters in a table in memory, and the table address
and understood, a script implementing that understanding is passed as a parameter in a register.
can be written and saved. The operation can thereafter be carried Push (store) the parameters onto the stack by the program, and
out with no further analysis and design effort. With GUIs, pop off the stack by operating system.
users must start over at the beginning every time, as GUI
Now I will explain you the Working of System call.
scripting (if available at all) is almost always more limited.
Simple commands do not even need an actual script, as the Obtain access to system space
completed command can usually be assigned a name (an alias) Do parameter validation
and executed simply by typing <operating system> A means of System resource collection ( locks on structures )
communication between a program and its user, based solely Ask device/system for requested item
on textual input and output. Commands are input with the
Suspend waiting for device
help of a keyboard or similar device and are interpreted and
executed by the program. Results are output as text or graphics Interrupt makes this thread ready to run
to the terminal. Wrap-up
Command line interfaces usually provide greater flexibility than Return to user
graphical user interfaces, at the cost of being harder for the There are 11 (or more) steps in making the system call read (fd,
novice to use. Consequently, some hackers look down on GUIs buffer, nbytes)
as designed.
Two ways of passing data between programs.
System Call:
Message Passing
System call provides the interface to running program and the
Shared Memory
operating system.User program receives operating system services
through the set of system calls. Examples of various system calls.
Generally available as assembly-language instructions. Review Exercise:
Languages defined to replace assembly language for systems 1. Compare the advantages and disadvantages of Command line
programming allow system calls to be made directly (e.g., C, Interface and Graphical user Interface?
C++) ______________________________________________________________________
An example of system call, let us consider a simple program to ______________________________________________________________________
copy data form one file to another. In an interactive system the ______________________________________________________________________
following system calls are generated by the operating system.
______________________________________________________________________
Prompt messages for inputting two file names and reading it
from terminal.
2. What is system call? How does it work?
Open source and destination files.
______________________________________________________________________
Prompt error messages in case the source file can not opened
because of ______________________________________________________________________
23
______________________________________________________________________ Edition 6th Ed.
OPERATING SYSTEMS
24
SELF-ASSESSMENT INTERACTIVE TOPIC 1
OPERATING SYSTEMS
1.1 True/False: An operating system can be viewed as resource deal with the cause of the interrupt; control is then returned to
allocator to control various I/O devices and user programs. the interrupted context and instruction. An interrupt can be
used to signal the completion of an I/O to obviate the need
Answer: True
for device polling.
1.2 True/False: automatic job sequencing means the System
Answer: True
does not proceeds from one job to the next without human
intervention. 2.2 True/False A trap is a software-generated interrupt. A trap
can be used to call operating system routines or to catch
Answer: False
arithmetic errors.
1.3 Which of the following lists the different parts of the monitor.
Answer: True
a. Control card interpreter.
2.3 True / False How is an interrupt executed? The I/O driver
b. Control card interpreter, device drivers, and loader. sends a signal through a special interrupt line to the CPU when
c. Loader. it has finished with an I/O request.
d. None of the above Answer: True
Answer: B 2.4 True / False An interrupt vector is a list giving the starting
1.4 In what ways are batch systems inconvenient for users?. addresses of each interrupt service routine.
Answer: Answer: True
a. Users cant interact with their jobs to fix problems. 2.5 True/ False Systems treat slow and fast devices differently, for
b. Turnaround time is too long. slow devices, each character transferred causes an interrupt. For
fast devices, each block of characters transferred causes an
c. B only
interrupt.
d. A and B
Answer: True
e. A only
2.6 True/False The Introduction of base and limit registers that
1.5 What were the advantages of off-line operations? hold the smallest legal physical memory address, and the size
a. Main computer no longer constrained by speed of card reader. of the range, respectively can prevent users from accessing other
b. Application programs used logical I/O devices instead of users programs and data. As a users job is started, the operating
physical I/O devices; programs didnt have to be rewritten system loads these registers; if the program goes beyond these
when new I/O devices replaced old ones. addresses, it is aborted. If another job starts up, these registers
are reset for the new job.
c. Both of the above
Answer: True
d. None of the above
Answer: c 2.7 True/False How can the operating system detect an infinite
1.6 True/False; In a master/slave processor system, the loop in a program? A timer (hardware) is added to system.
master computer controls the actions of various slave Each user is allowed some predetermined time of execution
computers. (not all users are given same amount). If user exceeds these
Answer: true time limits, the program is aborted via an interrupt.
1.7 True/false Answer: True
MULTICS was a time-sharing system created on a large 2.8 True/False: The operating system determines what mode it is
mainframe GE computer (since then taken over by Honeywell), in by using one bit (the monitor/user-mode bit) that gives
by GE, by Bell Labs, and by faculty at MIT. It was very flexible, the present state.
and oriented toward programmers. UNIX was inspired by Answer: True
MULTICS; but it was designed by Ritchie and Thompson in 2.9 The following is a list of operations, followed by a description
1974 at Bell Labs for use on minicomputers. It was designed why each can be considered illegal.
for program development, using a device-independent file
a. Programming errors, such as illegal instruction, addressing fault.
system.
c. Halting the computer.
Answer: True
d. Masking the interrupt so that none can occur. Turning on
Self-Assessment Interactive Topic 2 interrupts; or else job will interfere with I/O.
2.1 True/False An interrupt is a hardware-generated change-of- e. Changing mode from user to system; or else user can control
flow within the system. An interrupt handler is summoned to system.
25
f. Using memory outside user area; invasion of privacy. only specify the device and the operation to perform on it,
OPERATING SYSTEMS
g. Modifying interrupt vectors in monitor; could crash system. while the system converts that request into device or controller
specific commands. User-level programs cannot be trusted to
h. Accessing monitor memory; invasion of privacy.
only access devices they should have access to, and to only access
Which of the following sets of operations the monitor considers them when they are otherwise unused.
illegal
File-system manipulation. There are many details in file
a. none of the above creation, deletion, allocation, and naming that users should
b. all of the above not have to perform. Blocks of disk space are used by files and
c. only b must be tracked. Deleting a file requires removing the name file
information and freeing the allocated blocks. Protections must
Answer: b
also be checked to assure proper file access. User programs
Cache Memory (bonus Discussion) could ensure neither adherence to protection methods nor could
When are caches useful? they be trusted to allocate only free blocks and deallocate blocks
on file deletion.
Answer: Caches are useful when two or more components need
to exchange data, and the components perform transfers at differing Communications. Message passing between systems requires
speeds. messages be turned into packets of information, sent to the
network controller, transmitted across a communications
What problems do they solve? medium, and reassembled by the destination system. Packet
Answer: Caches solve the transfer problem by providing a buffer ordering and data correction must take place. Again, user
of intermediate speed between the components. If the fast device programs might not coordinate access to the network device,
finds the data it needs in the cache, it need not wait for the slower or they may receive packets destined for other processes.
device.
Error Detection.
What problems do they cause? Error detection occurs at both the hardware and software levels.
Answer: The data in the cache must be kept consistent with the At the hardware level, all data transfers must be inspected to ensure
data in the components. If a component has a data value change, that data have not been corrupted in transit. All data on media
and the datum is also in the cache, the cache must also be updated. must be checked to be sure they have not changed since they were
This is especially a problem on multiprocessor systems where written to the media. At the software level, media must be checked
more than one process may be accessing a datum. for data consistency; for instance, do the number of allocated and
If a cache can be made as large as the device for which it is caching unallocated
(for instance, a cache as large as a disk), why not make it that large blocks of storage match the total number on the device. There,
and eliminate the device? errors are frequently process-independent (for instance, the
Answer: A component may be eliminated by an equal-sized cache, corruption of data on a disk), so there must be a global program
but only if: a) the cache and the component have equivalent state- (the operating system) that handles all types of errors. Also, by
saving capacity (that is, if the component retains its data when having errors processed by the operating system, processes need
electricity is removed, the cache must retain data as well), and b) not contain code to catch and correct all the errors possible on a
the cache is affordable, because faster storage tends to be more system.
expensive.
Self assessment interactive Topic 3 3.3 What is the main advantage of the layered approach to system
design?
3.1What is the purpose of the command interpreter? Why is it
usually separate from the kernel? Answer: As in all cases of modular design, designing an operating
system in a modular way has several advantages. The system is
Answer: It reads commands from the user or from a file of
easier to debug and modify because changes affect only limited
commands and executes them, usually by turning them into one
sections of the system rather than touching all sections of the
or more system calls. It is usually not part of the kernel since the
operating system. Information is kept only where it is needed
command interpreter is subject to changes.
and is accessible only within a defined and restricted area, so any
3.2 List five services provided by an operating system. Explain bugs affecting that data must be limited to a specific module or
how each provides convenience to the users. Explain also in which
layer.
cases it would be impossible for user-level programs to provide
these services. 3.4 What is the main advantage for an operating-system designer
of using a virtual-machine architecture? What is the main
Answer:
advantage for a user?
Program execution. The operating system loads the contents
Answer: The system is easy to debug, and security problems are
(or sections) of a file into memory and begins its execution. A
easy to solve. Virtual machines also provide a good platform
user-level program could not be trusted to properly allocate
for operating system research since many different operating
CPU time.
systems may run on one physical system.
I/O operations. Disks, tapes, serial lines, and other devices
must be communicated with at a very low level. The user need
26
3.5 List system service functions provided for the convenience of Answer:
OPERATING SYSTEMS
the programmer. Tell what each does. A method of time sharing must be implemented to allow each
Answer:Program execution loads and executes programs, allows of several processes to have access to the system. This method
debugging I/O operations does all read and write operations involves the preemption of processes that do not voluntarily
File system management allows you to create, delete, open give up the CPU (by using a system call, for instance) and the
files, etc. Communications allows processes to communicate kernel being reentrant (so more than one process may be
with each other Error detection CPU, hardware, instructions, executing kernel code concurrently).
device errors Processes and system resources must have protections and must
3.6 List system service functions provided for efficient operation be protected from each other. Any given process must be limited
of the system. in the amount of memory it can use and the operations it can
Answer: perform on devices like disks.
Resource allocation Care must be taken in the kernel to prevent deadlocks between
processes, so processes arent waiting for each others allocated
Accounting
resources.
Protection
4.2 Describe the differences among short-term, medium-term,
3.7 List five or more functions to control processes and jobs. and long-term scheduling.
Answer: Answer:
Set error level Short-term (CPU scheduler) - selects from jobs in memory,
Load/link/execute program hose jobs which are ready to execute, and allocates the CPU to
Create new process them.
Get/set process attributes Medium-term - used especially with time-sharing systems as
an intermediate scheduling level. A swapping scheme is
Terminate process
implemented to remove partially run programs from memory
Wait for specific event or time and reinstate them later to continue where they left off.
Dump memory Long-term (job scheduler) - determines which jobs are brought
Trace instructions into memory for processing.
Create time profile The primary difference is in the frequency of their execution. The
3.8 List eight or more functions for file manipulation. short-term must select a new process quite often. Long-term is
Answer: Create, delete, open, close, read, write, and reposition used much less often since it handles placing jobs in the system,
files, get/set file attributes and may wait a while for a job to finish before it admits another
one.
3.9 List categories of systems programs.
4.3 True/False: The long-term scheduler selects a group of I/O-
Answer: bound jobs or a group of CPU-bound programs for subsequent
File manipulation activity.
Get status information Answer: False. It selects a mix of jobs for efficient machine
Modify files utilization.
Programming language support 4.4 True / False Time sharing is many users interactively using a
Program loading/execution system simultaneously; each user gets a share of CPU-time,
after other users have gotten their share. It uses medium-term
Communications
scheduling, such as round-robin for the foreground.
Application programs. Background can use a different scheduling technique.
3.10 What is a command interpreter? By what other names is it Answer: True
known? 4.5 True/False Swapping is the process of copying a process out
Answer: Program that interprets the commands you type in at of memory onto a fast disk or drum, to allow space for other
terminal, or enter through a batch file; gets and executes next active processes; it will be copied back into memory when space
user-specified command. Names: control card interpreter, is ample.
command line interpreter, console command processor, shell. Answer: True
Self assessment interactive topic 4 4.6 True/False context switching is the time needed to switch
4.1 Several popular microcomputer operating systems provide little from one job to another
or no means of concurrent processing. Discuss the major Answer: True
complications that concurrent processing adds to an operating
4.7 What two advantages do threads have over multiple processes?
system.
What major disadvantage do they have? Suggest one application
that would benefit from the use of threads, and one
27
that would not.
OPERATING SYSTEMS
28
LESSON -6 SELF-ASSESSMENT
OPERATING SYSTEMS
Self assessment interactive Topic 5 Answer: True.
5.1 What is a CPU burst? An I/O burst? 5.14 What is the time quantum used for?
Answer: Answer: Round-robin scheduling, to give each process the same
processing time.
CPU burst: a time interval when a process uses CPU only.
5.15 How should the time quantum be related to the context
I/O burst: a time interval when a process uses I/O devices
switch time?
only.
Answer: Quantum should be very large compared to context
5.2 An I/O-bound program would typically have what kind of
switch time.
CPU burst?
5.16 Describe the foreground-background approach.
Answer: Short.
5.3 What does preemptive mean? Answer: Low priority processes run in background; high priority
jobs run in foreground; background runs only when
Answer: Cause one process to temporarily halt, in order to run foreground is empty, or waiting for I/O.
another.
5.17 How can multilevel queues be scheduled? Which might have
5.4 What is the dispatcher? priority over others?
Answer: Determines which processes are swapped out. Answer:
5.5 What is throughput? a. Each queue can have absolute priority over lower queues.
Answer: Number of jobs done per time period. b. Time-slice queues can, giving each queue a certain percent of
5.6 List performance criteria we could select to optimize our system. time.
Answer: CPU use, throughput, turnaround time, waiting time, 5.18 What are multilevel feedback queues?
response time. Answer: Processes move from one queue to another, depending
5.7 What is a Gantt chart? Explain how it is used. on changes in its conditions (that is, the CPU burst may change).
Answer: A rectangle marked off horizontally in time units, marked 5.19 What are the advantages and disadvantages of using
off at end of each job or job-segment. It shows the distribution implementation to compare various scheduling algorithms?
of time-bursts in time. It is used to determine total and average Answer:
statistics on jobs processed, by formulating various scheduling
Advantages: completely accurate.
algorithms on it.
Disadvantages: cost in coding, cost in modifying operating
5.8 What are the advantages of SJF? Disadvantages?
system, cost in modifying data structures, bad reactions from
Answer: Provably optimum in waiting time. But no way to know users due to changing and comparing various scheduling
length of next CPU burst. schemes.
5.9 What is indefinite blocking? How can it occur? 5.20 List two ways several computers can work together on sharing
Answer: Also called starvation. A process with low priority that load.
never gets a chance to execute. Can occur if CPU is continually Answer:
busy with higher priority jobs.
One computer controls others.
5.10 What is aging?
Each computer acts independently..
Answer: Gradual increase of priority with age of job, to prevent
starvation. 5.21 Consider the following set of processes, with the length of
the CPU-burst time given in milliseconds:
5.11 What is SRTF (Shortest-Remaining-Time-First) scheduling?
Process Burst Time Priority
Answer: A preemptive scheduling algorithm that gives high
priority to a job with least amount of CPU burst left to P1 10 3
complete. P2 1 1
5.12 What is round-robin scheduling? P3 2 3
Answer: Each job is given a time quantum slice to run; if not P4 1 4
completely done by that time interval, job is suspended and P5 5 2
another job is continued. After all other jobs have been given a The processes are assumed to have arrived in the order P1, P2, P3,
quantum, first job gets its chance again. P4, P5, all at time 0.
5.13 True or False: Round-robin scheduling is preemptive.
29
Inroder to solve the following 3 questions Draw four Gantt charts 6.3 Why does Solaris 2 implement multiple locking mechanisms?
OPERATING SYSTEMS
illustrating the execution of these processes using FCFS, SJF,a Under what circumstances does it use spinlocks, blocking
nonpreemptive priority (a smaller priority number implies a higher semaphores, conditional variables, and readerswriters locks?
priority), and RR (quantum = 1) scheduling. Why does it use each mechanism?
b. What is the turnaround time of each process for each of the Answer: Different locks are useful under different circumstances.
scheduling algorithms in part a? Rather than make do with one type of lock which does not fit
answer :Turnaround time every lock situation (by adding code around the lock, for instance)
it makes sense to include a set of lock types. Spinlocks are the
FCFS RR SJF Priority
basic mechanism used when a lock will be released in a short
P1 10 19 19 16 amount of time. If the lock is held by a thread which is not
P2 11 2 1 1 currently on a processor, then it becomes a blocking semaphore.
P3 13 7 4 18 Condition variables are used to lock longer code sections,
P4 14 4 2 19 because they are more expensive to initiate and release, but
more efficient while they are held. Readers-writers locks are
P5 19 14 9 6.
used on code which is used frequently, but mostly in a read-
c. What is the waiting time of each process for each of the scheduling only fashion. Efficiency is increased by allowing multiple readers
algorithms in part a? at the same time, but locking out everyone but a writer when a
answer Waiting time (turnaround time minus burst time) change of data is needed.
FCFS RR SJF Priority 6.4 Explain the differences, in terms of cost, among the three
P1 0 9 9 6 storage types: volatile, non-volatile, and stable.
P2 10 1 0 0 Answer: Volatile storage is storage which fails when there is a
power failure. Cache, main memory, and registers require a steady
P3 11 5 2 16
power source; when the system crashes and this source is
P4 13 3 1 18 interrupted, this type of memory is lost. Nonvolatile storage is
P5 14 9 4 1 storage which retains its content despite power failures. For
example, disk and magnetic tape survive anything other than
demagnetization or hardware/head crashes (and less likely things
d. Which of the schedules in part a results in the minimal average
such as immersion in water, fire, etc.). Stable storage is storage
waiting time (over all processes)?
which theoretically survives any type of failure. This type of
Answer: Shortest Job First storage can only be approximated with duplication.
5.22 Suppose that a scheduling algorithm (at the level of short- 6.5 Explain the purpose of the checkpoint mechanism. How often
term CPU scheduling) favors those processes that have used should checkpoints be per-formed? How does the frequency
the least processor time in the recent past. Why will this of checkpoints affect:
algorithm favor I/O-bound programs and yet not permanently
System performance when no failure occurs?
starve CPU-bound programs?
The time it takes to recover from a system crash?
Answer: It will favor the I/O-bound programs because of the
relatively short CPU burst request by them; however, the CPU- The time it takes to recover from a disk crash?
bound programs will not starve because the I/ O-bound Answer: Checkpointing is done with log-based recovery schemes
programs will relinquish the CPU relatively often to do their I/ to reduce the amount of searching that needs to be done after
O. a crash. If there is no checkpointing, then the entire log must
6.1 What is the critical-section problem? be searched after a crash, and all transactions redone from the
Answer: To design an algorithm that allows at most one process log. If checkpointing is used, then most of the log can be
into the critical section at a time, without deadlock. discarded. Since checkpoints are very expensive, how often they
should be taken depends upon how reliable the system is. The
6.2 What is the meaning of the term busy waiting? What other more reliable the system, the less often a checkpoint should be
kinds of waiting are there? Can busy waiting be avoided taken.
altogether? Explain your answer.
6.6 Explain the concept of transaction atomicity.
Answer:
Answer: A transaction is a sequence of instructions which, when
A process is waiting for an event to occur and it does so by executed as an atomic unit, takes the database from a consistent
executing instructions. state to a consistent state.
A process is waiting for an event to occur in some waiting
queue (e.g., I/O, semaphore) and it does so without having
the CPU assigned to it.
Busy waiting cannot be avoided altogether.
30
UNIT-2
LESSON 7:
OPERATING SYSTEMS
Objectives and temporary variables), and a data section containing global
Today I will be covering the following topics given below : variables.
What is a Process? Process is allocated resources (such as main memory) and is available
for scheduling.
What is Process Management
A process is not the same as a program. Each process has a state
What is Context Switching
which includes:
What is a Process State?
a program counter: the location of the next instruction to be
What is Process State Transition? executed.
value of all registers (or stack)
What is a process?
A container to run software in values of all variables, including things such as file pointers
(where to start the next read from an input file or where to put
the next write to an output file).
What is a Process?
For example, can have several emacs processes running
You can talk about programs executing but what do you mean? simultaneously, each has a distinct state, but all processes may be
At the very least, you are recognizing that some program code is executing the same machine code.
resident in memory and the CPU is fetching the instructions in Note: A program by itself is not a process; a program is a passive
this code and executing them. entity, such as the contents of a file stored on disk, whereas a
Of course, a running program contains data to manipulate in process is an active entity, with a program counter specifying the
addition to the instructions describing the manipulation. next instruction to execute.
Therefore, there must also be some memory holding data.
The Process Model
You are starting to talk of processes or tasks or even jobs when Even though in actuality there are many processes running at
referring to the program code and data associated with any once, the OS gives each process the illusion that it is running alone.
particular program.
Virtual time: The time used by just this processes. Virtual
What would you need to save if you wanted to take a snapshot time progresses at a rate independent of other processes.
of a process so that you could put it aside for a short period, Actually, this is false, the virtual time is typically incremented a
and then resume its execution later? little during systems calls used for process switching; so if
Process Management there are more other processors more overhead virtual time
This topic deals with handling the many programs that may be in occurs.
main memory at once Virtual memory: The memory as viewed by the process. Each
Introduction to Process Management process typically believes it has a contiguous chunk of memory
A process is a program in execution. In general, a process will need starting at location zero. Of course this cant be true of all
certain resources-such as CPU time, memory, files, and I/O devices- processes (or they would be using the same memory) and in
to accomplish its task. These resources are allocated to the process modern systems it is actually true of no processes (the memory
either when it is created, or while it is executing. assigned is not contiguous and does not include location zero).
A process is the unit of work in most systems. Such a system Think of the individual modules that are input to the linker. Each
consists of a collection of processes: operating system processes numbers its addresses from zero; the linker eventually translates
execute system code, and user processes execute user code. All of these relative addresses into absolute addresses. That is the linker
these processes can potentially execute concurrently. provides to the assembler a virtual memory in which addresses
start at zero.
The operating system is responsible for the following activities in
connection with process management: the creation and deletion Virtual time and virtual memory are examples of abstractions
of both user and system processes; the scheduling of processes, provided by the operating system to the user processes so that the
and the provision of mechanisms for synchronization, latter sees a more pleasant virtual machine than actually exists.
communication, and deadlock handling for processes. Two-State Process Model
A process is more than the program code plus the current activity. Process may be one of two states
A process generally also includes the process stack containing Running
temporary data(such as subroutine parameters, return addresses, Not running
31
As a process executes, it changes state. The state of a process is
OPERATING SYSTEMS
32
Process Control Block (PCB)
OPERATING SYSTEMS
Information associated with each process.
Process state
Program counter
CPU registers
CPU scheduling information Pointer to Text (program code)
Memory-management information Pointer to uninitialized data
Accounting information Stack Pointer
I/O status information Program Counter
Process Control Block Pointer to Data
Each process is represented in the operating system by its own Root directory
process control block (PCB). A PCB is a data block or record Default File Permissions
containing many pieces of the information associated with a specific
Working directory
process, including
Process State
Process State. The state may be new, ready, running, waiting,
or halted. Exit Status
Program Counter. The counter indicates the address of the File Descriptors
next instruction to be executed for this process. Process Identifier (pid)
CPU State. This includes the contents of general purpose User Identifier (uid)
registers, index registers, stack pointers, and any condition- Pending Signals
code information. Along with the program counter, this state
Signal Maps
of information must be saved when an interrupt occurs, to
allow the process to be continued correctly afterward. Other OS-dependent information
CPU Scheduling Information. This information includes a These are some of the major elements that make up the process
process priority, pointers to scheduling queues, and any other context. Although not all of them are directly manipulated on a
scheduling parameters. context switch.
Memory-management information. This information Context
includes limit registers or page tables. The context, in this definition, refers to the contents of the CPU
I/O Status Information. The information includes registers. Remember from earlier when you were talking about the
outstanding I/O requests and a list of open files. instruction execution cycle and interrupt handling? The context is
the stuff on the CPU which needs to be saved so that the CPU can
The PCB serves as the repository for any information that may restart execution at the current point at some later date (usually
vary from process to process. after an interrupt).
Process Implementation Process
The operating system represents a process primarily in a data A process is a program in execution. A program is just a collection
structure called a Process Control Block (PCB). Youll see Tack of code. For example, you have the code for Netscape
Control Block (TCB) and other variants. When a process is created, Communicator on your hard-drive. When you run that program
it is allocated a PCB that includes by double clicking on its icon your operating system copies that
CPU Registers code into RAM, sets up a whole lot of data structures (including
33
a context) and starts executing it. Thats a process. A process is the
OPERATING SYSTEMS
3. load registers for the new context Let us now discuss Context switch versus Process switch
4. re-enter user state The difference between a context switch and a process switch.
Contact Switch is the act of switching from one process to another Context switch
is somewhat machine- dependent. A general outline is:
the OS gets control (either because of a timer interrupt or
because the process made a system call.
Operating system processing info is updated (pointer to the
current PCB, etc.)
Processor state is saved (registers, memory map and floating
point state, etc)
This process is replaced on the ready queue and the next process
selected by the scheduling algorithm
The new processs operating system and processor state is
restored
The new process continues (to this process it looks like a block
call has just returned, or as if an interrupt service routine (not
a signal handler) has just returned
A context switch is where you replace the current context (contents
CPU Switch From Process to Process of the CPU registers) with a new context. A context switch is
usually hardware supported. This means that at least part of a
context switch is performed by the hardware. This means that a
context switch is very, very fast. A context switch usually happens
when an interrupt occurs. Just because a context switch has occurred
it doesnt mean that a process switch will occur.
Process switch
34
Kernel-level threads have more overhead in the kernel (a kernel
OPERATING SYSTEMS
thread control block) and more overhead in their use (manipulating
them requires a system call). However the abstraction is cleaner
(threads can make system calls independently).
Examples include Solaris LWPs, and Java on machines that
support kernel threads (like solaris).
Review Exercise
1. Discuss the role of a process in process management.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
35
Author Peterson, James L.
OPERATING SYSTEMS
36
LESSON 8:
OPERATING SYSTEMS
Objectives In UNIX, the pid t fork (void) system call can be used to create
You will be able to know what operations are performed on a new child with a duplicate address space.
Processes? Let us now discuss Process Creation using different models
You will Understand about Process Scheduling Criteria. There are two main models of process creation - the fork/exec
Now I will start with an Operations on Processes and the spawn models. On systems that support fork, a new
You hopefully now know that the mix of processes present in the process is created as a copy of the original one and then explicitly
system is dynamic, with the operating system attempting to executes (exec) a new program to run. In the spawn model the
manage the mix in order to obtain good resource use efficiency new program and arguments are named in the system call, a new
and good user reactions! I have yet to address the issues involved process is created and that program runs directly.
in process creation and deletion. Fork is the more flexible model. It allows a program to arbitrarily
To manage the process mix, the operating system must be able to: change the environment of the child process before starting the
new program. Typical fork pseudo-code looks like:
Setup a process i.e. create it by marshalling all necessary resources
and placing it in the new queue; and if ( fork() == 0 ) {
Delete a process i.e. reallocating the various resources back to /* Child process */
the operating systems internal inventory data structures change standard input
Process Creation block signals for timers
Process creation is obviously critical to the operating system, run the new program
starting right at the boot up stage where it launches its own }
daemons and other service provider processes. else {
At the core is a process creation system call, which obtains resources /* Parent process */
either from the operating system or from the resources already
wait for child to complete
allocated to the process making the call - these resources are
organized into a PCB and this new process enters the new }
queue. Any parameters of the child processs operating environment that
Using UNIX as an example operating system, we say that a must be changed must be included in the parameters to spawn,
child processes has been created. A child process will possess a and spawn will have a standard way of handling them. There are
prototype of int main() so it will return a result to its parent. various ways to handle the proliferation of parameters that results,
for example AmigaDOS (R) uses tag lists - linked lists of self-
A hierarchical (tree) structure of processes is created.
describing parameters - to solve the problem.
Once a parent creates a child process, a number of execution
possibilities exist: The steps to process creation are similar for both models. The OS
gains control after the fork or spawn system call, and creates and
The parent may immediately enter a wait state for the child to fills a new PCB. Then a new address space (memory) is allocated
finish on UNIX, see the man pages for {wait, waitpid, for the process. Fork creates a copy of the parent address space,
wait4, wait3}; and spawn creates a new address space derived from the program.
The parent could immediately terminate; Then the PCB is put on the run list and the system call returns.
Both may continue to execute. An important difference between the two systems is that the fork
If the parent happens to terminate before the child has returned call must create a copy of the parent address space. This can be
its value, then the child will become a zombie process and may wasteful if that address space will be deleted and rewritten in a few
be listed as such in the process status list! instructions time. One solution to this problem has been a second
Once a parent creates a child process, a number of memory system call, vfork, that lets the child process use the parents memory
possibilities exist: until an exec is made. Well discuss other systems to mitigate the
cost of fork when we talk about memory management.
The child can have a duplicate of the parents address space - as
each process continues to execute, their data spaces will Which is better is an open issue. The tradeoffs are flexibility vs.
presumably diverge; overhead, as usual
The child can have a completely new program loaded into its I will explain you the various steps used for Process Termination
address space; Once a process executes its final instruction, a call to exit() is
made.
37
Even if the user did not program in a call to exit(), the compiler
OPERATING SYSTEMS
38
OPERATING SYSTEMS
Medium term scheduler
The medium term scheduler has nothing to do with the
suspended processes. But the moment the suspending condition
is fulfilled, the medium term scheduler get activated to allocate the
Long term and short term schedule
memory and swap in the process and make it ready for commenting
There are always more processes than it can be executed by CPU
CPU resources. In order to work properly, the medium term
operating System. These processes are kept in large storage devices
scheduler must be provided with information about the memory
like disk for later processing. The long term scheduler selects
requirement of swapped out processes which is usually recorded
processes from this pool and loads them into memory. In memory
at the time of swapping and stored in die related process control
these processes belong to a ready queue. Queue is a type of data
block. In term of the process state transition diagram (figure 1)
structure which has been discussed in course 4. Figure 3 shows the
the medium term scheduler controls suspended to ready transition
positioning of all three type of schedulers. The short term
of swapped processes.
scheduler (also called the CPU scheduler) selects from among the
processes in memory which are ready to execute and assigns the The short term scheduler:
CPU to one of them. The long term scheduler executes less It allocates processes belonging to ready queue to CPU for
frequently. immediate processing. Its main objective is to maximize CPU
requirement. Compared to the other two scheduler it is more
If the average rate of number of processes arriving in memory is frequent It must select a new process for execution quite often
equal to that of departuring the system then the long- term because a CPU executes a process only for few millisecond before
scheduler may need to be invoked only when a process departs the it goes for I/O operation. Often the short term scheduler executes
system. Because of longer time taken by CPU during execution, at least once very 10 millisecond. If it takes 1 millisecond to decide
the long term scheduler can afford to take more time to decide to execute a process for 10 millisecond, the 1/(10+1) = 9% of the
which process should be selected for execution. It may also be very CPU is being wasted simply for scheduling the work. Therefore. it
important that long term scheduler should take a careful selection must be very fast.
of processes i.e. processes should be combination of CPU and I/ In terms of the process state transition diagram it is in charge of
O bound types. Generally, most processes can be put into any of ready to running state transition
two categories: CPU bound or I/O bound. If all processes are I/ Scheduling Criteria
O bound, the ready queue will always be empty and the short
CPU utilization keep the CPU as busy as possible
term scheduler will have nothing to do. If all processes are CPU
bound. no process will be waiting for I/O operation and again Throughput # of processes that complete their execution
the system will be unbalanced. Therefore, the long term scheduler per time unit
provides good performance by selecting combination of CPU Turnaround time amount of time to execute a particular
bound and I/O bound process. process
Medium term scheduler: Waiting time amount of time a process has been waiting in
Most of the processes require some I/O operation. In that case, it the ready queue
may become suspended for I/O operation after running a while. Response time amount of time it takes from when a request
It is beneficial to remove these process (suspended) from main was submitted until the first response is produced, not output
memory to hard disk to make room for other processes. At some (for time-sharing environment)
later time these process can be reloaded into memory and continued
Optimization Criteria
where from it was left earlier. Saving of the suspended process is
said to be swapped out or rolled out. The process is swapped in Max CPU utilization
and swap out by the medium term scheduler. The figure 4 shows Max throughput
the positioning of the medium term scheduler. Min turnaround time
Min waiting time
Min response time
39
Discussion Abraham Silberschatz.
OPERATING SYSTEMS
40
LESSON-9
OPERATING SYSTEMS
Objectives system the consequence of missing one interrupt could be
Today I will teach you the Scheduling Concepts and various dangerous.
Scheduling Algorithms. In non-preemptive systems, jobs are made to wait by longer jobs,
Scheduling Concepts but the treatment of all processes is fairer. The decision whether
The objective of multiprogramming is to have some process to schedule preemptive or not depends on the environment and
running at all times, to maximize CPU utilization. The idea is the type of application most likely to be supported by a given
quite simple. A process is executed until it must wait, typically for operating system
the completion of some I/O request. In a simple computer First-Come, First-Served Scheduling
system, the CPU would normally sit idle while the process waited By far the simplest CPU scheduling algorithm is the first-come,
for the completion of the event. In a multiprogramming system, first- served (FCFS) algorithm. With this scheme, the process that
several processes are kept in memory at a time. When one process requests the CPU is allocated the CPU first. The implementation
has to wait, the operating system takes the CPU away from that of the FCFS policy is easily managed with a First-In-First-Out
process and gives it to another process. This pattern continues. (FIFO) queue. When a process enters the ready queue, its PCB is
Every time one process has to wait, another process may take over linked onto the tail of the queue. When the CPU is free, it is
use of the CPU. allocated to the process at the head of the ready queue. The FCFS
The benefits of multiprogramming are increased CPU utilization scheduling is simple to write and understand.
and higher throughput, which is the amount of work The FCFS scheduling algorithm is nonpreemptive. Once the CPU
accomplished in a given time interval. has been allocated to a process, that process keeps the CPU until it
Scheduling Criteria wants to release the CPU, either by terminating or by requesting I/
The aim of a scheduler algorithm is to allocate the CPU time O. The FCFS algorithm is particularly troublesome for time-sharing
resource in some optimal manner. The definition of optimality systems. Where it is important that each user get a share of the
determines the end result we can consider: CPU at regular intervals. It would be disastrous to allow one
process to keep the CPU for an extended period.
CPU utilization i.e. the proportion of time that the CPU is
doing work; Example:
Throughput i.e. the number of processes (or jobs) completed Process Burst Time
per unit time (not useful unless the jobs are similar in P1 24
complexity); P2 3
Turnaround time i.e. the total elapsed time from when the P3 3
job was submitted to when it was complete, including execution
Suppose that the processes arrive in the order: P 1 , P 2 , P 3 The
time, IO wait time, ready-to-run queue wait time, and all other
Gantt chart for the schedule is:
overheads;CPU burst: the amount of time the process uses
the processor before it is no longer ready
Types of CPU bursts:
short bursts-process I/O bound (i.e. vi)
Scheduling Algorithms Waiting time for P1 = 0; P2 = 24; P3 = 27
CPU scheduling deals with the problem of deciding which of the
Average waiting time: (0 + 24 + 27)/3 = 17
processes in the ready queue to be allocated the CPU. There are
several scheduling algorithms which you will examine in this Suppose that the processes arrive in the order: P2, P3 , P1.
section. The Gantt chart for the schedule is:
A major division among scheduling algorithms is that whether
they support pre-emptive or non-preemptive scheduling
discipline. A scheduling discipline is non-preemptive if once a
process has been given the CPU, the CPU cannot be taken away
from that process. A scheduling discipline is pre-emptive if the
Waiting time for P1 = 6; P2 = 0; P3 = 3
CPU can be taken away.
Average waiting time: (6 + 0 + 3)/3 = 3
Preemptive scheduling is more useful in high priority process
which requires immediate response. For example in Real time Much better than previous case.
41
Convoy effect: short process behind long process Average waiting time = (0 + 6 + 3 + 7)/4 = 4
OPERATING SYSTEMS
42
process, sets a timer to interrupt after 1 time quantum, and A multilevel queue scheduling algorithm partitions the ready queue
OPERATING SYSTEMS
dispatches the process. into separate queues as shown below. Processes are permanently
assigned to one queue, generally based on some property of the
One of two things will then happen. The process may have a CPU
process, such as memory size or process type. Each queue has its
burst of less than 1 time quantum. In this case, the process itself
own scheduling algorithm. For example, separate queues might
will release the CPU voluntarily. The scheduler will then proceed
be used for foreground and background processes. A RR algorithm
to the next process in the ready queue. Otherwise, it the CPU might schedule the foreground process queue, while the
burst of the currently running process is greater than 1 time background an FCFS algorithm schedules queue. In addition,
quantum; the timer will go off and will cause an interrupt to the there must be scheduling between the queues. This is commonly
operating system. A context switch will be executed, and the process a fixed-priority preemptive scheduling. For example, the
will be put at the tail of the ready queue. The CPU scheduler will foreground queue may have an absolute priority over the
then select the next process from the ready queue. background queue.
In the RR scheduling algorithm, no process is allocated the CPU
for more than 1 time quantum in a row. If a processs CPU burst
exceeds 1 time quantum, that process os preempted and is put back
in the ready queue. The RR scheduling algorithm is inherently
preemptive.
The performance of the RR algorithm depends heavily on the
size of the time quantum. At one extreme, if the time quantum
is very large (infinite), the RR policy is the same as the FCFS policy.
If the time quantum is very small (say 10 milliseconds), the RR
approach is called processor sharing, and appears (in theory) to the
users as though each of n processes has its own processor running
at 1/n the speed of the real processor.
For operating systems, you need to consider the effect of context
Multiple queue Scheduling
switching on the performance of RR scheduling. Let use assume
that you have only 1 process of 10 time units. If the quantum is Multilevel Feedback Queue Scheduling
12 time units, the process finishes in less than 1 time quantum, Normally, in a multilevel queue-scheduling algorithm, processes
with no overhead. If the quantum is 6 time units, however, the are permanently assigned to a queue on entry to the system.
process will require 2 quanta, resulting in a context switch. If the Processes do not move between queues. If there are separate
time quantum is 1 time unit, then 9 context switches will occur, queues for foreground and background processes, for example,
slowing the execution of the process accordingly. processes do not move from one queue to the other, since
Thus, you want the time quantum to be large with respect to the processes do not change their foreground or background nature.
context switch time. If the context switch time is approximately 5 This setup has the advantage of low scheduling overhead, but is
percent of the time quantum, then about 5 percent of the CPU inflexible.
time will be spent in context switch. Multilevel feedback queue scheduling, however, allows a process to
Summary of CPU Scheduling implementations move between queues. The idea is to separate processes with
+++ different CPU- burst characteristics. If a process uses too much
CPU time, it will be moved to a lower priority queue. This scheme
|FCFS |inherently non-preemptive |
leaves I/O-bound and interactive processes in the higher priority
+++ queues. Similarly, a process that waits too long in a lower-priority
|SJF |preemptive or non-preemptive | queue may be moved to a higher-priority queue. This is a form of
+++ aging that would prevent starvation.
|Priority |preemptive or non-preemptive | In general, a multifeedback queue scheduler is defined by the
following parameters:
+++
The number of queues
|Round-Robin |inherently preemptive |
The scheduling algorithm for each queue
+++
The method used to determine when to upgrade a process to
Multilevel Queue Scheduling
a higher- priority queue
Another class of scheduling algorithms has been created for
situations in which classes of processes are easily classified into The method used to determine when to demote a process to a
different groups. For example, a common division is made lower-priority queue
between foreground (interactive) processes and background (batch) The method used to determine which queue a process will
processes. These two types of processes have quite different enter when that process needs service
response-time requirements, and so might have different The definition of a multilevel feedback queue scheduler makes it
scheduling needs, In addition, foreground processes may have the most general CPU scheduling algorithm. It can be configured
priority(externally defined) over background processes. to match a specific system under design. Unfortunately, it also
43
requires some means of selecting values for all the parameters to Publisher London : Macmillan, 1984.
OPERATING SYSTEMS
define the best scheduler. Although a multilevel feedback queue is Author Gray, N. A. B. (Neil A. B.)
the most general scheme, it is also the most complex.
Main Title Introduction To Computer Systems / N.A.B. Gray.
Discussions Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
What would be the effect, using the FCFS scheme, if the running 1987.
process got stuck in an infinite CPU loop? Author Peterson, James L.
________________________________________________________________________ Main Title Operating System Concepts / James L. Peterson,
________________________________________________________________________ Abraham Silberschatz.
________________________________________________________________________ Edition 2nd Ed.
________________________________________________________________________ Publisher Reading, Mass. : Addison-Wesley, 1985.
________________________________________________________________________ Author Stallings, William.
________________________________________________________________________ Main Title Operating Systems / William Stallings.
With respect to the Round Robin scheduling scheme, discuss Edition 6th Ed.
the factors, which determine the ideal value for the time Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
quantum. Author Tanenbaum, Andrew S., 1944-
________________________________________________________________________ Main Title Operating Systems : Design And Implementation /
________________________________________________________________________ Andrew S. Tanenbaum, Albert S. Woodhull.
________________________________________________________________________ Edition 2nd Ed.
44
LESSON-10
OPERATING SYSTEMS
Objectives Suppose five processes have CPU needs of 350, 125, 475, 250, 75
Hello ,today you will learn about the following - and are run in that order. The average turnaround time is (350 +
Scheduling Mechanism. (350+125) + (350+125+475) + (350+125+475+250) +
(350+125+475+250+75)) * (1/5) = 4250/5 = 850. The average
Various Process Scheduling algorithms.
wait time is (0 + (350) + (350+125) + (350+125+475) +
Scheduling Mechanisms (350+125+475+250)) * (1/5) = 2975/5 = 595.
Time multiplexing of the CPU by the multiple processes Shortest-job-next (SJN).
simultaneously loaded into RAM. Enqueuer. Ready list (ready
The five processes with CPU needs of 350, 125, 475, 250, 75 will
queue) of pointers to process descriptors. Context switcher saves
be run in the order 75, 125, 250, 350, 475 The average turnaround
all register values of currently running process in an area in its
time is (75 + (75+125) + (75+125+250) + (75+125+250+350) +
process descriptor. Dispatcher chooses process to run next from
(75+125+250+350+475)) * (1/5) = 2800/5 = 560. The average
the ready queue based on the policy in effect. Context switcher
wait time is (0 + (75) + (75+125) + (75+125+250) +
loads the registers from the process descriptor of the process
(75+125+250+350)) * (1/5) = 1525/5 = 305. SJN minimizes
chosen by the dispatcher.
average wait time at the expense of increased variance of waiting
Voluntary release of the CPU when a process yields the CPU, times. Starvation of large jobs is possible if new arrivals to the
requests a resource that cannot be immediately granted, or makes ready queue with small CPU needs are run first even though the
an IO system call. Danger of infinite loops. larger jobs have been waiting longer.
Involuntary release of the CPU. Limits negative effect of process Priority scheduling
infinite loop to just that process. Interval timer device generates
External factors are used to determine which process gets the CPU
interrupts periodically. The interrupt handler code for this device
next, for example, faculty before students, deans before faculty,
can call the CPU scheduler to schedule some other process to run.
etc.
Preemptive scheduling.
Deadline scheduling.
Context switches take 5-10 microseconds, depending on memory
speed and how many registers there are in the CPU. A program digitizing music and writing a CD must be scheduled
carefully so that the buffer of digitized music to be written does
Context switch time is overhead and slows the system down. The
not empty. If that were to happen, the CD is ruined.
hardware determines context switch time. The time a process
spends in the ready queue before running on the CPU slows Preemptive Strategies
down that process. The scheduling policy determines this time, Round robin (time slicing).
not the hardware. If the process is interactive, the user might Widely used. Goal is to provide equitable CPU sharing in a
sense this time if it is long. timesharing interactive environment at the expense of considerable
Scheduling Policies (Strategies) context switch overhead.
Factors: predictable performance, equitable sharing, optimizes Suppose five processes have CPU needs of 350, 125, 475, 250, 75,
performance for certain classes of jobs (batch, interactive, real time). are run in that order for time slices of 50. Assume first that the
Lots of theoretical work done assuming a collection of processes context switch time is zero. The average turnaround time is (1100
in the ready queue, no more processes show up in the ready queue, + 550 + 1275 + 950 + 475) * (1/5) = 4350/5 = 870, comparable
and process total CPU needs and IO needs are known in advance. to FCFS. The average wait time is (0 + 50 + 100 + 150 + 200) * (1/
This is all unrealistic so this theoretical work is of theoretical interest 5) = 500/5 = 100, favorably low.
only. Now suppose the context switch time is not zero but 10 (time
Definitions: service time is the total CPU time needed by a process slice is still 50). The average turnaround time is (1320 + 660 +
to complete, wait time is the time spent in the ready queue before 1535 + 1140 + 565) * (1/5) = 5220/5 = 1044, a substantial increase.
getting the CPU for the first time, turnaround time is the total time The average wait time is (0 + 60 + 120 + 180 + 240) * (1/5) =
from first entering the ready queue (process creation) to leaving 600/5 = 120.
the running state for the last time (process termination). Multiple-level queues.
Batch systems try to minimize average turnaround time (maximize Foreground ready queue and background ready queue. Foreground
throughput or jobs completed per minute). Timesharing systems queue is scheduled round robin. Background ready queue is not
try to minimize the wait time (also called the response time). scheduled unless foreground ready queue is empty and is scheduled
Non preemptive Strategies round robin with a much larger time slice if the foreground queue
First-come-first-served (FCFS). is empty.
45
Multiple-level feedback queues. Main Title Introduction To Computer Systems / N.A.B. Gray.
OPERATING SYSTEMS
CPU-bound ready queue and IO-bound ready queue. OS Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
categorizes processes as they run and switches processes between 1987.
the two ready queues dynamically. The IO-bound ready queue is Author Peterson, James L.
scheduled before the CPU-bound queue to keep the IO devices
Main Title Operating System Concepts / James L. Peterson,
busy.
Abraham Silberschatz.
There might be a real-time ready queue that is scheduled before
Edition 2nd Ed.
the other two.
Publisher Reading, Mass. : Addison-Wesley, 1985.
Discussion
Author Stallings, William.
Now you explain the concept of a priority used in scheduling.
Main Title Operating Systems / William Stallings.
Why is priority working usually chosen for real-time processes?
Edition 6th Ed.
________________________________________________________________________
Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
________________________________________________________________________
Author Tanenbaum, Andrew S., 1944-
________________________________________________________________________
Main Title Operating Systems : Design And Implementation /
________________________________________________________________________
Andrew S. Tanenbaum, Albert S. Woodhull.
________________________________________________________________________
Edition 2nd Ed.
________________________________________________________________________
Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
________________________________________________________________________
Author Nutt, Gary J.
________________________________________________________________________
Main Title Operating Systems : A Modern Perspective / Gary J.
Nutt.
Give your Comments on the principal disadvantages of each
Publisher Reading, Mass. : Addison-Wesley, C1997.
of these scheduling methods:
Author Silberschatz, Abraham.
FCFS
Main Title Operating System Concepts / Abraham
SJF
Silberschatz, Peter Baer Galvin.
RR
Edition 6th Ed.
________________________________________________________________________
Publisher Reading, Mass. : Addison Wesley Longman, C1998.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
Reference Books:
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
Author Deitel, Harvey M., 1945-
Main Title An Introduction To Operating Systems / Harvey M.
Deitel.
Edition Rev. 1st Ed.
Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
Author Lister, A. (Andrew), 1945-
Main Title Fundamentals Of Operating Systems / A.M. Lister.
Edition 3rd Ed.
Publisher London : Macmillan, 1984.
Author Gray, N. A. B. (Neil A. B.)
46
LESSON-11
OPERATING SYSTEMS
Today I will be covering the following objectives. Advantage of Cooperating process
Introduction to Cooperating process. Information sharing: Several users may be interested in the
You will be able to know about Inter-Process Communication same piece of information.
Basic concept of Inter-Process Communication and Computation speedup: If we want particular task to run faster,
Synchronization we must break it into subtasks, each of which will be executing
in parallel with others.
Basic Concepts of Concurrency
Modularity: Dividing the system functions into separate
Concurrent Process: I discussed the concept of a process earlier process or threads.
in this unit. The operating system consists of a collection of such
Convenience: Even an individual user may have many task
processes which are basically two types:
on which to work at one time.
Operating system processes: Those that execute system code
Let us consider the producer-consumer problem, A producer is
and the rest being user processes, those that execute users code.
the process that is consumed by a consumer process. A compiler
All of these processes can potentially execute in concurrent manner.
produce a assembly code that is consume by the assembler. A
Concurrency refers to a parallel execution of a program.
producer is one item and the consumer is the another item. The
A concurrent program specifies two or more sequential programs producer and consumer must be synchronized so that consumer
(a sequential program specifies sequential execution of a list of does not consume an item that has yet been produced.
statements) that may be executed concurrently as parallel processes.
This can be done in following ways
For example, an airline reservation system that involves processing
transactions from many terminals has a natural specifications as a unbounded buffer places no practical limit on the size of the
concurrent program in which each terminal is controlled by its buffer.
own sequential process. Even when processes are not executed bounded buffer assumes that there is a fixed buffer size.
simultaneously, it is often easier to structure as a collection of Bounded Buffer - Shared-Memory Solution
cooperating sequential processes rather than as a single sequential
Using Shared data
program.
const int n = 5; //Buffer Size
A simple batch operating system can be viewed as 3 processes -a
int item; //may be of any data type
reader process, an executor process and a printer process. The
int buffer[n]; //array to hold items
reader reads cards from card reader and places card images in an
int in = 0; //indexes for placement and
input buffer. The executor process reads card images from input
int out = 0; //reading of items in buffer
buffer and performs the specified computation and store the result
in an output buffer. The printer process retrieves the data from
the output buffer and writes them to a printer Concurrent Producer process
processing is the basis of operating system which supports for (;;)
multiprogramming. {
The operating system supports concurrent execution of a program /*Produce Item */
without necessarily supporting elaborate form of memory and nextp = nextp + 1;
file management. This form of operation is also known as /*Test Pointer Position*/
multitasking. Multiprogramming is a more general concept in while(((in+1) % n)== out) //if in pointer catches up
operating system that supports memory management and file { //to out pointer, wait for out
management features, in addition to supporting concurrent /*do nothing*/ //pointer to move on
execution of programs. }
Cooperating Process
/*Place Item In Buffer*/
Concurrent process executing in the operating system may be
buffer[in] = nextp;
either independent process or cooperating process. A process is
independent if cannot affect or affected by another process
/*Increment Pointer*/
executing in the system. Any process that doesnt share any data
in = (in+1)%n;
with any other process is independent. A process is cooperating if
}
it can affect or be affected by the process executing in the system.
Any process that shares data with other process is a cooperating Consumer process
process. for (;;)
{
47
/*Test Pointer Position*/ Now I will explain you Inter-process Communication (IPC)
OPERATING SYSTEMS
while (in == out) //if out pointer catches up There are a number of applications where processes need to
{ //to in pointer, wait for in communicate with each other. Some examples of inter-process
/*do nothing*/ //pointer to move on communication include:
}
When a process prints a table it communicates with operating
system processes.An airline agent runs a program (processes) in
/*Take Item From Buffer*/
the reservation system, which communicates with others about:
nextc = buffer[out];
What flights and seats are available.Which process has access to
/*Increment Pointer*/ critical information (semaphores).
out = (out+1)%n; Two user processes on mhc communicate when they implement
the talk function.Knowledge sources in a blackboard system
/*Consume Item*/ communicate their hyphotheses.
cout << nextc ; Processes can communicate by passing information to each other
} via shared memory or by message passing.
Why Do Processes Intercommunicate?
Often a problem is broken into several stages, each handled by
a process, that passes information to the next stage.
Sometimes a package is broken up into several parts (e.g for an
accounting package: inventory, credits, debits, invoicing, payroll).
Each part will need to pass/obtain information to/from
another part (e.g sales affect inventory etc.).
There are many methods of intercommunicating information
between processes.
Files
Files are the most obvious way of passing information. One
process writes a file, and another reads it later. It is often used
for IPC.
Processes can communicate by passing information to each other
via shared memory or by message passing.
Shared Memory
When processes communicate via shared memory they do so by
entering and retrieving data from a single block of physical memory
that designated as shared by all of them. This memory may be a
single bit or a vast array. Each process has direct access to this block
of memory (see Figure ).
48
Message Passing
OPERATING SYSTEMS
Message passing is a more indirect form of communication. Rather
than having direct access to a block of memory, processes
communicate by sending and receiving packets of information
called messages. These messages may be communicated
indirectly or directly. Indirect message passing is done via a
mailbox. Direct message passing is done via a link between the
two communicating processes.
49
Figure Processes may communicate by sending messages to each
OPERATING SYSTEMS
50
Processes that are working together often share some common Edition 3rd Ed.
OPERATING SYSTEMS
storage that one can read and write. The shared storage may be in Publisher London : Macmillan, 1984.
main memory or it may be a shared file. Each process has segment
Author Gray, N. A. B. (Neil A. B.)
of code, called a critical section, which accesses shared memory or
files. The key issue involving shared memory or shared files is to Main Title Introduction To Computer Systems / N.A.B. Gray.
find way to prohibit more than one process from reading and Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
writing the shared data at the same time. What we need is mutual 1987.
Exclusion : Author Peterson, James L.
some way of making sure that if one process is executing in its Main Title Operating System Concepts / James L. Peterson,
critical section, the other processes will be excluded from doing Abraham Silberschatz.
the same thing. Now I present algorithm to support mutual Edition 2nd Ed.
exclusion. This is applicable for two processes only. Publisher Reading, Mass. : Addison-Wesley, 1985.
Buffering Author Stallings, William.
1 Queue of messages attached to the link; implemented in one Main Title Operating Systems / William Stallings.
of three ways.
Edition 6th Ed.
2. Zero capacity 0 messages Sender must wait for receiver
Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
(rendezvous).
Author Tanenbaum, Andrew S., 1944-
3. Bounded capacity finite length of n messages Sender must
wait if link full. Unbounded capacity infinite length Sender Main Title Operating Systems : Design And Implementation /
Andrew S. Tanenbaum, Albert S. Woodhull.
never waits
Edition 2nd Ed.
Review Exercise
Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
What is Concurrent Process?
Author Nutt, Gary J.
________________________________________________________________________
Main TitleOperating Systems : A Modern Perspective / Gary J.
________________________________________________________________________ Nutt.
________________________________________________________________________ Publisher Reading, Mass. : Addison-Wesley, C1997.
________________________________________________________________________ Author Silberschatz, Abraham.
________________________________________________________________________ Main Title Operating System Concepts / Abraham Silberschatz,
________________________________________________________________________ Peter Baer Galvin.
________________________________________________________________________ Edition 6th Ed.
Publisher Reading, Mass. : Addison Wesley Longman, C1998.
Explain the Basic for Inter-process Communication
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
Reference Books:
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
Author Deitel, Harvey M., 1945-
Main Title An Introduction To Operating Systems / Harvey M.
Deitel.
Edition Rev. 1st Ed.
Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
Author Lister, A. (Andrew), 1945-
Main Title Fundamentals Of Operating Systems / A.M. Lister.
51
LESSON-12
OPERATING SYSTEMS
Producer process
do
{
/*Produce Item */
52
OPERATING SYSTEMS
53
OPERATING SYSTEMS
54
Critical Section 1. Mutual Exclusion. If process Pi is executing in its critical section,
OPERATING SYSTEMS
then no other processes can be executing in their critical sections.
2. Progress. If no process is executing in its critical section and
there exist some processes that wish to enter their critical section,
then the selection of the processes that will enter the critical
section next cannot be postponed indefinitely.
3. Bounded Waiting. A bound must exist on the number of
times that other processes are allowed to enter their critical
sections after a process has made a request to enter its critical
section and before that request is granted.
Number 1 just says the obvious, that no two processes can be
executing their critical section at the same time. Number 2 says
that the choosing process (who will enter the critical section) should
not depend on processes currently executing their critical section -
the system still has to work even if nobody is executing the critical
section. Number 3 says that no process should have to wait forever
to execute its critical section.
Two-Process Synchronization
Assume that each process executes at a nonzero speed.
No assumption concerning relative speed of the n processes.
Only 2 processes, P0 and P1
General structure of process Pi (other process Pj )
Consider a system consisting of several processes, each having a
segment of code called a critical section, in which the process may
be changing common variables, updating tables, etc. The important
feature of the system is that when one process is executing its
critical section, no other process is to be allowed to execute its
critical section. Execution of the critical section is mutually exclusive
in time.
The critical section problem is to design a protocol that these
processes can use to cooperate safely. Each process must request
permission to enter its critical section (entry section). The critical
section may be followed by the exit section.
n processes all competing to use some shared data
Each process has a code segment, called critical section, in which
the shared data is accessed.
Processes may share some common variables to synchronize
Problem - ensure that when one process is executing in its
their actions.
critical section, no other process is allowed to execute in its
critical section. Algorithm 1
ProcessPi
do
{
while (turn != i)
{
/*do nothing*/
}
critical section
turn = j;
remainder section
}
Solution to Critical Section Problem
55
while (true) max(a0, . . . , an-1) is a number, k , such that k >= ai for i = , . . .
OPERATING SYSTEMS
Meets all three requirements; solves the critical section problem Mutual Exclusion with Test and Set
for two processes. Shared data:
Let us now discuss what is Bakery Algorithm boolean lock = false;
Critical section for n processes Process Pi
Before entering its critical section, process receives a number. do
Holder of the smallest number enters the critical section. {
If processes P i and P j receive the same number, if i < j , then while (Test-and-Set(lock))
P i is served first; else P j is served first. {
The numbering scheme always generates numbers in increasing /*do nothing*/
}
order of enumeration; i.e., 1,2,3,3,3,3,4,5...
Notation <= lexicographical order (ticket #, process id #) critical section
(a,b) < (c,d) if a < c or if a = c and b < d lock = false;
56
remainder section Edition 6th Ed.
OPERATING SYSTEMS
}while (true) Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
Author Tanenbaum, Andrew S., 1944-
Check Your Progress Main Title Operating Systems : Design And Implementation /
What is a critical Section? Andrew S. Tanenbaum, Albert S. Woodhull.
________________________________________________________________ Edition 2nd Ed.
________________________________________________________________ Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
Author Nutt, Gary J.
________________________________________________________________
Main Title Operating Systems : A Modern Perspective / Gary J.
________________________________________________________________
Nutt.
________________________________________________________________
Publisher Reading, Mass. : Addison-Wesley, C1997.
________________________________________________________________
Author Silberschatz, Abraham.
________________________________________________________________ Main Title Operating System Concepts / Abraham Silberschatz,
________________________________________________________________ Peter Baer Galvin.
Edition 6th Ed.
What is Process Synchronization? Publisher Reading, Mass. : Addison Wesley Longman, C1998.
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
________________________________________________________________
Reference Books:
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
PublisherPeterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
Author Deitel, Harvey M., 1945-
Main Title An Introduction To Operating Systems / Harvey M.
Deitel.
Edition Rev. 1st Ed.
Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
Author Lister, A. (Andrew), 1945-
Main Title Fundamentals Of Operating Systems / A.M. Lister.
Edition 3rd Ed.
Publisher London : Macmillan, 1984.
Author Gray, N. A. B. (Neil A. B.)
Main Title Introduction To Computer Systems / N.A.B. Gray.
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
1987.
Author Peterson, James L.
Main TitleOperating System Concepts / James L. Peterson,
Abraham Silberschatz.
Edition 2nd Ed.
Publisher Reading, Mass. : Addison-Wesley, 1985.
Author Stallings, William.
Main Title Operating Systems / William Stallings.
57
LESSON-13
Objectives
OPERATING SYSTEMS
}
In previous Lesson you learn about Process Synchronization, while(true)
Synchronization hardware and critical section. Today I will teach Mutual Exclusion with Semaphores
you about the Process Synchronization with Semaphores
which shows how to use semaphores for mutual exclusion.
Semaphore
A non-computer meaning of the word semaphore is a system or
code for sending signals, by using arms or flags held in hands, etc.
Various positions represent different letters and numbers. These
are the things that used to be used on ships to coordinate their
motion (before the invention of radios). Presently, you might
have seen them used on aircraft carriers to coordinate the onboard
activities of airplanes.
In a computer sense, a semaphore is an integer variable that, apart
from initialization, is accessed only through two standard atomic
operations: wait and signal. These operations were originally
termed P (for wait; from the Dutch proberen, to test) and V (for
signal; from verhogen, to increment). The classical definition of wait
in pseudocode is
Points you should Remember
Synchronization tool that does not require busy waiting.
Semaphore S - integer variable
can only be accessed via two indivisible (atomic) operations
wait(s)
{
while (S<=0)
{
/*do nothing*/
}
S= S-1;
}
signal(S)
{
S = S + 1;
}
58
OPERATING SYSTEMS
59
OPERATING SYSTEMS
A
signal(flag)
Pj
.
.
.
wait(flag)
B
Semaphores as Process Synchronization
showing how semaphores can be used for process
synchronization.
Semaphore Implementation
Define a semaphore as a record/structure
struct semaphore
{
int value;
List *L; //a list of processes
}
signal(S)
{
S.value = S.value + 1;
if (S.value <= 0)
{
remove a process P from S.L;
wakeup(P);
}
}
60
OPERATING SYSTEMS
61
Author Dahmke, Mark.
OPERATING SYSTEMS
P0 P1
Main Title Microcomputer Operating Systems / Mark Dahmke.
wait(S); wait(Q);
wait(Q); wait(S); Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
. .
. . Author Deitel, Harvey M., 1945-
. .
signal(S); signal(Q);
Main Title An Introduction To Operating Systems /Harvey M.
signal(Q); signal(S); Deitel.
Edition Rev. 1st Ed.
Starvation -
Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
indefinite blocking. A process may never be removed from the
semaphore queue in which it is suspended. Author Lister, A. (Andrew), 1945-
Main Title Fundamentals Of Operating Systems / A.M. Lister.
Check Your Progress
Edition 3rd Ed.
What is a semaphore? What am its drawbacks?
Publisher London : Macmillan, 1984.
________________________________________________________________
Author Gray, N. A. B. (Neil A. B.)
________________________________________________________________
Main TitleIntroduction To Computer Systems / N.A.B. Gray.
________________________________________________________________
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
________________________________________________________________
1987.
________________________________________________________________
Author Peterson, James L.
________________________________________________________________
Main Title Operating System Concepts / James L. Peterson,
________________________________________________________________
Abraham Silberschatz.
Edition 2nd Ed.
What is a DeadLock ? How to break DeadLocks ?
Publisher Reading, Mass. : Addison-Wesley, 1985.
________________________________________________________________
Author Stallings, William.
________________________________________________________________
Main Title Operating Systems / William Stallings.
________________________________________________________________ Edition 6th Ed.
________________________________________________________________ Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
________________________________________________________________ Author Tanenbaum, Andrew S., 1944-
________________________________________________________________ Main Title Operating Systems : Design And Implementation /
________________________________________________________________ Andrew S. Tanenbaum, Albert S. Woodhull.
Edition 2nd Ed.
Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
Author Nutt, Gary J.
Main Title Operating Systems : A Modern Perspective / Gary J.
Nutt.
Publisher Reading, Mass. : Addison-Wesley, C1997.
Author Silberschatz, Abraham.
Main Title Operating System Concepts / Abraham Silberschatz,
Peter Baer Galvin.
Edition 6th Ed.
Publisher Reading, Mass. : Addison Wesley Longman, C1998.
Reference Books:
62
LESSON-14
OPERATING SYSTEMS
Objectives semaphore mutex = 1; //binary semaphore
Hello students, In previous Lesson you learnt about the Process char nextp, nextc;
Synchronization, Synchronization hardware critical section and Producer process
Semaphores. Today I will teach you various types of Semaphores, do
Monitors and Atomic transactions. {
Two Types of Semaphores produce an item in nextp
Counting semaphore - integer value can range over an wait (empty);
unrestricted domain. wait (mutex);
add nextp to buffer
Binary semaphore - integer value can range only between 0 and signal (mutex);
1; can be simpler to implement. signal (full);
Can implement a counting semaphore S as a binary semaphore. }
Implementing S (Semaphore) as a Binary Semaphore while (true)
Data structures: Consumer process
binary semaphore S1, S2; do
int C; {
wait( full );
Initialization:
wait( mutex );
S1 = 1; remove an item from buffer to nextc
S2 = 0; signal( mutex );
C = initial value of semaphore S; signal( empty );
wait operation consume the item in nextc;
}
wait( S1 );
C = C - 1;
if (C<0)
{ Readers-Writers Problem
signal( S1 ); Shared data
wait( S2 );
} semaphore mutex = 1;
else semaphore wrt = 1;
signal( S1 ); int readcount = 0;
Writer process
signal operation wait(wrt);
wait( S1 ); writing is performed
C = C+1; signal (wrt);
if (C <= 0) Reader process
signal( S2 );
wait (mutex);
signal( S1 );
readcount = readcount + 1;
Let us discuss classical Problems of Synchronization
if (readcount ==1)
BoundedBuffer Problem wait (wrt);
Readers and Writers Problem signal (mutex);
reading is performed
DiningPhilosophers Problem
wait(mutex);
Bounded Buffer Problem readcount = readcount - 1;
Shared data if (readcount == 0)
signal (wrt);
char item; //could be any data type
signal (mutex);
char buffer[n];
semaphore full = 0; //counting semaphore
semaphore empty = n; //counting semaphore
63
Dining Philosophers Problem Example - Bounded Buffer
OPERATING SYSTEMS
Shared variables:
Producer process inserts nextp into the shared buffer
CODE GOES HERE
Consumer process removes an item from the shared buffer
and puts it in nextc
CODE GOES HERE
Implementation: region x when B do S
Associate with the shared variable x, the following variables:
CODE GOES HERE
Mutually exclusive access to the critical section is provided by mutex.
If a process cannot enter the critical section because the Boolean
expression B is false, it initially waits on the first delay semaphore;
moved to the second delay semaphore before it is allowed to
reevaluate B.
Keep track of the number of processes waiting on first delay
and second delay , with first count and second count respectively.
The algorithm assumes a FIFO ordering in the queuing of
processes for a semaphore.
For an arbitrary queuing discipline, a more complicated
implementation is required.
Code Goes Here
Monitors
Shared data
High level synchronization construct that allows the safe sharing
semaphore chopstick[5]; of an abstract data type among concurrent processes.
chopstick[] = 1;
Philosopher i: class monitor
{
do
variable declarations
{
wait (chopstick[i]);
P(1)
wait (chopstick[i+1 mod 5]);
{...}
eat;
signal (chopstick [1]);
P(2)
signal (chopstick [i+1 mod 5]);
{...}
think;
}
P(n)
while (true)
{...}
Critical Regions
High level synchronization construct Initialization code
A shared variable v of type T, is declared as: }
var v: shared T
To allow a process to wait within the monitor, a condition
Variable v accessed only inside statement: variable must be declared, as:
region v when B do S condition x, y;
where B is a Boolean expression.
Condition variable can only be used with the operations wait
While statement S is being executed, no other process can access and signal.
variable v.
The operation
Regions referring to the same shared variable exclude each other
x.wait;
in time.
means that the process invoking this operation is suspended
When a process tries to execute the region statement, the
until another process invokes
Boolean expression B is evaluated. If B is true, statement S is
executed. If it is false, the process is delayed until B becomes x.signal;
true and no other process is in the region associated with v.
64
The x.signal operation resumes exactly one suspended process. For each condition variable x, we have:
OPERATING SYSTEMS
If no process is suspended, then the signal operation has no semaphore x-sem = 0;
effect. semaphore x-count = 0;
Dining Philosophers Example
monitor dining-philosophers The operation x.wait can be implemented as:
{ x-count = x-count + 1;
enum state {thinking, hungry, eating}; if (next-count > 0)
state state[5]; signal(next);
condition self[5]; else
signal(mutex);
void pickup (int i)
wait(x-sem);
{
x-count = x-count - 1;
state[i] = hungry;
test(i);
if (state[i] != eating) The operation x.signal can be implemented as:
self[i].wait; if (x-count > 0)
} {
next-count = next-count + 1;
void putdown (int i) signal(x-sem);
{ wait(next);
state[i] = thinking; next-count = next-count - 1;
test(i+4 % 5); }
test(i+1 % 5); Conditional wait construct: x.wait(c);
} c - integer expression evaluated when the wait operation
is executed.
void test (int k)
{ value of c (priority number) stored with the name of the
if ((state[k+4 % 5] != eating) && (state[k]==hungry) process that is suspended.
&& state[k+1 % 5] != eating)) when x.signal is executed, process with smallest associated
{ priority number is resumed next.
state[k] = eating;
Check two conditions to establish correctness of system:
self[k].signal;
} User processes must always make their calls on the monitor
} in a correct sequence.
Must ensure that an uncooperative process does not
init ignore the mutual exclusion gateway provided by the
{ monitor, and try to access the shared resource directly ,
for (int i = 0; i< 5; i++) without using the access protocols.
state[i] = thinking;
} Atomic Transactions
} Transaction - program unit that must be executed atomically;
that is, either all the operations associated with it are executed
Monitor Implementation Using Semaphores to completion, or none are performed.
Variables Must preserve atomicity despite possibility of failure.
semaphore mutex = 1; We are concerned here with ensuring transaction atomicity in
semaphore next = 0; an environment where failures result in the loss of information
int next-count; on volatile storage.
Log Based Recovery
Each external procedure F will be replaced by
Write ahead log - all updates are recorded on the log, which is
wait(mutex); kept in stable storage; log has following fields:
...
body of F; transaction name
... data item name, old value, new value
if (next-count > 0) The log has a record of <Ti starts>, and either
signal(next);
else <Ti commits> if the transactions commits, or
signal(mutex); <Ti aborts> if the transaction aborts.
Recovery algorithm uses two procedures:
Mutual exclusion within a monitor is ensured.
65
undo(Ti ) - restores value of all data updated by transaction Ti
OPERATING SYSTEMS
66
Author Lister, A. (Andrew), 1945-
OPERATING SYSTEMS
Main Title Fundamentals Of Operating Systems / A.M. Lister.
Edition 3rd Ed.
Publisher London : Macmillan, 1984.
Author Gray, N. A. B. (Neil A. B.)
Main Title Introduction To Computer Systems / N.A.B. Gray.
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
1987.
Author Peterson, James L.
Main TitleOperating System Concepts / James L. Peterson,
Abraham Silberschatz.
Edition 2nd Ed.
Publisher Reading, Mass. : Addison-Wesley, 1985.
Author Stallings, William.
Main Title Operating Systems / William Stallings.
Edition 6th Ed.
Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
There are schedules that are possible under the two-phase Author Tanenbaum, Andrew S., 1944-
locking protocol but are not possible under the timestamp Main Title Operating Systems : Design And Implementation /
protocol, and vice versa. Andrew S. Tanenbaum, Albert S. Woodhull.
The timestamp ordering protocol ensures conflict serializability; Edition 2nd Ed.
conflicting operations are processed in timestamp order. Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
Check Your Progress Author Nutt, Gary J.
What are various type of Semaphores? Main Title Operating Systems : A Modern Perspective / Gary J.
Nutt.
_______________________________________________________________ Publisher Reading, Mass. : Addison-Wesley, C1997.
_______________________________________________________________ Author Silberschatz, Abraham.
_______________________________________________________________ Main Title Operating System Concepts / Abraham Silberschatz,
Peter Baer Galvin.
_______________________________________________________________
Edition 6th Ed.
_______________________________________________________________
Publisher Reading, Mass. : Addison Wesley Longman, C1998.
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
Reference Books:
Author Dahmke, Mark.
Main TitleMicrocomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
Author Deitel, Harvey M., 1945-
Main Title An Introduction To Operating Systems / Harvey M.
Deitel.
Edition Rev. 1st Ed.
Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
67
LESSON-16 UNIT-3
OPERATING SYSTEMS
68
If a process is allocated a resource R1 that it is not using and if We can use these graphs to determine if a deadline has occurred or
OPERATING SYSTEMS
some other process P2 requires the resource, then P2 is denied may occur. If for example, all resources only have one instance (all
the resource and the resource remains idle. resource node rectangles have one dot) and the graph is circular,
then a deadlock has occurred. If on the other hand some resources
How do you characterize deadlocks?
have several instances, then a deadlock may occur. If the graph is
Deadlocks are undesirable because processes never finish
not circular, a deadlock cannot occur (the circular wait condition
executing and system resources are tied up
wouldnt be satisfied).
What are the conditions under which deadlocks can occur in a
system? A set of vertices V and a set of edges E.
A deadlock situation can arise if the following four conditions V is partitioned into two types:
hold simultaneously in a system: P = {P1 , P2 , ..., P n }, the set consisting of all the processes in the
Mutual Exclusion: At least one resource must be held in a non- system.
sharable mode; that is, only one process at a time can use the R = {R1 , R2 , ..., Rm }, the set consisting of all resource types in
resource. If another process requests the resource, the requesting the system.
process must be delayed until the resource has been released.
request edge - directed edge Pi > Rj
Hold and Wait: A process must be holding at least one resource
assignment edge - directed edge Rj > Pi
and waiting to acquire additional resources that are currently being
held by other processes. Process
No Preemption: Resources cannot be preempted; that is, a
resource can be released only voluntarily by the process holding it,
after that process has completed its task.
Circular Wait: A set {P0, P1, P2, , Pn} of waiting processes
must exist such that P0 is waiting for a resource that is held by P1,
P1 is waiting for a resource that is held by P2, , Pn-1 is waiting Resource type with 4 instances
for a resource that is held by Pn, and Pn is waiting for a resource
that is held by P0.
Pi requests instance of Rj
Pi is holding an instance of Rj
69
only run the process when all the resources are available for the
OPERATING SYSTEMS
3. You can totally ignore the deadlock problem (pretend it doesnt Main TitleFundamentals Of Operating Systems / A.M. Lister.
exist). This is what most operating systems do (including UNIX Edition 3rd Ed.
and Windows). Publisher London : Macmillan, 1984.
Preventing deadlocks is ensuring that at least one of the necessary
four deadlock conditions cannot occur. Avoiding a deadlock is Author Gray, N. A. B. (Neil A. B.)
knowing which resources the process will use beforehand and
70
Main Title Introduction To Computer Systems / N.A.B. Gray.
OPERATING SYSTEMS
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
1987.
71
LESSON-17
Alternatively: Initially request tape drive and disk file. Copy from
OPERATING SYSTEMS
Objectives
tape drive to disk file. Then release both. Request again for disk
In previous lecture, you have learnt about the concept of file and printer. Copy from disk to printer. Release disk and printer.
deadlocks, In this lecture you will learn about deadlock prevention
No Preemption: Process holds some resources. It requests
and what causes deadlocks.
another resource, which cannot be immediately allocated to it. All
What are the methods of handling deadlocks? resources currently being held are preempted. Preempted resources
Deadlocks can be handled in many ways. These are as follows: added to available list of resources for which the process is waiting.
Deadlock prevention Process is restarted only when it can regain all its old resources as
well as new ones that it is requesting.
Deadlock Avoidance
Here is an example:
Deadlock Detection and Recovery
Process P1 requests for some resources.
In this lecture, we will discuss about deadlock prevention and in
the next lecture we will look at the other two. Check if they are available.
If yes, allocate
So what is deadlock prevention?
If No,
Deadlock prevention involves a set of methods for ensuring that
at least one of the four necessary conditions cannot hold. Check if they are allocated to some other process that is waiting
for additional resources.
Let me explain each of these conditions in detail:
If yes, preempt desired resources from waiting process and allocate
Mutual Exclusion: If no resource were ever assigned exclusively to requesting process.
to a single process, we would never have deadlocks.
Circular Wait: To prevent circular wait, impose total ordering of
Suppose that two processes are allowed to write on the printer at all resources types. Each process, then, should request resources in
the same time. This would lead to chaos. By spooling the printer an increasing order of enumeration.
output, several processes can generate output at the same time.
The only process that actually requests the physical printer is the Suppose R = {R1, R2 Rm} is a set of resource types.
printer daemon. Since the printer daemon never requests for any Assign to each resource type, a unique integer.
other resources, deadlock can be eliminated for the printer. Define a one-to-one function F such that R>N where N is a
The bottom-line: set of natural numbers.
Avoid assigning a resource when that is not absolutely necessary. For example, F (Tape drive) = 1, F (Disk drive) = 5, F (Printer) =
12.
Hold and wait: All processes are required to request all their
resources before starting execution. If everything is available, Each process requests resource in increasing order of enumeration.
process will be allocated whatever it needs and can run to A process can initially request any number of instances of resource
completion. If one or more resources are busy, nothing will be type Ri.After that, process can request instances of resource type
allocated and process would just wait. Rj if and only if F (Rj) > F (Ri).
Disadvantages: Whenever a process requests an instance of resource type Rj, we
must ensure that it has released any resources Ri such that F (Ri)
Many processes do not know how many resources they will >= F (Rj).
need until they have started running.
Consider another example:
Resources will not be used optimally with this approach
Let i > j. If i is allocated to A, then A cannot request j because i
Starvation may result
> j.
Here is an alternative to overcome this disadvantage:
Let i < j. If j is allocated to B, then B can not request i
A process can request resources only if it has none. This means it
The function F should be defined according to the normal order
should first temporarily release all resources it currently holds.
of usage of the resources in a system.
Can you give us an example?
Check Your Progress
A process copies data from tape drive to disk file, sorts the disk file
and then prints the results on a printer. What are various method of Deadlock prevention?
If all resources (tape drive, disk drive and printer) are requested at _______________________________________________________________
the beginning, then the process must initially request tape drive, _______________________________________________________________
disk file and printer. It will then hold the printer for its entire _______________________________________________________________
execution even though it needs it only at the end. _______________________________________________________________
72
_______________________________________________________________ Author Silberschatz, Abraham.
OPERATING SYSTEMS
_______________________________________________________________ Main Title Operating System Concepts / Abraham Silberschatz,
_______________________________________________________________ Peter Baer Galvin.
_______________________________________________________________ Edition 6th Ed.
_______________________________________________________________ Publisher Reading, Mass. : Addison Wesley Longman, C1998.
_______________________________________________________________ Notes
Reference Books:
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
73
LESSON-18
Objectives
OPERATING SYSTEMS
74
Resource Preemption Main Title Operating System Concepts / James L. Peterson,
OPERATING SYSTEMS
This approach takes resources from waiting processes and gives Abraham Silberschatz.
them to other processes. Obviously, the victim process cannot Edition 2nd Ed.
continue regularly, and you have a choice of how to handle it. We Publisher Reading, Mass. : Addison-Wesley, 1985.
can either terminate that process, or roll it back to some previous
state so that it can request the resources again.
Author Stallings, William.
Again, there are many factors that determine which process you
choose as the victim. Main TitleOperating Systems / William Stallings.
Note: that if the system has resource preemption, by definition, a Edition 6th Ed.
deadlock cannot occur. The type of resource preemption you are Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
talking about here is non-normal preemption that only occurs
when a deadlock detection mechanism detected a deadlock.
Author Tanenbaum, Andrew S., 1944-
Check Your Progress Main TitleOperating Systems : Design And Implementation /
Explain Deadlock Detection process? Andrew S. Tanenbaum, Albert S. Woodhull.
_______________________________________________________________ Edition 2nd Ed.
_______________________________________________________________ Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
_______________________________________________________________
_______________________________________________________________ Author Nutt, Gary J.
_______________________________________________________________ Main TitleOperating Systems : A Modern Perspective / Gary J.
Nutt.
How to recover from Deadlock? Publisher Reading, Mass. : Addison-Wesley, C1997.
_______________________________________________________________
_______________________________________________________________ Author Silberschatz, Abraham.
_______________________________________________________________ Main TitleOperating System Concepts / Abraham Silberschatz,
_______________________________________________________________ Peter Baer Galvin.
_______________________________________________________________ Edition 6th Ed.
Publisher Reading, Mass. : Addison Wesley Longman, C1998.
Reference Books:
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
75
LESSON-19
OPERATING SYSTEMS
76
A town banker deals with a group of customers to whom he Now D runs and requests 3 additional resources and gets them.
OPERATING SYSTEMS
has granted lines of credits. It then runs to completion and releases all its resources.
There are four customers: A, B, C and D, which are analogous Process Current Max. Free = 9
to four processes. A 1 6
The credit unit is like the resource B 0 -
The banker himself is the OS C 0 -
Assume each credit unit = Rs. 1000. D 0 -
Not all customers need their maximum credit immediately. Hence Finally A runs and requests 5 additional resources and gets them.
only 10 credit units are reserved. It then runs to completion and releases all its resources.
Process Current Max. Free = 10
Process Current Max. Free = 10 A 0 -
B 0 -
A 0 6 C 0 -
B 0 5 D 0 -
C 0 4 Here is the complete bankers algorithm:
D 0 7 The bankers algorithm requires the following data structures to
be defined:
How does the algorithm work?
When a new process (customer) enters the system, it (he) must Available: A vector of length m indicates the number of available
declare the maximum number of instances of each resource type resources of each type. If Available [j] = k, there are k
(credit units) that it (he) may need. This number may not exceed instances of resource type Rj available.
the total number of resources (credit units) in the system. When Max: An n * m matrix that defines the maximum demand of
a user (customer) requests a set of resources (credit unit), the each process.
system must determine whether the allocation of these resources If Max [I,j] = k, then process Pi may request at most k instances
will leave the system in a safe state. If it will, the resources are of resource type Rj.
allocated; otherwise, the process must wait until some other
Allocation: An n * m matrix defines the number of resources of
process releases enough resources.
each type currently allocated to each process. If Allocation [I, j] =
Consider current allocation to various processes is as shown below. k, then process Pi is currently allocated k instances of resource type
Process Current Max. Free = 2 Rj.
A 1 6 Need: An n * m matrix indicates the remaining resource need of
B 1 5 each process. If Need [I,j] = k, then Pi may need k more instances
C 2 4 of resource type Rj to complete its task..
D 4 7 Note that Need [ I, j] = Max [I, j] Allocation [I,j].
Would the System be in a safe state? Having defined the data structures, the algorithm now proceeds
in two phases:
C requests 2 additional units and gets them. It then runs to
completion and frees all the resources it has. Safety Algorithm
Process Current Max. Free = 4 Resource Request Algorithm
A 1 6 Safety Algorithm
B 1 5 As discussed earlier, the safety algorithm is for finding out whether
C 0 - or not a system is in a safe state. It is described below:
D 4 7 3. Let work and finish be vectors of length m and n respectively.
Initialize work = Available and Finish[I] = false for all I = 1,
2, , n.
Now either B or D can request and run to completion. Assume
4. Find an I such that both
B requests 4 additional units and gets them. It then runs to
completion and frees all its resources. Finish[I] = false
Process Current Max. Free = 5 Need i <=work
A 1 6 If no such I exists, go to step 4.
B 0 - 5. work = work + allocationi
C 0 - finish[I] = true
go to step 2
D 4 7
6. If finish[I] = true for all I, then the system is in a safe state.
77
This algorithm may require an order of m * n2 operations to What is this graph of resource requests?
OPERATING SYSTEMS
decide whether a state is safe. It is also known as a DRAG (Directed resource allocation graph).
Resource Request Algorithm The DRAG is a:
Having determined that the system is safe, this algorithm grants Directed Graph
the requested resources to the process. Consists of set of vertices V and a set of edges E
Let Requesti be the request vector for process P i . If Requesti [j] = k, V is partitioned into two sets:
then process Pi wants k instances of resource type Rj. When this P (set of all processes) = {P1, P2, P3, , Pn}
request is made, the following actions are taken:
R (set of all resources) = {R1, R2, R3, , Rm}
1. If request I <= need I, then go to step 2. Otherwise raise an
A directed edge from process Pi to resource Rj is denoted by: Pi
error condition because the process has exceeded its maximum
claim. Rj (known as request edge)
A directed edge from resource Rj to process Pi is denoted by:
2. If request I <= available, go to step 3. Otherwise, Pi must
wait since the resources are not available. Rj Pi (known as assignment edge)
Each process Pi is represented by a circle and each resource
3. Have the system pretend to have allocated the requested
resources to process Pi by modifying the state as follows: type Rj is represented by a square.
Multiple instances of a resource type are represented by dots
a. Available = available request I
b. Allocation = allocation + request I The notation Rj > Pi indicates:
Process Pi has been allocated an instance of resource type Rj.
c. Need I = Need I request I
An assignment edge always points to a Circle (Pi) in the DRAG
4. Call the Safety algorithm. If the state is safe, then transaction is
and must also designate one of the dots.
completed and process Pi is allocated the resources. If the new
state is unsafe, then Pi must wait and the old resource allocation When a process releases a resource, the assignment edge is deleted.
state is restored. The notation Pi > Rj indicates:
Exercise: Process Pi has requested for an instance of resource type Rj and is
currently waiting.
Consider a system with five processes P0 through P4 and three
Request Edge always points to a Square (Rj) in a DRAG.
resource types A, B and C. A has 10 instances, B has five instances
and C has seven instances. Consider the following snapshot of When a process Pi requests an instance of a resource Rj, a request
the system: edge is inserted into the DRAG and after the request is fulfilled,
the edge is converted into an assignment edge.
Process Allocation Max Available
If a DRAG has no cycles, no process is deadlocked.
A B C A B C
A B C If a DRAG has a cycle, deadlock may exist.
P0 0 1 0 7 5 3 If each resource type has only one instance, then a cycle implies
3 3 2 that deadlock occurred. (Necessary and sufficient condition)
P1 2 0 0 3 2 2 If each resource type has several instances, then a cycle does not
necessarily imply a deadlock has occurred.
P2 3 0 2 9 0 2 Example Of A Drag
There are two minimal cycles: P1>R1>P2>R3>P3
P3 2 1 1 2 2 2 >R2>P1 and P2>R3>P3>R2>P2.
Processes P1, P2, P3 are deadlocked because:
P4 0 0 2 4 3 3 P2 is waiting for R3, which is held by P3.
P3 is waiting for R2 which is held by P1 and P2 and
Assume that the system is in a safe state. (prove it!). P1 is waiting for R1, which is held by P2
Suppose now that process P1 requests one additional instance of Once you detect a deadlock using the DRAG, how do you
resource type A and two instances of resource type C. So Request recover from it?
= (1,0,2). Apply bankers algorithm to determine if the request
1
Once you have discovered a deadlock, you have to figure out how
can be granted.
to break it. This involves preempting a resource, which might
Deadlock detection and recovery mean canceling a process and starting it over.
If a system does not employ either deadlock prevention or a Deadlock detection and recovery is the optimistic solution to the
deadlock avoidance algorithm, then a deadlock situation may occur. problem. You assume deadlock is unlikely, but detect it and recover
The system should first detect the deadlock and then try to recover from it when it occurs rather than spending resources trying to
from it. prevent it or avoid it.
Deadlock in a system can be detected by finding a cycle in a graph Review Questions:
of resource requests. 1. List three examples of deadlocks that are not related to
computer-system environment.
78
2. Is it possible to have a deadlock involving only one single Publisher London : Macmillan, 1984.
OPERATING SYSTEMS
process? Explain your answer. Author Gray, N. A. B. (Neil A. B.)
3. Consider the following snapshot of a system: Main Title Introduction To Computer Systems / N.A.B. Gray.
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
Process Allocation Max Available 1987.
A B C D A B C D A B C D Author Peterson, James L.
P0 0 0 1 2 0 0 1 2 1 5 2 0 Main TitleOperating System Concepts / James L. Peterson,
Abraham Silberschatz.
P1 1 0 0 0 1 7 5 0
P2 1 3 5 4 2 3 5 6 Edition 2nd Ed.
P3 0 6 3 2 0 6 5 2 Publisher Reading, Mass. : Addison-Wesley, 1985.
P4 0 0 1 4 0 6 5 6 Author Stallings, William.
Main Title Operating Systems / William Stallings.
a) What is the content of the matrix need? Edition 6th Ed.
b) Is the system in a safe state? Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
c) If a request from the process P1 arrives for (0,4,2,0) can the Author Tanenbaum, Andrew S., 1944-
request be granted immediately? Main Title Operating Systems : Design And Implementation /
Check Your Progress Andrew S. Tanenbaum, Albert S. Woodhull.
Explain Deadlock Avoidance Procedure? Edition 2nd Ed.
_______________________________________________________________ Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
_______________________________________________________________ Author Nutt, Gary J.
_______________________________________________________________ Main Title Operating Systems : A Modern Perspective / Gary J.
Nutt.
_______________________________________________________________
Publisher Reading, Mass. : Addison-Wesley, C1997.
_______________________________________________________________
Author Silberschatz, Abraham.
_______________________________________________________________
Main TitleOperating System Concepts / Abraham Silberschatz,
_______________________________________________________________ Peter Baer Galvin.
_______________________________________________________________ Edition 6th Ed.
_______________________________________________________________ Publisher Reading, Mass. : Addison Wesley Longman, C1998.
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
Reference Books:
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
Author Deitel, Harvey M., 1945-
Main TitleAn Introduction To Operating Systems / Harvey M.
Deitel.
Edition Rev. 1st Ed.
Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
Author Lister, A. (Andrew), 1945-
Main Title Fundamentals Of Operating Systems / A.M. Lister.
Edition 3rd Ed.
79
SELF-ASSESSMENT INTERACTIVE
OPERATING SYSTEMS
7.1 List types of resources we might consider in deadlock problems available vector Available(m)
on computers. demand matrix Max(n,m)
Answer: CPU cycles, memory space, files, I/O devices, tape drives, allocation matrix Allocation(n,m)
printers. need matrix Need(n,m)
7.2 Define deadlock. 7.9 Summarize the bankers algorithm.
Answer: A situation where every process is waiting for an event Answer:
that can be triggered
a. If request for process i exceeds its need, error has occurred.
only by another process.
b. If request of process i exceeds available resources, process i
7.3 What are the four necessary conditions needed before deadlock must wait.
can occur?
c. The system temporarily allocates the resources process i wants;
Answer: if the state is unsafe, the allocation is postponed.
a. At least one resource must be held in a nonsharable mode. 7.10 Summarize the Safety Algorithm.
b. A process holding at least one resource is waiting for more Answer:
resources held by other processes.
a. Initialize vector Work to Available and set vector Finish to false.
c. Resources cannot be preempted.
b. Find a process such that Finish(i) = false and Need(i) leq Work.
d. There must be a circular waiting.
c. If found, add Allocation(i)toWork(i), Finish(i)to true,and go to
7.4 Give examples of sharable resources. step b.
Answer: Read-only files, shared programs and libraries. d. If not found, continue here. If Finish(i) = true for all processes
7.5 Give examples of nonsharable resources. then state is safe, else it is unsafe.
Answer: Printer, magnetic tape drive, update-files, card readers. 7.11 How can we determine whether current state is safe in
7.6 List three overall strategies in handling deadlocks. systems with only one instance of each resource type?
Answer: Answer: State is unsafe if any cycle exists.
a. Ensure system will never enter a deadlock state. 7.12 What conditions must exist before a wait-for graph is useful
b. Allow deadlocks, but devise schemes to recover from them. in detecting deadlocks?
80
7.18 What three issues must be considered in the case of
OPERATING SYSTEMS
preemption?
Answer:
a. Select a victim to be preempted.
b. Determine how far back to rollback the victim.
c. Determine means for preventing that process from being
starved.
Notes
81
LESSON-21 UNIT-4
OPERATING SYSTEMS
82
Linking postponed until execution time. Operating system cannot anticipate all of the memory references a
OPERATING SYSTEMS
Small piece of code, stub, used to locate the appropriate program will make
memoryresident library routine. What does sharing mean?
Stub replaces itself with the address of the routine, and executes Allow several processes to access the same portion of memory
the routine. Better to allow each process (person) access to the same copy of
Operating system needed to check if routine is in processes the program rather than have their own separate copy
memory address.
Overlays What does logical organization of memory mean?
To handle processes larger than their allocated memory Programs are written in modules
Keep in memory only instructions and data needed at any Modules can be written and compiled independently
given time Different degrees of protection given to modules (read-only,
Implemented by user, no special support needed from OS, execute-only)
programming design is complex Share modules
The Need for Memory Management What does physical organization of memory mean?
Memory available for a program plus its data
may be insufficient
Overlaying allows various modules to be
Overlay for a two-pass
assigned the same region of memory
assembler:
Pass 1 70KB Programmer does not know how much space
Pass 2 80KB will be available
Symbol Table 20KB
Common Routines 30KB Swapping
Swapping is the act of moving processes
Total 200KB between memory and a backing store. This is
Two overlays: 120 + 130KB done to free up available memory. Swapping is
necessary when there are more processes than
available memory. At the coarsest level, swapping
is done a process at a time. That is, an entire
process is swapped in/out.
Main memory is generally the most critical resource in a computer
system in terms of the speed at which programs run and hence it
is important to manage it as efficiently as possible.
What are the requirements of Memory Management?
The requirements of memory management are:
Relocation
Protection
Sharing
Logical Organization
Physical Organization
What is meant by relocation?
Programmer does not know where the program will be placed
in memory when it is executed
While the program is executing, it may be swapped to disk and
returned to main memory at a different location (relocated)
Memory references must be translated in the code to actual
physical memory address
What is meant by protection?
Processes should not be able to reference memory locations in
another process without permission What are the various memory management schemes
Impossible to check absolute addresses in programs since the available?
program could be relocated There are many different memory management schemes. Selection
of a memory management scheme for a specific system depends
Must be checked during execution
83
on many factors, especially the hardware design of the system. A
OPERATING SYSTEMS
84
_____________________________________________________________________
OPERATING SYSTEMS
Current process mode bit prot. bit access status
USER u-mode 0 OS _____________________________________________________________________
N
USER u-mode 1 user Y
Reference Books:
OS p-mode 1 user Y
OS p-mode 0 OS AuthorY Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Fence Register: Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
Similar to any other register in the CPU
Contains address of the fence between OS and the user process Author Deitel, Harvey M., 1945-
(see Fig. 2)
Main TitleAn Introduction To Operating Systems / Harvey M.
Fence Register value = P Deitel.
For every memory reference, when final address is in MAR Edition Rev. 1st Ed.
(Memory Address Register), it is compared with Fence Register
Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
value by h/w thereby detecting protection violations
Author Lister, A. (Andrew), 1945-
Main TitleFundamentals Of Operating Systems / A.M. Lister.
Edition 3rd Ed.
Publisher London : Macmillan, 1984.
O
Author Gray, N. A. B. (Neil A. B.)
O
S Main TitleIntroduction To Computer Systems / N.A.B. Gray.
P
FENC
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
E 1987.
User
Process Author Peterson, James L.
Area
Main TitleOperating System Concepts / James L. Peterson,
Abraham Silberschatz.
Edition 2nd Ed.
MA
X Publisher Reading, Mass. : Addison-Wesley, 1985.
Author Stallings, William.
In a multi-programming environment, where more than one Main TitleOperating Systems / William Stallings.
process is in the memory, we have the fixed-partition scheme. Edition 6th Ed.
In this scheme, Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
Main memory is divided into multiple partitions Author Tanenbaum, Andrew S., 1944-
Partitions could be of different sizes but fixed at the time of Main TitleOperating Systems : Design And Implementation /
system generation Andrew S. Tanenbaum, Albert S. Woodhull.
Could be used with or without swapping and relocation Edition 2nd Ed.
To change partition sizes, system needs to be shut down and Publisher Upper Saddle River, Nj : Prentice Hall, C1997.
generated again with a new partition size
Author Nutt, Gary J.
Review Questions: Main Title Operating Systems : A Modern Perspective / Gary J.
1. What is Memory Management? Nutt.
_____________________________________________________________________ Publisher Reading, Mass. : Addison-Wesley, C1997.
_____________________________________________________________________ Author Silberschatz, Abraham.
_____________________________________________________________________ Main Title Operating System Concepts / Abraham Silberschatz,
_____________________________________________________________________ Peter Baer Galvin.
_____________________________________________________________________ Edition 6th Ed.
_____________________________________________________________________ Publisher Reading, Mass. : Addison Wesley Longman, C1998.
2. What is various type of addressing?
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
85
LESSON-22
Objectives
In the last lecture, you have learnt about memory management, Can a process be allocated to any partition?
swapping and concept of contiguous memory allocation. In this The processes are allocated to the partitions based on the allocation
lecturer you are going to learn about how OS manages the memory policy of the system. The allocation policies are:
partitions. First Fit
So how does the OS manage or keep track of all these partitions? Best Fit
In order to manage all the partitions, Worst Fit
The OS creates a Partition Description Table (PDT) Next Fit
Initially all the entries in PDT are marked as FREE Let me explain this with a simple example:
When a partition is loaded into one of the partitions, the
status column is changed to ALLOC
86
Yes. This scheme causes wastage of memory, referred to as
OPERATING SYSTEMS
fragmentation.
Let me explain with an example:
Suppose there is a process, which requires 20K of memory. There
is a partition of size 40K available. Assuming that the system is
following the First-fit policy, then this partition would be allocated
to the process. As a result, 20K of memory within the partition is
unused. This is called internal fragmentation.
Now consider the same 20K process. This time, though there are
three partitions of 10K, 5K and 16K available. None of them are
large enough to accommodate the 20K process. There are no other
smaller processes in the queue. Hence these three partitions remain
unused. This is waste of memory and is referred to as external
fragmentation.
All the blocks associated with a partition allocated to a process What are the disadvantages of this mechanism?
are given the same key. Memory wastage due to internal fragmentation
Limits maximum number of partitions (due to key length)
Hardware malfunction may generate a different address but in
the same partition - scheme fails!!
Limit Register:
The Limit Register for each process can be stored in the PCB
and can be saved/restored during context switch.
If the program size were 1000, logical addresses generated would
be 0 to 999
The Limit Register therefore is set to 999
87
Every logical or virtual address is checked to ensure that it is Reference Books:
OPERATING SYSTEMS
<= 999 and then added to base register. If not, then hardware Author Dahmke, Mark.
generates an error and process is aborted. Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
88
LESSON-23
OPERATING SYSTEMS
Objectives
In the last two lectures, you will learnt about memory management,
swapping and concept of contiguous memory allocation. In this
lecturer you are going to learn multiprogramming environment
using fixed and Dynamic partitions.
Multiprogramming With Fixed Partition
In a multiprogramming environment, several programs reside in
primary memory at a time and the CPU passes its control rapidly
between these programs. One way to support multiprogramming
is to divide the main memory into several partitions each of which
is allocated to a single process. Depending upon how and when
partitions are created, there may be two types of memory
partitioning:
(1) Static and
(2) Dynamic.
Static partitioning implies that the division of memory into
number of partitions and its size is made in the beginning (during
the system generation process) and remain fixed thereafter. In
dynamic partitioning, the size and the number of partitions are
decided during the run time by the operating system. In this
section we will take up static partitioning and multiprogramming
with dynamic (variable) partitioning will be discussed in the next
Fixed Size Partition
section.
As shown, the memory is partitioned into 6 regions. The first
In this section, You present several memory management schemes region Lower area) is reserved for operating system. The remaining
based on contiguous allocation. five regions are for user programs. Three partitions occupied by
The basic approach here is to divide memory into several fixed programs P1, P2 and P3. Only the first and last one are free and
size partitions where each partition will accommodate only one available for allocation.
program for execution. The number of programs (i.e. degree of Once partitions are defined, operating system keeps track of status
multiprogramming) residing in memory will be bound by the (whether allocated or free) of memory partitions. Ibis is done
number of partition When a program terminates, that partition through a data structure called partition description table (figure).
is free for another program waiting in a queue.
An example of partition memory is shown in figure.
89
Partition Description Table One important issue concerning swapping is whether the process
OPERATING SYSTEMS
The two most Common strategies to allocate free partitions to removed temporarily from any partition should be brought back
ready processes are: (i) first-fit and (ii) best-fit. The approach to the same partition or any partition of adequate size.
followed in the first fit is to allocate the first free partition large This is dependent upon partitioning policy. The binding of process
enough to accommodate the process. The best fit approach on to a specific partition (static partitioning) eliminates overhead of
the other hand allocates the smallest free partition that meets the run time allocation of partition at the expense of lowest utilization
requirement of the process. of primary memory. On the other hand, systems where processes
Both strategies require to scan the partition description table to are not permanently bound to a specific partition (dynamic
find out free partitions. However, the first-fit terminates after partition) are much more flexible and utilizes memory more
finding the first such partition whereas the best-fit continues efficiently. The only drawback with dynamic partitioning approach
searching for the near exact size. is run time overhead of partition allocation whenever a new process
As a result, the first-fit executes faster whereas the best- fit achieves is swapped in.
higher utilization of memory by searching the smallest free As said earlier, the loading of a process into a same partition
partition. Therefore, a trade-off between execution speed of first- where from it was swapped out into a different partition is
fit and memory utilization of best-fit must be made. dependent upon relocation policy. The term relocation usually
To explain these two strategies, let us take one example. A new refers to the ability to load and execute a given program into an
process P4 with size 80K is ready to be allocated into memory arbitrary memory partition as opposed to fixed set of memory
whose partition layout is given in figure 2. Using first-fit strategy, locations specified at program translation time.
P4 will get the first partition leaving 120K of unused memory. Depending upon when and how the addresses translation from
Best fit will continue searching for the best possible partition and the virtual address to actual address (also called physical address)
allocate the last partition to the process leaving just 20K bytes of of primary memory, takes place, process or program relocation
unused memory. may be regarded as static relocation and dynamic relocation. There
Wherever a new process is ready to be loaded into memory and if is a difference between virtual and physical address. Virtual address
no partition is free, swapping of processes between main memory refers to information within a programs address space, while
and secondary storage is done. Swapping helps in CPU utilization physical address specifies the actual physical memory locations
by replacing suspend able processes but residing into main memory where program and data are stored in memory during execution
with ready to execute processes from secondary storages. When time.
the scheduler admits a new process (of high priority) for which no If the relocation is performed before or during the loading of a
partition is free, a memory manager is invoked to make a partition program into memory by a relocating linker or a relocating loader,
free to accommodate the process. the relocation approach is called static relocation. The static
relocation is practically restricted to support only static binding of
The memory manager performs this task by swapping out low
processes to partition.
priority processes suspended for a comparatively long time in
order to load and execute the higher priority process. When the Dynamic relocation refers to run-time mapping of virtual address
higher priority process is terminated, the lower priority process into physical address with the support of some hardware
mechanism such as base registers and limit registers. Relocation
can be swapped back and continued.
of memory references at run-time is illustrated in the following
Swapping requires secondary storage device such as fast disk to figure:
store the suspended processes from main memory. One problem
with swapping process is that it takes lengthy time to access process
from secondary storage device. For example, to get an idea of total
swap time, assume that user program is 100K words and secondary
storage device is a fixed head disk with an average latency of 8m sec
and a transfer rate of 250,000 words/second then a transfer of
100K words to or from memory takes:
8msec + (100K words/250,000 words/sec)
= 8msec + 100000 words/250,000 words/sec
= 8msec + 215 sec
= 8msec + 2000/5 msec
= 8msec + 400 msec When a process is scheduled, the base register is loaded with the
starting address. Every memory address generated automatically
= 408 msec (approximately)
has the base register contents added to it before being sent to
Since you must swap in and swap out the total swap time is main memory. Thus, if the base register is 100000 (IOOK), a
about 408+408 = 816msec. MOVE R1, 200 which is supposed to load the contents of virtual
The overhead must be considered when deciding whether to swap address 200 (relative to program beginning) into register, effectively
a process in order to make room for another process. turned into a MOVE R1, 100000 + 200, without the instruction
itself being modified. The hardware protects the base register to
prevent user programs from modifying.
90
An additional advantage of using a base register for relocation is Multiprogramming With Dynamic Partitions
OPERATING SYSTEMS
that a program can be moved anywhere in memory after it has The main problem with fixed size partition is the wastage of
started execution. memory by programs that are smaller than their partitions (i.e.
Protection and Sharing: Multiprogramming introduces one internal fragmentation). A different memory management
essential problem of protection. Not only that the operating approach known as dynamic partitions (also called variable
system must be protected from user programs/processes but partition) which creates partitions dynamically to meet the
each user process should also be protected from maliciously requirements of each requesting process. When a process
accessing the areas of other processes. terminates or becomes swapped-out, the memory manager can
return the vacated space to the pool of free memory areas from
In system that uses base register for relocation, a common approach
which partition allocations are made.
is to use limit (bound) register for protection. The primary
function of a limit register is to detect attempts to access memory Compared to fixed partitions, in dynamic partitions, neither the
location beyond the boundary assigned by the operating system. size nor the number of dynamically allocated partition need be
When a process is scheduled, the limit register is loaded with the limited at any other time. Memory manager continues creating
highest virtual address in a program. As illustrated in figure 5, and allocating partitions to requesting processes until all physical
each memory access of a running program is first compared with memory is exhausted or maximum allowable degree of
the contents of the limit register. If it exceeds the limit register, multiprogramming is reached.
no permission is given to the user process. In this way, any attempt The main difference between the fixed partition and variable
to access a memory location beyond the boundary is trapped. partitions is that the number, location and size of partitions vary
dynamically in the latter as processes are created and terminated,
whereas they are
fixed in the
former. The
flexibility of not
being tied to a
fixed number
of partitions
that may be too
large or too
small for
requesting
processes,
improves
m e m o r y
utilisation but it
also complicates
the process of
allocation and
deallocation of memory.
Protection through Limit and Base Register In variable partition, operating system keeps track of which parts
In addition to protection, a good memory management of memory are available and which are allocated.
mechanism must also provide for controlled sharing of data and Assume that we have 640K main memory available in which 40K
code between cooperating processes. One traditional approach to is occupied by operating system program. There are 5 jobs waiting
sharing is to place data and code in a dedicated common partition. for memory allocation in a job queue (figure ). Applying FCFS
However, any attempt by a participating process to access memory scheduling policy, Process 1, Process 2 and Process 3 can be
outside of its own participation is normally regarded as a protection immediately allocated in memory. Process 4 cannot be
violation. In systems with protection keys, this obstacle may be accommodated because there is only 600 - 550 = 50K left for it.
circumvented by changing the keys of all shared blocks upon every This situation is shown in figure (a)
process switch in order to grant access rights to currently running
process.
Fixed partitioning imposes several restrictions:
No single program/process may exceed the size of the largest
partition in a given system.
It does not support a system having dynamically data structure
such as stack, queue, heap etc.
It limits the degree of multiprogramming which in turn may
reduce the effectiveness of short-term scheduling.
91
holes of sizes 30K, 20K, 40K and 20K which have been compacted
OPERATING SYSTEMS
fragmenatoitn.
After
the swapping out of Process 2 due to termination, Process 5 will
be loaded for execution.
This example illustrates one important problem with variable
size partitions. The main problem is external fragmentation. It
exists when the size of memory is large enough for a requesting
process, but it cannot satisfy a request because it is not contiguous;
storage is fragmented into a small number of holes (free spaces).
Depending upon the total size of memory and number and size
of a program, external fragmentation may be either a minor or a
major problem.
One solution to this problem is compaction. It is possible to
combine all the holes (free spaces) into a large block by pushing all
the processes downward as far as possible. The following figure
illustrates the compaction of memory. In figure (a) there are 4
92
OPERATING SYSTEMS
_____________________________________________________________________
Comparison of some different ways to Compact memory
_____________________________________________________________________
If you apply simplest algorithm, Process 3 and 4 will be moved at
the end, for a total movement of 500K creating a situation in _____________________________________________________________________
figure (b). If you simply move Process 4 above 3, then you only 2. How to manage in the multiprogramming environment
300K is moved or if you move Process 3 down below Process 4, using dynamic partitions
then you move only 200K. Please observe that a large memory _____________________________________________________________________
hole (block) is now in the middle. Therefore, if you have large _____________________________________________________________________
number of processes, selection of which process or processes for
_____________________________________________________________________
shifting downwards or upwards to meet the requirement for
waiting process is quite difficult task. _____________________________________________________________________
_____________________________________________________________________
Advantages:
One advantage with variable partition is that memory utilization _____________________________________________________________________
is generally better than fixed size partitions, since partitions are Reference Books:
created accordingly to the size of process. Author Dahmke, Mark.
Protection and sharing in static and dynamic partitions are quite Main Title Microcomputer Operating Systems / Mark Dahmke.
similar, because of same hardware requirement except for some
PublisherPeterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
additional consideration due to compaction of memory during
dynamic partitioning.
One advantage of dynamic partitioning is to support processes Author Deitel, Harvey M., 1945-
whose memory requirement increase during their execution. In Main Title An Introduction To Operating Systems / Harvey M.
that case operating system creates a larger partition and moves a Deitel.
process into it. If there is an adjacent free area it simply expands it.
Edition Rev. 1st Ed.
Disadvantages: Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
Dynamic memory management requires lots of operating system
space, time, complex memory management algorithm and
bookkeeping operation. Author Lister, A. (Andrew), 1945-
Compaction time is very high. Although internal fragmentation Main Title Fundamentals Of Operating Systems / A.M.
is negligible, external fragmentation may be severe problem Lister.
imposing a time penalty for compaction. Edition 3rd Ed.
Review Questions: Publisher London : Macmillan, 1984.
1. How to manage in the multiprogramming environment using Author Gray, N. A. B. (Neil A. B.)
fixed partitions
Main Title Introduction To Computer Systems / N.A.B. Gray.
_____________________________________________________________________
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
_____________________________________________________________________ 1987.
_____________________________________________________________________
93
OPERATING SYSTEMS
94
LESSON-24
OPERATING SYSTEMS
Objectives
In the last lecture, you learnt about multiprogramming
environment using fixed and Dynamic partitions. In this lecture,
you will get to know about non-contiguous memory management
scheme and the concept of Paging and Segmentation.
Let us start by defining non-contiguous memory. Non-contiguous
memory means that the available memory is not contiguous but
is distributed.
This scheme has the benefit of minimizing external fragmentation.
How?
The logical address space of the process is allowed to be non-
contiguous, thus allowing a process to be allocated physical
memory wherever the later is available. This is achieved using a
concept called paging.
What is paging?
Paging is a process where by
Physical memory is broken down into fixed size blocks called
page frames.
Logical memory is broken down into blocks of the same size
as physical memory blocks and is called pages.
When a process is to be executed, its pages are loaded from the Every address generated by CPU is divided into two parts:
backing store into any available memory frames. page number (p) and page offset (d)
p is used as an index into a page map table
Page table contains base address of each page in physical memory
The base address is combined with d to define physical memory
address that is then put into the MAR
Compiler generates one-dimensional single address in binary
Assume 16-bit addresses are used
The address needs to be partitioned into P (page number) and
D (offset)
How many bits (out of 16) are needed for P and how many for
D?
Answer depends on page size.
For example if page size is 1024 bytes, then we require 10 bits
(210=1024) for D and remaining 6 for P
Here is a complete example illustrating paging:
Let Page size = 4 bytes and available physical memory = 32 bytes
We therefore have 8 frames and 8 pages as follows:
Page 0 addresses 0 - 3
Page 1 addresses 4 - 7
Page 2 addresses 8 - 11
Page 3 addresses 12 - 15
Page 4 addresses 16 - 19
Page 5 addresses 20 - 23
Does this require any hardware support? Page 6 addresses 24 - 27
Yes. The picture below shows the support required. Page 7 addresses 28 31
95
To access 4 bytes within each page, we need 2 bits
OPERATING SYSTEMS
96
Hierarchical Paging Virtual page numbers are compared in this chain searching for
OPERATING SYSTEMS
Hashed Page Tables a match. If a match is found, the corresponding physical frame
is extracted.
Inverted Page Tables
Having understood the basic concept of paging, we will now look
Hierarchical Page Table - Two-Level at another concept called segmentation.
97
Reference Books:
OPERATING SYSTEMS
Notes
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
98
LESSON-25
OPERATING SYSTEMS
Objectives 2. Several user programs can reference the same segment
In the last lecture, you learnt Paging and memory protection Some of the segments of a program may consist of library code
scheme. In this lecture, you will get to know about non-contiguous shareable with other users. In this case, several users could
memory management scheme and the concept of Segmentation simultaneously access the same copy of the code. For example, in
the above, the Pascal library could be allocated as a shared segment.
Why Segmentation? In this case, each of the processes using the shared code would
1. Pages are of a fixed size contain a pointer the same physical memory location.
In the paging scheme we have discussed, pages are of a fixed size,
and the division of a processs address space into pages is of little
interest to the programmer. The beginning of a new page comes Segment table Segment table Segment table
logically just after the end of the previous page. user A user B user C
2. Segments are of variable sizes Ptr to private code Ptr to private code Ptr to private code
An alternate approach, called segmentation, divides the processs
address space into a number of segments - each of variable size. A Ptr to private code Ptr to shared code Ptr to private code
logical address is conceived of as containing a segment number
and offset within segment. Mapping is done through a segment Ptr to shared code Ptr to private code Ptr to private code
table, which is like a page table except that each entry must now
Ptr to private code Ptr to shared code
store both a physical mapping address and a segment length (i.e.
a base register and a bounds register) since segment size varies Ptr to private code Ptr to private code
from segment to segment.
3. No (or little) internal fragmentation, but you now have
external fragmentation This would not be possible with pure paging, since there is no
Whereas paging suffers from the problem of internal one-to-one correspondence between page table entries and logical
fragmentation due to the fixed size pages, a segmented scheme program units.
can allocate each process exactly the memory it needs (or very close 3. Protection issues
to it - segment sizes are often constrained to be multiples of Of course, the sharing of code raises protection issues. This is
some small unit such as 16 bytes.) However, the problem of most easily handled by associating with each segment table entry
external fragmentation now comes back, since the available spaces an access control field - perhaps a single bit. If set, this bit might
between allocated segments may not be of the right sizes to satisfy allow a process to read from the segment in question, but not to
the needs of an incoming process. Since this is a more difficult write to it. If clear, both read and write access might be allowed.
problem to cope with, it may seem, at first glance, to make Now, segments that correspond to pure code (user written or
segmentation a less-desirable approach than paging. library) are mapped read only. Data is normally mapped read-
4. Segments can correspond to logical program units write. Shared code is always mapped read only; shared data might
However, segmentation has one crucial advantage that pure paging be mapped read-write for one process and read only for others.
does not. Conceptually, a program is composed of a number of
What is segmentation?
logical units: procedures, data structures etc. In a paging scheme,
In paging, the users view of memory and the actual physical
there is no relationship between the page boundaries and the
memory are separated. They are not the same. The users view is
logical structure of a program. In a segmented scheme, each logical
mapped onto the physical memory.
unit can be allocated its own segment.
1. Example with shared segments
Example: A Pascal program consists of three procedures plus a
main program. It uses the standard Pascal IO library for read,
write etc. At runtime, a stack is used for procedure activation records.
This program might be allocated memory in seven segments:
One segment for the main routine.
Three segments, one for each procedure.
One segment for Pascal library routines.
One segment for global data.
One segment for the runtime stack.
99
Since segments vary in length, memory allocation is a dynamic
OPERATING SYSTEMS
storage-allocation problem.
A segmentation example is shown in the following diagram
100
variable length and is intrinsically defined by the purpose of the
OPERATING SYSTEMS
segment in the program.
Thus segmentation is a memory management scheme that
supports this user view of memory. Thus a logical address space
is a collection of segments with each segment having a name and
length.
What is a 2-d address?
In paging, a 1-d virtual address and a 2-d address would be
exactly same in binary form as page size is an exact power of 2
In segmentation, segment size is unpredictable. Hence we need
to express the address in 2-d form explicitly.
A system implementing segmentation needs to have a different
address format and a different architecture to decode the address
So, what does the segment address consist of?
The address consists of:
Figure-2
A segment number (S)
Let the virtual address to be translated be 2520
An offset (D) within the segment
This corresponds to segment 3 (S) and offset = 20 (D) from
So what does the logical address space in segmentation consist
figure-1
of?
Segment # is used as index into SMT.
Each segment is compiled with reference to 0 as the starting
address for that segment Info. at this entry is: seg-size = 900, base = 6100 (figure-2)
Application programmer does not necessarily have to declare Displacement D is a virtual address within the segment and
different segments in his program explicitly should not exceed seg-size. In this case, D = 20 is less than seg-
The compiler/linkage editor does it on its own as follows: size = 900
OS then checks access rights.
Recognizes different segments
Effective address is then: Base + D = 6100 + 20 = 6120 which
Numbers them
is also the physical address.
Builds segment table
Each process has one SMT
Produces an executable image by assigning a 2-d address.
So what is this SMT?
How is the segment table constructed? Just as there was a page map table (PMT) associated with each
Refer to the figure on page-4. process, there is a segment map table (SMT) per process. The
Putting all the segments, virtually one after the other, we get the segment table specifies physical base address and address range.
following table: Virtual addresses are offsets within a segment, added to base
address and checked against address limit. Multiple segments
Virtual Address Range Virtual Segment handled by address mode or segment register. A typical SMT is
Number shown in figure-2.
0 999 0
1000 1699 1
1700 2499 2
2500 3399 3
3400 3899 4
Figure-1
From the table, a virtual address 1100 will mean Segment # 1 and
displacement 100 (S=1, D=100) and a virtual address 3002 will
mean S = 3 and D = 502
How is address translation done in segmentation?
I will explain this with an example:
101
The Intel Pentium uses segmentation with paging for memory _____________________________________________________________________
OPERATING SYSTEMS
102
LESSON-26
OPERATING SYSTEMS
Objectives for a very large main memory to alleviate any need for storage
In the last lecture, you learnt about Paging and Segmentation . In allocation. This solution was not possible due to very high cost.
this lecture, you will get to know about Virtual Memory The second proposal is known as virtual memory
Virtual memory is a memory management technique that allows Definition
the execution of processes that may not be completely in main Virtual memory is a technique that allows processes that may not
memory and do not require contiguous memory allocation. be entirely in the memory to execute by means of automatic storage
The address space of virtual memory can be larger than that physical allocation upon request. The term virtual memory refers to the
memory. abstraction of separating LOGICAL memory-memory as seen
by the process-from PHYSICAL memory-memory as seen by
Advantages: the processor. Because of this separation, the programmer needs
programs are no longer constrained by the amount of physical to be aware of only the logical memory space while the operating
memory that is available system maintains two or more levels of physical memory space.
increased degree of multiprogramming
less overhead due to swapping
Why Do you Need Virtual Memory?
Storage allocation has always been an important consideration in
computer programming due to the high cost of main memory
and the relative abundance and lower cost of secondary storage.
Program code and data required for execution of a process must
reside in main memory to be executed, but main memory may
not be large enough to accommodate the needs of an entire process.
Early computer programmers divided programs into sections that
were transferred into main memory for a period of processing
time. As the program proceeded, new sections moved into main
memory and replaced sections that were not needed at that time.
In this early era of computing, the programmer was responsible
for devising this overlay system.
As higher level languages became popular for writing more complex
programs and the programmer became less familiar with the
machine, the efficiency of complex programs suffered from poor
overlay systems. The problem of storage allocation became more
complex.
The virtual memory abstraction is implemented by using secondary
Two theories for solving the problem of inefficient memory
storage to augment the processors main memory. Data is
management emerged -static and dynamic allocation. Static
transferred from secondary to main storage as and when necessary
allocation assumes that the availability of memory resources and
and the data replaced is written back to the secondary storage
the memory reference string of a program can be predicted. Dynamic
according to a predetermined replacement algorithm. If the data
allocation relies on memory usage increasing and decreasing with
swapped is designated a fixed size, this swapping is called paging;
actual program needs, not on predicting memory needs.
if variable sizes are permitted and the data is split along logical
Program objectives and machine advancements in the 60s made lines such as subroutines or matrices, it is called segmentation.
the predictions required for static allocation difficult, if not Some operating systems combine segmentation and paging
impossible. Therefore, the dynamic allocation solution was
The diagram illustrates that a program generated address ( 1 ) or
generally accepted, but opinions about implementation were still
logical address consisting of a logical page number plus the
divided. One group believed the programmer should continue to
location within that page (x) must be interpreted or mapped
be responsible for storage allocation, which would be accomplished
onto an actual (physical) main memory address by the operating
by system calls to allocate or deallocate memory. The second group
system using an address translation function or mapper ( 2 ). If
supported automatic storage allocation performed by the operating
the page is present in the main memory, the mapper substitutes
system, because of increasing complexity of storage allocation
the physical page frame number for the logical number ( 3 ). If the
and emerging importance of multiprogramming. In 1961, two
mapper detects that the page requested is not present in main
groups proposed a one-level memory store. One proposal called
103
memory, a fault occurs and the page must be read into a frame in between those pages that are in memory and those that are on the
OPERATING SYSTEMS
The mapper is the part of the operating system that translates the
logical page number generated by the program into the physical
page frame number where the main memory holds the page. This
translation is accomplished by using a directly indexed table called
the page table which identifies the location of all the programs
pages in the main store. If the page table reveals that the page is,
in fact, not resident in the main memory, the mapper issues a
page fault to the operating system so that execution is suspended
on the process until the desired page can be read in from the
secondary store and placed in main memory.
The mapper function must be very fast if it is not to substantially
increase the running time of the program. With efficiency in mind,
where is the page table kept and how is it accessed by the mapper?
The answer involves associative memory.
Virtual memory can be implemented via:
Demand paging What happens if a process tries to use a page that was not brought
Demand segmentation into memory?
If you try to access a page that is marked invalid (not in memory),
What is demand paging?
then page fault occurs.
Demand paging is similar to paging with swapping. Processes
normally reside on the disk (secondary memory). When we want How do you handle such page faults?
to execute a process, we swap it into memory. Rather than swapping Upon page fault, the required page brought into memory by
the entire process into memory, however, we use a lazy swapper. executing the following steps:
What is a lazy swapper? 1. Check an internal table to determine whether the reference was
A lazy swapper never swaps a page into memory unless that page valid or invalid memory access.
will be needed. Since we are now viewing a process as a sequence 2. If invalid, terminate the process. If valid, page in the required
of pages rather than one large contiguous address space, the use page
of the term swap is technically incorrect. A swapper manipulates 3. Find a free frame (from the free frame list).
entire processes whereas a pager is concerned with the individual
4. Schedule the disk to read the required page into the newly
pages of a process. It is correct to use the term pager in connection
allocated frame
with demand paging.
5. Modify the internal table to indicate that the page is in memory
So how does demand paging work?
6. Restart the instruction interrupted by page fault
Whenever a process is to be swapped in, the pager guesses which
pages will be used before the process is swapped out again. So
instead of swapping in the whole process, the pager brings only
those necessary pages into memory. Here, I would like to add that
demand paging requires hardware support to distinguish
104
OPERATING SYSTEMS
What is the advantage of demand paging?
Demand paging avoids reading into memory pages that will not
be used anyway. This decreases the swap time and also the physical A logical address 02FE would be translated into the physical
memory needed. address 01A0FE.
We saw that whenever the referenced page is not in memory, it C. Security in a paging system
needs to be paged in. To start with, a certain number of frames in
In a paging system, one security provision that is needed is a
main memory are allocated to each process. Pages (through demand
check to be sure that the page number portion of a logical
paging) are loaded into these frames.
address corresponds to a page that has been allocated to the
What happens when a new page needs to be loaded into memory process. This can be handled either by comparing it against a
and there are no free frames available? maximum page number or by storing a validity indication in
Well, the answer is simple. Replace one of the pages in memory the page table. This can be done by providing an additional bit
with the new one. This process is called page replacement. in the page table entry in addition to the frame number. In a
paging system, an attempt to access an invalid page causes a
So Virtual memory basics
hardware trap, which passes control to the operating system.
A. Virtual memory is an extension of paging and/or The OS in turn aborts the process.
segmentation
D. Situations that cause traps to the Operating System
The basic implementation of virtual memory is very much like
In a virtual memory system, we no longer require that all of the
paging or segmentation. In fact, from a hardware standpoint,
pages belonging to a process be physically resident in memory
virtual memory can be thought of as a slight modification to
at one time. Thus, there are two reasons why a logical address
one of these techniques. For the sake of simplicity, we will
generated by a process might give rise to a hardware trap:
discuss virtual memory as an extension of paging; but the
same concepts would apply if virtual memory were 1. violations
implemented as an extension of segmentation. The logical address is outside the range of valid logical addresses
B. Page table used to translate logical to physical addresses for the process. This will lead to aborting the process, as before.
(We will call this condition a memory-management violation.)
Recall that in a paging scheme each process has a page table
which serves to map logical addresses generated by the process 2. page faults
to actual physical addresses. The address translation process The logical address is in the range of valid addresses, but the
can be described as follows: corresponding page is not currently present in memory, but
1. Break the logical address down into a page number and an rather is stored on disk. The operating system must bring it
offset. into memory before the process can continue to execute. (We
will call this condition a page fault).
2. Use the page number as an index into the page table to find
the corresponding frame number. E. Need a paging device to store pages not in memory
3. Using the frame number found there, generate a physical In a paging system, a program is read into memory from disk
address by concatenating the frame number and the offset all at once. Further, if swapping is used, then the entire process
from the original address. is swapped out or in as a unit. In a virtual memory system,
Example: suppose the page table for a process looks like this. processes are paged in/out in a piece-wise fashion. Thus, the
Assume that the page size is 256 bytes, that logical addresses are operating system will need a paging device (typically a disk)
16 bits long, and that physical addresses are 24 bits long. (All where it can store those portions of a process which are not
numbers in the table are hexadecimal): currently resident.
1. When a fault for a given page occurs, the operating system will
read the page in from the paging device.
105
2. Further, if a certain page must be moved out of physical Some implementations also require a per-page accessed bit that
OPERATING SYSTEMS
memory to make room for another being brought in, then the is set whenever any access (read or write) to the page occurs.
page being removed may need to be written out to the paging This can be used to help decide which pages are no longer
device first. (It need not be written out if it has not been altered being actively used and so can be paged out to make room for
since it was brought into memory from the paging device.) new pages coming in. Not all memory management strategies
3. When a page is on the paging device rather than in physical require this, however.
memory, the page table entry is used to store a pointer to the Virtual memory design issues
pages location on a the paging device.
A. Policy for bringing pages into memory
F. Virtual memory has an impact on CPU scheduling 1. When does the OS decide to bring a page in?
In a virtual memory system, the hardware can behave in basically We have already noted that, in general, only a portion of the
the same way as for paging. However, the operating system no pages belonging to a given process will actually be resident in
longer simply aborts the process when the process accesses an physical memory at any given time. Under what circumstances
invalid page. Instead, it determines which of the above two is a given page brought in from the paging device?
reasons caused the trap. If it is the latter, then the operating
system must initiate the process of bringing in the appropriate 2. Demand paging
page. The process, of course, must be placed into a wait state The simplest policy is demand paging. Simply stated, under
until this is completed. So our set of possible process states demand paging, a given page is only brought into memory
must be extended from: when the process it belongs to attempts to access it. Thus, the
RUNNING number of page faults generated by a process will at least be
equal to the number of pages it uses. (The number of faults
READY
will be higher if a page that has been used is removed from
WAITING for IO to complete memory and then is used again.) In particular, when a process
to: starts running a program there will be a period of time when
RUNNING the number of faults generated by the process is very high:
READY a. Page faults occur one-by-one as program begins running
WAITING for IO to complete To start running the program, the CPU PC register is set to the
first address in the program. Immediately, a page fault occurs
WAITING for a page to be brought in
and the first page of the program is brought in. Once control
(Note, though, that a page wait is in reality just another leaves this page (due either to running off the end or to a
form of IO wait, except that here the reason for the wait subroutine call) another fault occurs etc. Further, any access to
is not an explicit IO instruction in the process.) data will also generate a fault.
b. Startup and post-swapped time can be slow
G. Hardware support beyond that for paging along is required An implication of pure demand paging is that the initial startup
for virtual memory of a new program may take a significant amount of time, since
Though the burden of recognizing and handling page faults each page needed will require a disk access to get it. Likewise, if
falls on the operating system, certain provisions must be present a process is ever swapped out of memory due to a long IO
in the hardware that are not needed with simple paging: wait then when it is brought back in it will be paged in one page
1. A page fault could occur while a single instruction is being at a time.
carried out c. No pages are brought into memory unnecessarily
The ability to restart an instruction that caused a fault in mid- The chief advantage of demand paging is that no pages are
stream. This can be tricky if the instruction accesses large blocks ever brought into memory unnecessarily. For example, if a
of memory - e.g. a block move that copies a character string en program contains code for handling a large number of different
masse. kinds of input data, only the code needed for the actual data
2. Page table entry should include a dirty bit presented to it will ever be brought in.
Though it is not strictly necessary, it is desirable to include a 3. Anticipatory or Pre-paging
written-in bit in the page table entry, along with the valid bit Some systems combine demand paging with some form of
noted above. This bit is set if any location in the page has been anticipatory paging or pre-paging. Here, the idea is to bring a
modified since it was brought into physical memory. This bit page in before it is accessed because it is felt that there is good
comes into play when the operating system finds it necessary reason to expect that it will be accessed. This will reduce the
to take the frame away from a page to make room for a new number of page faults a process generates, and thus speed up
page being faulted in. If the old page has not been written in, its startup at the expense of possibly wasting physical memory
then it need not be written back to disk, since it is the same as space on unneeded pages. Anticipatory paging becomes
the copy on disk that was brought in originally. increasingly attractive as physical memory costs go down.
3. May want a bit to indicate that a page has been accessed a. Pages known to be initially required can all be loaded at
once
106
When initially loading a program, there may be a certain allowed to grow by taking pages from other processes or should
OPERATING SYSTEMS
minimum set of pages that have to be accessed for program be required to page against itself.
initialization before branching based on the input data begins a. The working set is the set of pages that a process has
to occur. These can all be read in at once. accessed in the time interval [ T - T , T ]
b. All pages swapped out can later be swapped back in at The working set for a process is defined in terms of some
once
interval T back from the current time T. Building on the
If a process is totally swapped out during a long IO wait, then principle of locality of reference, it is assumed that this is a
swap the whole set of pages that were swapped out back in good approximation to the set of pages that the process must
when it is resumed instead of paging it back in a little bit at a have physically resident in order to run for an interval T into
time.
the future without a page fault. (The interval T is chosen to
c. Structure of page device may make it advantageous to keep the percentage of memory accesses resulting in a fault to
read several pages at once an acceptable level. A time corresponding to around 10,000
Another form of anticipatory paging is based on the clustering memory accesses being a good rule of thumb.)
of the paging device. If several pages reside in the same cluster b. During the life of a process, there are times when the
on the paging device, then it may be advantageous to read all working set changes slowly and other times when it changes
of them in if any one of them is demanded, since the added rapidly
transfer time is only a small fraction of the total time needed
Studies of the memory access behavior of processes show that
for a disk access. This is especially advantageous if the pages
typically there are periods of time during which the working set
correspond to logically-adjacent memory locations.
of a given process changes very little. During these periods, if
B. Page replacement policies: What page do we remove from sufficient physical memory is allocated to the process then it
memory? can page locally against itself with an acceptably low rate of
Over time, the number of pages physically resident in memory page faults. These periods are separated by bursts of paging
on a system under any significant load will eventually equal the activity when the processs working set is changing rapidly. These
number of available frames. At this point, before any new correspond to major stages in the program execution - e.g. the
page can be faulted in a currently resident page must be moved termination of one top level subroutine and the starting up of
out to make room for it. The question of how to select a page another. When this happens performance is improved if the
to be replaced is a very important one. In general, there are two global paging is used.
kinds of page replacement policies. c. Maintaining a working set requires some system overhead
1. Global policies Of course, determining what the actual working set of a process
When process X needs to fault in a new page, the set of is requires a certain amount of overhead - notably keeping track
candidates for replacement includes all pages belonging to all of what pages have been referenced during a past interval.
processes on the system. Note that unless a page belonging to (This is one of the places that a hardware referenced bit comes
X already happens to be chosen, this will result in an increase in in.) One way to keep track of a processs working set involves
the total amount of physical memory allocated to X. using a timer that interrupts at the chosen interval T::
2. Local policies At the start of the interval, turn off all of the referenced bits in
When process X needs to fault in a new page, the set of the page table for the currently running process.
candidates for replacement includes only those pages currently When the timer interrupts, include in the working set only
belonging to process X. Note that this means that the total those pages whose referenced bit is now on.
amount of physical memory allocated to X will not change. d. The working set concept can also be applied without going
3. In general, a system will have to incorporate both kinds of to all of the effort needed to determine the exact working
policy: set:
a. At startup, we must use a global policy If the page fault rate for a process lies within a certain
When a process is just starting up, a global policy will have to empirically determined range, then assume that it has
be used since the new process has few pages available as sufficient physical memory allocated to it to hold its (slowly
replacement candidates. evolving) working set and page it locally.
b. Local paging may be used to keep a particular process If the page fault rate increases above the upper limit, assume
from using too much memory its working set is expanding and page it globally, allowing its
Eventually, however, a local policy may have to be imposed to physical memory allocation to grow to keep pace with its
keep a given process from consuming too much of the systems presumably growing working set.
resources. If the page fault rate drops too low, then consider reducing its
4. The working set of a process physical memory allocation by not only paging it against
itself but also allowing other processes to take page frames
Many of the policies to be discussed below can be applied
from it. This corresponds to an assumption that the size of
either locally or globally. The notion of a processs working set
can be used to help decide whether the process should be
107
its working set is less than the amount of physical memory _____________________________________________________________________
OPERATING SYSTEMS
108
OPERATING SYSTEMS
Author Stallings, William.
Main TitleOperating Systems / William Stallings.
Edition 6th Ed.
Publisher Englewood Cliffs, Nj : Prentice Hall, C1995.
109
LESSON-27
OPERATING SYSTEMS
110
hand, it could contain a heavily used variable that was initialized
OPERATING SYSTEMS
early and is in constant use. Disadvantages:
2. Suffers from Beladys Anomaly. Contrary to expectation, 1. Difficult to implement. Requires future knowledge of reference
allocating more frames can result in worse page-fault behavior. string.
In the illustration above: (check this out by yourself) Used mainly for comparison studies.
Hit ratio with 3 frames: 25% LRU Algorithm
Hit ratio with 4 frames: 16.7% Idea: Approximation of optimum algorithm. Replace the page
that has not been used for the longest period of time. Associates
with each page, the time of that pages last use. When a page has
to be replaced, LRU chooses that page that has not been used for
the longest period of time.
Illustration: (Assume the three frames are initially empty)
Reference String
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
Frame-1 7 7 7 2 H 2 H 4 4 4 0 H H 1 H 1 H 1 H H
Frame-2 0 0 0 0 0 0 3 3 3 0 0
Frame-3 1 1 3 3 2 2 2 2 2 7
* * * ^ ^ ^ ^ ^ ^ ^ ^ ^
111
Main TitleFundamentals Of Operating Systems / A.M. Lister.
OPERATING SYSTEMS
112
LESSON-28
OPERATING SYSTEMS
Objectives Two memory accesses per translation. First the SMT and then
In the last lecture, you learnt about paging and segmentation PMT.
which are two methods of implementing virtual memory. You More tables to manage (SMT and PMT)
also saw the advantages and disadvantages of these two methods.
In this lecture, we will study about a method which is the How can you minimize the memory access?
combination of paging and segmentation. This can be done by providing something called as TLB
(Translation Look-aside Buffer). The TLB is like a cache. It keeps
Paged Segmentation the most recent translations. Only when there is a miss in the TLB
In this model, the logical memory is composed of segments. will the memory is accessed.
Each segment is composed of pages. The per process segment
table is in memory pointed to by register. Entries map segment How does the TLB work?
number to page table base. The page table is as described in the When a reference to a page is made, the TLB is checked to see if
previous lecture. there is an entry. If yes, then the frame number is retrieved from
the TLB. If not, there is a TLB miss and the PMT is accessed. If
How is the mapping from the logical address to physical
the page is in the PMT, then it is loaded from there into the TLB
address done in this combined approach?
and the physical address is computed. If the page is not there in
The Logical address now consists of segment number, page the PMT also, then a page fault occurs and the required page is
number, and offset. The segment number is indexed into segment retrieved from the virtual memory and loaded into the PMT and
table to get base of page table. The page number is then used to
then the TLB.
index into page table to get the frame number. The frame number
is then concatenated with the offset to get the physical address. What is a page fault?
The figure below gives an example of this mapping. When a page is referenced and it is not in the PMT (and hence in
memory), then it needs to be fetched from the virtual memory.
This is called as page fault.
Review Questions
1. Explain Paged Segmentation
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Reference Books:
Author Dahmke, Mark.
What are the main advantages of this combined approach?
The advantages stem out from the fact that it combines the Main Title Microcomputer Operating Systems / Mark Dahmke.
individual advantages of paging and segmentation. Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
Reduces external fragmentation (due to paging within a
segment) Author Deitel, Harvey M., 1945-
Multiple address spaces available (for various segments) Main TitleAn Introduction To Operating Systems / Harvey M.
Distinguishes between access violations and page faults Deitel.
Swapping can occur incrementally Edition Rev. 1st Ed.
Instructions can have smaller address fields Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
What are the main disadvantages of this combined approach?
Author Lister, A. (Andrew), 1945-
113
Main Title Fundamentals Of Operating Systems / A.M. Lister.
OPERATING SYSTEMS
Notes
114
LESSON-29
SELF- ASSESSMENT INTERACTIVE TOPIC
OPERATING SYSTEMS
7.1 List types of resources we might consider in deadlock problems allocation matrix Allocation(n,m)
on computers. need matrix Need(n,m)
Answer: CPU cycles, memory space, files, I/O devices, tape drives, 7.9 Summarize the bankers algorithm.
printers. Answer:
7.2 Define deadlock. a. If request for process i exceeds its need, error has occurred.
Answer: A situation where every process is waiting for an event b. If request of process i exceeds available resources, process i
that can be triggered only by another process. must wait.
7.3 What are the four necessary conditions needed before deadlock c. The system temporarily allocates the resources process i wants;
can occur? if the state is unsafe, the allocation is postponed.
Answer: 7.10 Summarize the Safety Algorithm.
a. At least one resource must be held in a nonsharable mode. Answer:
b. A process holding at least one resource is waiting for more a. Initialize vector Work to Available and set vector Finish to false.
resources held by other processes.
b. Find a process such that Finish(i) = false and Need(i) leq Work.
c. Resources cannot be preempted.
c. If found, add Allocation(i)toWork(i), Finish(i)to true,and go to
d. There must be a circular waiting. step b.
7.4 Give examples of sharable resources. d. If not found, continue here. If Finish(i) = true for all processes
Answer: Read-only files, shared programs and libraries. then state is safe, else it is unsafe.
7.5 Give examples of nonsharable resources. 7.11 How can we determine whether current state is safe in
Answer: Printer, magnetic tape drive, update-files, card readers. systems with only one instance of each resource type?
7.6 List three overall strategies in handling deadlocks. Answer: State is unsafe if any cycle exists.
Answer: 7.12 What conditions must exist before a wait-for graph is useful
in detecting deadlocks?
a. Ensure system will never enter a deadlock state.
Answer: A cycle.
b. Allow deadlocks, but devise schemes to recover from them.
7.13 What does a cycle in a wait-for graph indicate?
c. Pretend deadlocks dont happen.
Answer: A deadlock.
7.7 Consider a traffic deadlock situation
7.14 Consider a system consisting of four resources of the same
a. Show that the four necessary conditions for deadlock indeed
type that are shared by three processes, each of which needs at
hold in this example.
most two resources. Show that the system is deadlock-free.
b. State a simple rule that will avoid deadlocks in this system.
Answer: Suppose the system is deadlocked. This implies that
Answer: each process is holding one resource and is waiting for one
a. Each section of the street is considered a resource. more. Since there are three processes and four resources, one
Mutual-exclusion only one vehicle on a section of the street. process must be able to obtain two resources. This process
requires no more resources and therefore it will return its
Hold-and-wait each vehicle is occupying a section of the
resources when done.
street and is waiting to move to the next section.
7.16 What is starvation?
No-preemption a section of a street that is occupied by a
vehicle cannot be taken away from the vehicle unless the car Answer: System is not deadlocked, but at least one process is
moves to the next section. indefinitely postponed..
Circular-wait each vehicle is waiting for the next vehicle in 7.17 List three options for breaking an existing deadlock.
front of it to move. Answer
b. Allow a vehicle to cross an intersection only if it is assured that a. Violate mutual exclusion, risking data.
the vehicle will not have to stop at the intersection.
b. Abort a process.
7.8 List the data structures needed for the bankers algorithm.
c. Preempt resources of some process.
Answer:
available vector Available(m)
demand matrix Max(n,m)
115
7.18 What three issues must be considered in the case of
OPERATING SYSTEMS
preemption?
Answer:
a. Select a victim to be preempted.
b. Determine how far back to rollback the victim.
c. Determine means for preventing that process from being
starved.
116
LESSON-30 UNIT-5
OPERATING SYSTEMS
Objectives
Today I will be covering basic concepts related to files , basic file 1.2 File Structure:
structures ,various file operations File can be structured in any of several ways. Three common
Introduction possibilities are depicted (a) is an unstructured sequence of bytes
Whatever the objectives of the applications, it involves the (b) record sequence (c) tree structure.
generation and use of information. As you know the input of a) Unstructured sequence of bytes: It provide the maximum
the application is by means of a file, and in virtually all applications, flexibility. User programs can put anything they want in their
output is saved in a file for long-term storage. files and name them any way that is convenient.
You should be aware of the objectives such as accessing of files, b) Record sequence: In this model, a file is a sequence of fixed
saving the information and maintaining the integrity of the length records each with some internal structure. Central idea
contents, virtually all computer systems provide file management of a file being a sequence of records is the idea that the read
services. Hence a file management system needs special services operation returns and the write operation overwrites or appends
from the operating system. one record.
1. Files: c) Tree structure: In this organization, a file consists of a tree of
The following are the commonly discussed with respect to files: records, not necessarily all the same length, each containing a
key field in a fixed position in the record. The tree is sorted on
Field: Basic element of data. Its length and data type
the key field, to allow rapid searching for a particular key.
characterizes it. They can be of fixed or variable length.
Record: Collection of related fields. Depending on the design, Let us discuss File System components
records may be of fixed or variable length. Ex: In sequential file Device Drivers:
organization the records are of fixed length where as in Line Communicates directly with peripherals devices (disks,
sequential file organization the records are of variable length. tapes, etc)
File: Collection of similar records and is referenced by name. Responsible for starting physical I/O operations on the
They have unique file names. Restrictions on access control device
usually apply at the file level. But in some systems, such controls Processes the completion of an I/O request
are enforced at the record or even at the field level also.
Schedule access to the device in order to optimize
Database: Collection of related data. The essential aspects of a performance
database are that the relationships that exists among elements
Basic File System:
of data. The database itself consists of one or more types of
files. Uses the specific device driver
Files are managed by the operating system. How they are structured, Deals with blocks of data that are exchanged with the
named, accessed, used, protected and implemented are the major physical Device
issues in operating system design. As a whole, the part of the Concerned with the placement of blocks on the disk
operating system deals with files is known as the file system. The Concerned with buffering blocks in main memory
linked lists and bitmaps are used to keep track of free storage and
how many sectors there are in a logical block are important to the
designers of the file system. Logical File System:
Responsible for providing the previously discussed
1.1 File Naming:
Files are an abstraction mechanism. The main characteristic feature interface to the user including:
of abstraction mechanism is the way the objects being managed File access
are name. The exact rules for the file naming vary from system to Directory operations
system, but all current operating system allows strings of one to Security and protection.
eight letters as legal file names. Many file systems support names
as long as 255 characters with a distinguish in upper and lower 1.3 File Types:
case. Many operating systems support two-part file names, with Many operating systems support several types of files. Unix and
the two parts separated by a period. The first part is called primary Windows, have regular files and directories. Regular files are the
file name and the second part is called secondary or extension file ones that contain user information generally in ASCII form.
name. Directories are system files for maintaining the structure of the file
system. Character special files are related to input/output and
117
used to model serial I/O devices such as terminals, printers and
OPERATING SYSTEMS
1.6.6 Write:
networks. Block special files are used to model disks. Data are written to the file, again, usually at the current position.
1.4 File Access: If the current position is end of the file then the file size gets
Early operating systems provided only one kind of file access: increased.
sequential access. In these system, a process could read all the bytes 7.7.7 Append:
or records in a file in order, starting at the beginning, but could This call is a restricted from of write. It can only add data to the
not skip around and read them our of order. Sequential files were end of the file.
convenient when the storage medium was magnetic tape, rather 1.6.8 Seek:
than disk. Files whose bytes or records can be read in any order are
For random access files, a method is needed to specify from where
called random access files. Two methods are used form specifying
to take the data.
where to start reading. In the first one, every read operation gives
the position in the file to start reading at. In the second one, a 1.6.9 Get attributes:
special operation, seek, is provided to set the current position. Processes often need to read file attributes to do their work.
This allows the system to use different storage techniques for the
1.6.10 Set attributes:
two classes. Where as in modern operating systems all the files are
Some of the attributes are user settable and can be changed after
automatically random access.
the file has been created. This system call makes that possible. The
1.5 File Attributes: protection mode information is an obvious example.
Every file has a name and its data. In addition all operating systems
11.11.11Rename:
associate other information with each file such as the date and
It frequently happens that a user needs to change the name of an
time the file was created and the files size. The list of attributes
existing file.
varies considerably from system to system. Attributes such as
protection, password, creator and owner tell who may access it Review Exercise:
and who may not. The flags are bits or short fields that control or 2. What is the importance of a filename having two parts?
enable some specific property. The record length, key, position ________________________________________________________________________
and key length fields are only present in files whose records can be
looked up using a key. The various times keep track of when the ________________________________________________________________________
file was created, most recently accessed and most recently modified. ________________________________________________________________________
These are useful for a variety of purpose. The current size tells ________________________________________________________________________
how big the file is at present. ________________________________________________________________________
1.6 File operations:
Files exist to store information and allow it to be retrieved later. 3. What are the rules that govern for naming a file?
Different systems provide different operations to allow storage
and retrieval. The few of them of the most common system calls ________________________________________________________________________
relating to files are: ________________________________________________________________________
1.6.1 Create: ________________________________________________________________________
The file is created with no data. The purpose of the call is to ________________________________________________________________________
announce that the file is coming and to set some of the attributes. ________________________________________________________________________
1.6.2 Delete:
When the file is no longer needed, it has to be deleted to free up 4. Discuss to make the file system more useful.
disk space.
________________________________________________________________________
1.6.3 Open: ________________________________________________________________________
Before using a file, a process must open, the purpose of the open
________________________________________________________________________
call is to allow the system to fetch the attributes and list of disk
addresses into main memory for rapid access on later calls. ________________________________________________________________________
________________________________________________________________________
1.6.4 Close:
When all the accesses are finished, the attributes and disk addresses
are no longer needed, so the file should be closed to free up 5. What are the components that constitute the file system?
internal table space. ________________________________________________________________________
1.6.5 Read: ________________________________________________________________________
Data re read from file. Usually, the bytes a come from the current
________________________________________________________________________
position. The caller must specify how much data are needed and
must also provide a buffer to put them in. ________________________________________________________________________
________________________________________________________________________
118
6. What are the various file attributes that are applicable for different Publisher Reading, Mass. : Addison-Wesley, C1997.
OPERATING SYSTEMS
types of files. Explain?
________________________________________________________________________ Author Silberschatz, Abraham.
________________________________________________________________________ Main Title Operating System Concepts / Abraham Silberschatz,
________________________________________________________________________ Peter Baer Galvin.
________________________________________________________________________ Edition 6th Ed.
________________________________________________________________________ Publisher Reading, Mass. : Addison Wesley Longman, C1998.
Reference Books: Notes
Author Dahmke, Mark.
Main Title Microcomputer Operating Systems / Mark Dahmke.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
119
LESSON-31
OPERATING SYSTEMS
Objectives To avoid conflicts caused by different users choosing the same file
In this lecture I will be covering all the points given below. name for their own files, the next step up is giving each user a
private directory. In that way, names chosen by one user do not
Concept of directories
interfere with names chosen by a different user and there is no
Their organization & structure problem caused by the same name occurring in two or more
And various operations on directories directories. This design used on multi-user computer or on a
Directory Implementations simple network of personal computers that shared a common
file server over a local area network. This level structure uses login
Directories
procedure, which restricts the unauthorized user access.
You should know that the operating system keeps the track of
files, file systems normally have directories or folders, which, in These are the Important aspects of Two-Level Directory
many systems are themselves, are files. One master file directory.
Directory Organization Each user has their own user file directory.
Goals: Each entry in the master file directory points to a user file
directory.
Efficiency: quickly locating the file.
Issues:
Convenience: naming files in a convenient way to users.
Sharing - accessing other users files.
Grouping: allowing users to group files based on users
classifications. System files.
Organization of the file system Grouping problem.
Virtual disks (called volumes, or minidisks, or partitions).
May span a physical disk, part of a physical disk, or several
disks.
Virtual disk directory.
Directory Structure
Single-Level Directory System:
The simplest form of directory system is having one directory
containing all the files, which is called the root directory. It is
commonly used on personal computers, which is used by only
one user. But the problem arises when multiple users create their
directories, where the name of the directory may coincide resulting
to problem. Hierarchical Directory Systems:
Important aspects of Single Level Directory The two-level hierarchy eliminates name conflicts among users
All files are contained in the same directory. but is not satisfactory for users with a large number of files. In
Easy to support and understand. this approach, each user can have as many directories as are needed
so that files can be grouped together in natural ways. The ability
Have significant limitations in terms of: for users to create an arbitrary number of subdirectories provides
Large number of files (naming). a powerful structuring tool for users to organize their work.
Ability to support different users / topics (grouping). Tree-Structured Directory
The directory structure is a tree with arbitrary height.
Users may create their own subdirectories.
Issues
Efficient Searching, grouping.
Current directory notion / change directory (absolute/
relative naming).
Directory semantics (e.g. deletion).
Two-Level Directory Systems:
120
OPERATING SYSTEMS
Acyclic-Graph Directory
General-Graph Directory
Allow sharing of directories and files several times on the tree
structure. A problem with acyclic graphs - how to ensure that there
Issues are no cycles.
Only one actual copy of the file or directory is stored. Can happen only when linking a directory.
Can be accessed through one or more paths. Every time a link is added to a directory - use a cycle
detection algorithm...
May have different names.
General graph directories allow cycles.
There are several ways to implement shared files and directories.
Issues:
Example - Unix:
How to avoid traversing a component in a cycle while searching.
Symbolic links:
A different type of a directory entry (other than a file or a
directory).
Specifies the name of the file that this link is pointing to.
Can be relative or absolute.
What happens when one deletes the original file?
Duplicate directory entries (also called hard links):
The original and copy entries are the same.
What happens when one deletes the original or copy
entries?
121
Create: A directory is created. It is empty except for dot and Review Exercise:
OPERATING SYSTEMS
dotdot which are put there automatically be the system. 1. What are the similarities and dissimilarities between files and
Delete: directories?
Only an empty except directory can be deleted. ________________________________________________________________________
Opendir: ________________________________________________________________________
To list all the files in a directory, a listing program opens the ________________________________________________________________________
directory to read out the names of all the files it contains. Before a
________________________________________________________________________
directory can be read, it must be opened, analogous to opening
and reading a file. ________________________________________________________________________
Closedir:
When a directory has been read, it should be closed to free up 2. What is the advantage of directories over files?
internal table space. ________________________________________________________________________
Readdir: ________________________________________________________________________
This call returns the next entry in an open directory. It always ________________________________________________________________________
returns one entry in a standard format, no matter which of the ________________________________________________________________________
possible directory structures is being used.
________________________________________________________________________
Rename:
They can be renamed the same way file can be.
3. Describe the directory structure?
Link:
________________________________________________________________________
Linking a technique that allows a file to appear in more than one
directory. This system call specifies an existing file and a path name, ________________________________________________________________________
and creates a link from the existing file to the name specified by the ________________________________________________________________________
path. ________________________________________________________________________
Unlink: ________________________________________________________________________
A directory entry is removed. If the file being unlinked is only
present in one directory, it is removed from the file system. If it is
4. Explain various operations on a directory?
present in multiple directories, only the path name specified is
removed. ________________________________________________________________________
________________________________________________________________________
Directory Implementations
We can implement the directory in several ways. ________________________________________________________________________
Linear List ________________________________________________________________________
The simplest approach to implementing a directory is simply ________________________________________________________________________
maintaining a list (or array) of file names (and other info). Reference Books:
This approach has some problems like: searching for a file means Author Dahmke, Mark.
we must do a linear search, and inserting and deleting from a fixed
Main Title Microcomputer Operating Systems / Mark Dahmke.
list is not simple.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982.
We can also maintain a sorted list, but that would mean maintaining
the sorted structure.
Author Deitel, Harvey M., 1945-
Hash Table
We can also implement the directory as a hash table. This could be Main TitleAn Introduction To Operating Systems / Harvey M.
in addition to the linear list. A hash table allows us to quickly find Deitel.
any individual file. Edition Rev. 1st Ed.
Hash tables arent the perfect solution either. One problem is Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
hash clashes. These must be resolved, and ways to resolve them
arent exactly better than maintaining a linear list.
Author Lister, A. (Andrew), 1945-
Let me brief you the description of Directory Operations:
Main Title Fundamentals Of Operating Systems / A.M. Lister.
Create a file.
Edition 3rd Ed.
Delete a file.
Publisher London : Macmillan, 1984.
Search for a file.
List a directory.
Author Gray, N. A. B. (Neil A. B.)
Rename a file.
Main Title Introduction To Computer Systems / N.A.B. Gray.
Traverse the file system.
122
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
OPERATING SYSTEMS
1987.
Notes
123
SELF-ASSESSMENT INTERACTIVE TOPIC
OPERATING SYSTEMS
124
10.23 What is an acyclic graph? 10.33 List four ways systems might provide for users to protect
OPERATING SYSTEMS
Answer: A tree that has been corrupted by links to other branches, their files against other users.
but does not have any cyclic paths in it. Answer:
10.24 List ways to share files between directories in operating a. Allowing user to use unprintable characters in naming files so
systems. other users cant determine the complete name.
Answer: b. Assigning password(s) to each file that must be given before
a. Copy file from one account into another. access is allowed.
b. Link directory entry of copied file to directory entry of original c. Assigning an access list, listing everyone who is allowed to use
file. each file.
c. Copy directory entry of file into account file is copied into. d. Assigning protection codes to each file, classifying users as
system, owner, group, and world (everyone else)..
10.25 What problems might arise on deletion if a file is shared?
Answer: Copier of file might delete the original shared file, Self-assessment interactive topic
depriving rest of users. They have a pointer to a deleted directory 11.1 List three ways of allocating storage, and give advantages of
entry pointing to the original file or one overwritten by other each.
users of the system, or a new entry pointing to a new file Answer:
created by the original user.
a. Contiguous allocation. Fastest, if no changes are to be made.
10.26 How can we solve this problem? Also easiest for random-access files.
Answer: Keep a count of the number of links to a file in original b. Linked allocation. No external fragmentation. File can grow
directory. As each person deletes a file, the count decreases by 1. without complications.
10.27 What is a general graph? c. Indexed allocation. Supports direct access without external
Answer: A tree structure where links can go from one branch to a fragmentation.
node earlier in the same branch or other branch, allowing cycles. 11.2 What is contiguous allocation?
10.28 What problems arise if the directory structure is a general Answer: Allocation of a group of consecutive sectors for a single
graph? file.
Answer: Searching for a particular file may result in searching the 11.3 What main difficulty occurs with contiguous allocation?
same directory many times. Deletion of the file may result in
Answer: Finding space for a new file.
the reference count to be nonzero even when no directories
point to that file. 11.4 What is a hole in contiguous allocation method?
10.29 What is garbage collection? Answer: An unallocated segment of blocks.
Answer: Determining what file space is available, and making it 11.5 Explain first-fit, best-fit, and worst-fit methods of allocating
available for users. space for contiguous files.
125
11.9 What is linked allocation, as detailed in text? e. Hash tables are set up for a maximum number of files; also
OPERATING SYSTEMS
Answer: Directory contains pointers to first and last blocks of there is a problem with collisions.
file. Each block of file (except last) has pointer to the next 11.17 Give advantages of each directory structure above.
block. Answer:
11.10 Can linked allocation have external fragmentation? Internal Linear list Simple to program search.
fragmentation?
Linked list Easier to process deletes.
Answer: External - no. Internal - Yes.
Sorted list Fast access.
11.11 Can linked allocation be used for direct-access files?
Linked binary tree Faster access.
Answer: Not in the form suggested in the book. RSTS on the
Hash table Fastest access...
PDP-11 stores the sector numbers in the directory, with each
group of seven addresses linked to the next group of seven. Notes
Direct access using this modified linked allocation is possible.
(This approach is really a hybrid of linked and indexed
allocations.)
11.12 What is indexed allocation?
Answer: Each file has its own block of pointers to the sectors of
the file.
11.13 Rank the allocation methods on speed.
Answer: Contiguous is fastest. Linked is slower, because the disk
head may have to move between accesses of file. Indexed is
slowest, unless the entire index can be kept in memory at all
times. If not, then extra time must be used to access next block
of file indexes.
11.14 List four ways a system could use to determine which sectors
are free. Give advantages of each way.
Answer:
a. Free-space list. Each section indicates a sector that is available.
Not encumbered by a used-sector list.
b. Bit vector is a compact version. Has no links that can be broken.
c. Link all free sectors together in an available list. Takes no usable
space. But links could break.
d. List giving start of each block of free sectors, and a count of
number of sectors in this block. This is fast for use in
contiguous storage search.
11.15 What data structures can be used for directory information?
Answer:
a. Linear list
b. Linked list
c. Sorted list
d. Linked binary tree
e. Hash table
11.16 What problems might arise with above data structures?
Answer:
a. Linear list is slow to access particular file. Also must decide how
to take care of deletions (mark, copy last entry to it, ...).
b. Linked list requires storage overhead for pointers; also, if link
goes bad, rest of files are lost.
c. Sorted list requires list always to be sorted, which means extra
work on creating and deleting files.
d. Binary tree suffers like linked list.
126
OPERATING SYSTEMS GLOSSARY
OPERATING SYSTEMS
ANSI as 486, Pentium or Pentium II. Other CPUs exist, like Digitals
American National Standardisation Institute Alpha, Suns UltraSPARC, Mips, Hewlett-Packard.
ASCII DASD
American Standard Code for Information Interchange - a table Direct Access Storage Device
converting nummeric values into human readable characters. DBCS
API Dual Byte Character Set - an expansion of ASCII to support
Application Programming Interface - the set of routines/functions foregin languages better. Special char values are reserved and results
made available to a program developer. in the char size increasing to two bytes (eg. 4Ah is normal one byte
where F8h,B3h is a double byte character). A very efficient method
ATA
to store all possible characters in limited memory space.
AT Attachment - also known as IDE.
Disk
ATAPI
A circular storage media, on which data can be recorded, usually in
ATA Packet Interface - minor extension to IDE to control
sectors. Often magnetically or optically coded.
additional device types.
DLL
BASIC
Dynamic Link Libary - a set of routines stored in a file. Addresses
Beginners All-purpose Symbolic Instruction Code - a high-level
to the routines are determined by the OS on load or at run-time.
interpreted programming language which is very easy to learn.
DOS
Binary
Disk Operating System - a simple single user single tasking OS
A base-2 system written as either 1b or 1 2, unlike our normal base-
bought by Bill Gates as QDOS and used on the first IBM PCs. A
10. Each place is multiplied with 2 as you move left: 00000001b =
clone, DR-DOS is available.
1*20 = 1, 00000010b = 1*21+0*20, 00000011b = 1*21+1*20 ,
00000100b = 1*22+0*21+0*20 = 4, etc. DOS 8.3
Refers to the naming convention on DOSs FATFS volumes, where
Bit
a filename had to be 1-8 chars long and have an extension of 0-3
Binary Digit - the smallets possible piece of information: set or
chars, seperated by a period.
cleared, 1 or 0, true or false.
EMS
Byte
Expanded Memory Specification - a system to access additional
A group of 8 bits making up a base-2 number.
memory in DOS. It is specified in the so-called LIM (Lotus-Intel-
CD-ROM Microsoft) EMS specification. It uses 16K pages which can be
Compact Disc Read Only Memory - Optical storage media with a swapped in and out of real-mode addressing space.
capacity of 74 minutes of digital music or 650-740 MB of read
GID
only storage. Serveral different formats exists, known by their
Group ID - a number or a string that represents the group to
book-color (red book, yellow book etc.).
which a user belongs uniquely within the OS.
CDi
GPF
CD Interactive - Philips extended CD-ROM architecture for video
General Protection Fault - a process violated its assigned resources
storage.
and tried to access a resource which it was not granted (often
Char unavailable memory due to pointer errors).
Character - usually a 1 byte data size representing one character to
GUI
the user. In the case of Unicode of DBCS a char may take up two
Graphical User Interface - a representation using squares (windows)
bytes of memory.
to represent a programs output. Uses buttons and icons to
CP/M implement a more user-friendly interface with the computer.
Control Program for Microcomputers - A simple single tasking Today, most OS are delivered with a GUI. The GUI was developed
single user OS used on home PC in the late 1970s. Claimed to be at RankXerox PARC, introduced to the public with Apple
the blueprint for QDOS. Macintosh and made common by MS Windows 3.0.
CPU Handle
Central Processing Unit - the chip that executes a stream of Usually a number used by the operating system to identify an
instructions, like add 2 and 4, read from memory, etc. It control object, like an open file or a window.
everything in your computer. Often supplied by Intel and known
127
Hex Refers to the Intel 80286 Protected Mode architecture. The least
Hexadecimal notation - a base-16 number system, where a=10, restricted level with access to all system resources. Should only be
b=11, c=12, d=13, e=14, f=15. Written as 00h, $00 or 0016. Eg. used by the OS and its drivers.
10h = 16, 2Fh=47 (2*16+15), 123h=291 (1*162+2*16+3).
Ring 3
HMA Refers to the Intel 80286 Protected Mode architecture. The most
High Memory Area - a 64 KB block of memory accessible by the restricted level of protection. Should be used by all user
i80286 and later above 1 MB when running in real mode. applications.
OPERATING SYSTEMS
IDE SCSI
Integrated Drive Electronics - a system for connecting harddisks Small Computer Systems Interface - a general bus for connecting
to your computer. Used in PC. Supports upto 2 units. Replaced additional devices to a computer. Modified and exists in serveral
by EIDE. variations today, known as SCSI-2, SCSI-3, Ultra-SCSI 1+2, Fast
SCSI 1+2, Wide SCSI and serveral other combinations. Basic SCSI
ISO
uses a 8-bit parallel bus running at 5 MHz giving it a transfer rate
International Standard Organization
of 5MB/s.
ISO 9660
Sector
A specification for a filesystem on the CD-ROM.
Smallets unit data storage on a disk. Often blocks with a size of
Kb 512, 1024, 2048 or 4096 bytes (CD-ROM can use 2352).
Kilobit - 1024 bit (210) - 128 bytes (27). Storage Media
KB A media capable of storing data permanently. Often the shape of
Kilobyte - 1024 bytes (210). a disc or as a tape.
LFN Thread
Long File Name - a filename that is longer than the DOS 8.3 A thread of execution is the series of machine instructions that
specification. the CPU executes.
Mb UID
Megabit - 1048576 bit (2 ) = 131072 bytes (2 ).
17 17 User ID - a number or a string that represents the user uniquely
within the OS.
MB
Megabyte - 1048576 bytes (220). UMB
Upper Memory Block - in DOS 5 or later, unused blocks of
OS memory in the 640 KB - 1 MB memory range can be used to store
Operating System(s) - I honestly do not care to write operating device drivers.
system each time since it occurs quite often in these texts ;).
Unicode
Paging A newer way of supporting all foregin languages special characters.
The process of realizing virtual memory in physical memory by Used instead of DBCS. Uses two bytes to represent one character,
moving blocks of physical memory to and from a slower storage supports upto 65536 different characters. Used primarily in WinNT
media (usually a disk). and Win95/98.
Partition V86 Mode
Sub-division of a disk into smaller logical disks. Refers to the Intel 80386 Protected Mode architecture. A mode
PhotoCD where the CPU emulates the 8086 real mode addressing but
maintains support for paging and certain access restrictions. Often
Kodak format for storage of images on CD-ROM
used by OSs to implement virtual DOS machines and can be
Process used to implement a EMS memory manager (like QEMM386 or
A collection of threads that share resources. EMM386).
Protected Mode Virtual Memory
Refers to the Intel 80286 Protected Mode architecture. When the A CPU-addressible memory area, which does not exist in real
CPU runs in this mode, it supports virtual memory, memory memory, but is created on a slower storage media. The process of
access restrictions and task-switching in hardware. This is the swapping virtual memory in and out of real memory is called
prefered mode for all new operating system and the only mode paging.
where you can access memory above 1 MB.
Volume
Real Mode An area of a disk containing a filesystem of some kind.
Refers to the Intel 80286 Protected Mode architecture. The mode
XMS
in which the 8086 ran. It supports upto 1 MB of address space
eXtended Memory Specification - a system to access additional
and has no access restrictions whatsoever.
memory in DOS. It uses a copying mechanism to copy to/from
Ring 0 conventional memory to/from extended memory.
128
REFERENCE BOOKS:
OPERATING SYSTEMS
Author Dahmke, Mark. Main Title Operating System Concepts / Abraham Silberschatz,
Main Title Microcomputer Operating Systems / Mark Dahmke. Peter Baer Galvin.
Publisher Peterborough, N.H : Mcgraw-Hill/Byte Books, C1982. Edition 6th Ed.
Publisher Reading, Mass. : Addison Wesley Longman, C1998.
Author Deitel, Harvey M., 1945-
Main Title An Introduction To Operating Systems / Harvey M. Useful Web Sites
Deitel.
http://www.d.umn.edu/~tpederse/Courses/CS3221-
Edition Rev. 1st Ed.
SPR04/class.html
Publisher Reading, Mass : Addison-Wesley Pub. Co., C1984.
http://www.cse.msu.edu/~cse410/
http://cs.wisc.edu_~solomon_cs537_notes.html/
Author Lister, A. (Andrew), 1945- ~solomon_cs537_intro.html
Main Title Fundamentals Of Operating Systems / A.M. Lister. http:
Edition 3rd Ed. ww2.cs.uregina.ca_~hamilton_courses_330_notes_index.ht
Publisher London : Macmillan, 1984. ~hamilton_courses_330_notes_index.html
http://cs.nyu.edu_~gottlieb_courses_2000-01-
Author Gray, N. A. B. (Neil A. B.) spring_os_lectures/~gottlieb_courses_2000-01-
spring_os_lectures_lectures.html
Main Title Introduction To Computer Systems / N.A.B. Gray.
http://cs.gordon.edu_courses_cs322_lectures_index.html/
Publisher Englewood Cliffs, New Jersey ; Sydney : Prentice-Hall,
courses_cs322_lectures_index.html
1987.
129
The lesson content has been compiled from various sources in public domain including but not limited to the
internet for the convenience of the users. The university has no proprietary right on the same.