[go: up one dir, main page]

0% found this document useful (0 votes)
12 views200 pages

Operating System

The document outlines the syllabus for the M.Sc. (Information Technology) program at Bharathidasan University, focusing on Operating Systems. It includes details about the course structure, modules covering various aspects of operating systems such as process management, storage management, file system interface, and device management. Additionally, it lists the contributors, copyright information, and the educational approach of the material presented.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views200 pages

Operating System

The document outlines the syllabus for the M.Sc. (Information Technology) program at Bharathidasan University, focusing on Operating Systems. It includes details about the course structure, modules covering various aspects of operating systems such as process management, storage management, file system interface, and device management. Additionally, it lists the contributors, copyright information, and the educational approach of the material presented.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 200

OPERATING SYSTEM

M.Sc. (Information Technology)

Bharathidasan University
Centre for Distance and Online Education
Chairman:
Dr. M. Selvam
Vice-Chancellor
Bharathidasan University
Tiruchirappalli-620 024
Tamil Nadu
Co-Chairman:
Dr. G. Gopinath
Registrar
Bharathidasan University
Tiruchirappalli-620 024
Tamil Nadu
Course Co-Ordinator:
Dr. A. Edward William Benjamin
Director-Centre for Distance and Online Education
Bharathidasan University
Tiruchirappalli-620 024
Tamil Nadu
The Syllabus is Revised from 2021-22 onwards

Reviewer
Ms. N. Vijayalakshmi, Asst. Professor, Dept. of Computer Application Sirmashi India Gandhi College, Trichy

Authors
VK Govindan, Professor, Computer Engineering, Department of Computer Science and Engineering, NIT, Calicut
(Units: 1.0-1.4, 1.8-1.12, 2.0-2.2, 2.4, 2.5, 2.8-2.12, 4.0-4.2, 4.3, 4.6-4.10, 5.0-5.2, 5.6-5.11)
Vikas Singhal, Senior Lecturer, JSS Academy of Technical Education, Noida
(Units: 1.5, 2.3, 2.4.1, 2.6-2.7)
D Anil Kumar, Asstt Professor, Matrusri Institute of Post Graduate Studies
(Units: 2.3.1-2.3.2, 3.2.2, 4.2.1, 4.4-4.5, 5.4)
Dr Deepti Mehrotra, Director, Amity School of Computer Science, Noida
(Units: 3.0-3.2.1, 3.2.3-3.11)
Vikas® Publishing House, (Units: 1.6-1.7, 4.5.1-4.5.3, 5.3, 5.5)

"The copyright shall be vested with Bharathidasan University"


All rights reserved. No part of this publication which is material protected by this copyright notice
may be reproduced or transmitted or utilized or stored in any form or by any means now known or
hereinafter invented, electronic, digital or mechanical, including photocopying, scanning, recording
or by any information storage or retrieval system, without prior written permission from the Publisher.

Information contained in this book has been published by VIKAS® Publishing House Pvt. Ltd. and has
been obtained by its Authors from sources believed to be reliable and are correct to the best of their
knowledge. However, the Publisher, its Authors shall in no event be liable for any errors, omissions
or damages arising out of use of this information and specifically disclaim any implied warranties or
merchantability or fitness for any particular use.

Vikas® is the registered trademark of Vikas® Publishing House Pvt. Ltd.


VIKAS® PUBLISHING HOUSE PVT
LTDE-28, Sector-8, Noida - 201301
(UP)
Phone: 0120-4078900 • Fax: 0120-4078999
Regd. Office: A-27, 2nd Floor, Mohan Co-operative Industrial Estate, New Delhi 1100 44
Website: www.vikaspublishing.com • Email: helpline@vikaspublishing.com

SYLLABI-BOOK MAPPING TABLE
Operating System
Syllabi Mapping in Book

Module 1
Definition: Functions, OS as Resource Manager, Types, Structure, Unit 1: Introduction to
Concept of Batch Processing, Multi-programming, Multi-user Operating Systems
Systems and Real-Time System, POST, Bootstrapping, Kernel. (Pages: 3-32)

Module 2
Process Management: Process concept, Process scheduling, Unit 2: Process Management
Operations on processes, Cooperating processes, Interprocess and Operation
communication, Communication in client server systems, Threads, (Pages: 33-83)
Overview, Multithreading models, CPU scheduling, Scheduling
criteria, CPU scheduling algorithms, Process synchronization,
Critical-section problem-Semaphores, Deadlocks, Prevention,
Avoidance and Detection.

Module 3
Storage Management: Memory management, Contiguous Unit 3: Storage Management
memory allocation, Paging, Segmentation, Segmentation with Paging, (Pages: 85-117)
Virtual memory, Demand paging, Page replacement, Allocation of
Frames, Thrashing.

Module 4
File-System Interface: File concept, Access methods, Directory Unit 4: File System Interface
structure, File system structure, File system implementation, (Pages: 119-148)
Allocation methods, Free space management, File protection and
Security, Protection concepts, Security problem, User authentication,
Program threats, System threats.

Module 5
Device Management: Types of devices, Dedicated, Shared-device Unit 5: Device Management
scheduling and Virtual devices-SPOOLing, Concept of device (Pages: 149-191)
drivers.
CONTENTS
INTRODUCTION 1-2
UNIT 1 INTRODUCTION TO OPERATING SYSTEMS 3-32
1.0 Introduction
1.1 Unit Objectives
1.2 Functions and Definition of Operating System
1.3 Operating System as a Resource Manager
1.4 Types of Operating Systems
1.5 Structure of an Operating System
1.5.1 Virtual Machine Concept
1.5.2 Kernel Approach
1.5.3 Central Processing Unit and Input/Output Structure
1.6 POST and Bootstrapping
1.7 Kernel
1.8 Summary
1.9 Key Terms
1.10 Answers to ‘Check Your Progress’
1.11 Questions and Exercises
1.12 Further Reading
1.13 Learning Outcomes

UNIT 2 PROCESS MANAGEMENT AND OPERATION 33-83


2.0 Introduction
2.1 Unit Objectives
2.2 Process Management
2.2.1 Process Concept
2.2.2 Multithreading Models
2.3 Process Scheduling
2.3.1 Operations on Processes
2.3.2 Concurrent Processes
2.4 Interprocess Communication
2.4.1 Communication in Client-Server Systems
2.5 CPU Scheduling
2.6 Process Synchronization
2.6.1 Critical Section
2.6.2 Semaphores
2.7 Deadlocks
2.7.1 Deadlock Prevention
2.7.2 Deadlock Avoidance
2.7.3 Deadlock Detection
2.8 Summary
2.9 Key Terms
2.10 Answers to ‘Check Your Progress’
2.11 Questions and Exercises
2.12 Further Reading
2.13 Learning Outcomes

UNIT 3 STORAGE MANAGEMENT 85-117


3.0 Introduction
3.1 Unit Objectives
3.2 Memory Management
3.2.1 Address Binding
3.2.2 Contiguous Allocation
3.2.3 Dynamic Loading and Linking
3.2.4 Overlay
3.3 Paging
3.3.1 Paging Process
3.3.2 Hardware Support for Paging
3.4 Segmentation
3.4.1 Segmentation with Paging
3.5 Virtual Memory
3.5.1 Demand Paging
3.6 Page Replacement
3.6.1 Thrashing
3.6.2 Allocation of Frame
3.7 Summary
3.8 Key Terms
3.9 Answers to ‘Check Your Progress’
3.10 Questions and Exercises
3.11 Further Reading
3.12 Learning Outcomes

UNIT 4 FILE SYSTEM INTERFACE 119-148


4.0 Introduction
4.1 Unit Objectives
4.2 Concept of a File
4.2.1 File System Structure and Implementation
4.3 File Systems Organization
4.3.1 Techniques of File Organization
4.3.2 File Attributes
4.3.3 Directory Structures
4.3.4 Operations on Directory
4.3.5 File Protection
4.3.6 Secondary Storage Management
4.4 Protection Concepts
4.5 Security Problem
4.5.1 User Authentication
4.5.2 Program Threats
4.5.3 System Threats
4.6 Summary
4.7 Key Terms
4.8 Answers to ‘Check Your Progress’
4.9 Questions and Exercises
4.10 Further Reading
4.11 Learning Outcomes

UNIT 5 DEVICE MANAGEMENT 149-191


5.0 Introduction
5.1 Unit Objectives
5.2 Input/Output Devices
5.2.1 Input Devices
5.2.2 Output Devices
5.2.3 Storage Devices
5.2.4 Optical Drives
5.3 Dedicated and Shared Devices
5.3.1 Virtual Devices
5.4 Disk Management and Scheduling
5.4.1 Disk Structure
5.4.2 Disk Scheduling
5.5 SPOOLing
5.6 I/O Systems and Device Drivers
5.7 Summary
5.8 Key Terms
5.9 Answers to ‘Check Your Progress’
5.10 Questions and Exercises
5.11 Further Reading
5.12 Learning Outcomes
Introduction
INTRODUCTION
An operating system is an essential part of any computer system. It is the software that
acts as an interface between the user and the computer. The main purpose of an operating NOTES
system is to provide an environment in which a user can execute programs in a convenient
and efficient manner. An operating system is also responsible for managing the hardware
and software resources of a system such as processor, memory and disk space. It
consists of programs and data that runs on computers, manages computer hardware
resources and provides common services for efficient execution of various application
software. For hardware functions, such as input, output and memory allocation, the
operating system acts as an intermediary between application programs and the computer
hardware. Operating systems are found on almost any device that contains a computer—
from cellular phones and video game consoles to supercomputers and web servers.
Examples of popular modern operating systems for personal computers are Microsoft
Windows, Mac OS X, UNIX and GNU/Linux. Hence, every general purpose computer
must have an operating system to run other programs. An operating system performs
basic tasks, such as recognizing input from the keyboard, sending output to the display
screen, keeping track of files and directories on the disk and controlling peripheral devices
such as disk drives and printers. For large systems, the operating system has even
greater responsibilities and powers. It makes sure that different programs and users
running at the same time do not interfere with each other. The operating system is also
responsible for security, ensuring that unauthorized users do not access the system.
Operating systems can be classified as single user and multi-user. A multi-user
operating system allows multiple users to access a computer system concurrently while
the single user operating systems are usable by a single user at a time. Time sharing
system is classified as multi-user system as they facilitate multiple user access to a
computer through the sharing of time. Some operating systems allow multiprocessing
(supports running a program on more than one CPU), multitasking (allows more than
one program to run concurrently), multithreading (allows different parts of a single program
to run concurrently) and real time (responds to input instantly). An operating system
consists of many parts. One of the most important components is the kernel, which
controls low-level processes that are not visible to the average users. It controls how
memory is read and written, the order in which processes are executed, how information
is received and sent by various input and output devices, and decides how to interpret
information received from networks.
Memory protection enables the kernel to limit a process’ access to the computer’s
memory. Various methods of memory protection exist, including memory segmentation
and paging. The user interface is a component that interacts with the computer user
directly, allowing them to control and use programs. The user interface may be graphical
with icons and a desktop or textual with a command line. Application programming
interfaces provide services and code libraries that let application developers write modular
code reusing well defined programming sequences either in user space libraries or in the
operating system itself. The components of an operating system exist in order to make
the different parts of a computer work together whether it is as simple as a mouse or
keyboard or as complex as an Internet connection.

Self-Instructional
Material 1
Introduction This book, Operating System, is designed to be a comprehensive and easily
accessible book covering the basic concepts of computer systems, operating systems,
hardware and software, and also how to use basic application programs for managing
information on computers. The book has been written in the self-instructional mode or
NOTES the SIM format wherein each Unit begins unit starts with an ‘Introduction’ to the topic
followed by an outline of the ‘Unit Objectives’. The detailed content is then presented in
an organized and comprehensive way interspersed with ‘Check Your Progress’ questions
to test the student’s understanding of the topics covered. A ‘Summary’ along with a list
of ‘Key Terms’ and a set of ‘Questions and Exercises’ is provided at the end of each
unit for effective recapitulation.

Self-Instructional
2 Material
Introduction to Operating

UNIT 1 INTRODUCTION TO Systems

OPERATING SYSTEMS
NOTES
Structure
1.0 Introduction
1.1 Unit Objectives
1.2 Functions and Definition of Operating System
1.3 Operating System as a Resource Manager
1.4 Types of Operating Systems
1.5 Structure of an Operating System
1.5.1 Virtual Machine Concept
1.5.2 Kernel Approach
1.5.3 Central Processing Unit and Input/Output Structure
1.6 POST and Bootstrapping
1.7 Kernel
1.8 Summary
1.9 Key Terms
1.10 Answers to ‘Check Your Progress’
1.11 Questions and Exercises
1.12 Further Reading
1.13 Learning Outcomes

1.0 INTRODUCTION
In this unit, you will learn about the concept of operating system. The operating
systems originally used in mainframes and later in microcomputers, only supported
one program at a time and therefore required a very basic scheduler. You will be
introduced to the role of the OS as a resource manager. An operating system is a
complex software used to control and coordinate the hardware resources, such as a
CPU, memory and input/output devices to enable easy interaction of the computer
with human and other applications. You will also learn the various types of operating
systems, such as batch processing system, multiprogramming system, time shared
system, multitasking system, parallel system, distributed system and real-time
system. A real-time system is the one which responds to real-time events or inputs
within a specified time limit. In the virtual machine multiprogramming system, a
single machine gives an illusion of many virtual machines, each of them having its
own virtual processor and storage space which can be handled through process
scheduling.
You will be introduced about the structure of an operating system in which
you will know about the virtual machine concept, kernel approach, central processing
unit and I/O structure. Power on self test is a diagnostic tool that provides the end
user information about the computer. The motherboard basic input output system
contains POST function. Booting up is a bootstrapping process that starts the
operating system when the user switches on a computer. Kernel is the fundamental
part of an operating system. It is a piece of software used for providing secure
access to the machine’s hardware to various computer programs.

Self-Instructional
Material 3
Introduction to Operating
Systems 1.1 UNIT OBJECTIVES
After going through this unit, you will be able to:
NOTES  Define operating systems
 Understand the functions of operating systems
 Explain the role of operating system as a resource manager
 Describe the various types of operating systems
 Explain the structure of operating system
 Know about POST and bootstrapping processes
 Understand the functions of kernel

1.2 FUNCTIONS AND DEFINITION OF OPERATING


SYSTEM
The first computers did not have operating systems and they simply ran standalone
programs. By the mid 1960s, computer vendors were providing tools for developing,
scheduling and executing jobs in a batch processing mode.
The operating systems originally used in mainframes and later in
microcomputers only supported one program at a time and therefore required a
very basic scheduler. Each program was in complete control of the computer while
it ran. Multitasking or time sharing came to be associated with mainframe computers
in the 1960s. By 1970, minicomputers would be sold with proprietary operating
systems. An Operating System (OS) can be defined as ‘Software responsible for the
direct control and management of hardware and basic system operations’.
Objectives of Operating Systems
Why do we need an OS? Or, what are the objectives of having an OS for a computer?
There are many objectives to be met for achieving the ultimate goal of easy to use
and human friendly operating system that transforms the computer to be useful,
user friendly, acceptable and affordable to everyone in this world. We may achieve
this ultimate goal through the realization of the following three major objectives:
Convenience or Ease of Use
Operating systems hide the idiosyncrasies of hardware by providing abstractions
for ease of use. Abstraction hides the low level details of the hardware and provides
high level user friendly functions to use a hardware piece. For example, consider
using a hard disk which records information in terms of magnetic polarities. A hard
disk consists of many cylinders and tracks and sectors within a track and the read/
write heads for writing and reading bits to a sector. A user of a computer system
cannot convert the data to be recorded to a format needed for the disk and issue low
level commands to address the appropriate track and read/write head and write the
data on to the right sector. There are software programs called device drivers for
every device types to handle this task. The programmer just issues read/write
commands through the OS and the OS passes it to the driver which translates this
command to the low level commands that a hard disk can understand. The OS may
issue the same command for reading/writing to a tape drive or to a printer. However,
the device drivers translate it into the proper low level commands understood by
Self-Instructional
4 Material
the addressed device. The same is true for any other electromechanical and electronic Introduction to Operating
Systems
devices connected to a computer.
An application program wants to use the functionalities built into an operating
system as parts of its code while executing it. The OS provides these functionalities
to other programs through the use of software interrupts or system calls. Library NOTES
functions are provided for all standard Input/Output (IO) operations. A programmer
can just reuse it so that he can concentrate on the coding of major logical aspects of
the problem at hand.
Efficient Allocation and Utilization of Resources
A computer system has various resources like the Central Processing Unit (CPU),
memory and I/O devices. Every use of the resources is controlled by the OS.
Executing programs or processes may request for the use of resources and the OS
sanctions the request and allocates the requested resources if available. The allocated
resources will be taken back from the processes normally after the use of the same
is completed. That is, the OS is considered as the manager of the resources of a
computer system. The allocation of resources must be done looking for overall
efficiency and utilization. That is, the allocation must be done to improve the system
throughput (number of jobs executed per unit time) and the use of resources in a
fair manner.
Ability to Evolve
The OS provides many services to the user community. As the time passes, users
may need new and improved services for accomplishing some task with the computer.
In some situations, as we use the system for doing new task, some of the existing
services may introduce undesirable side effects causing inefficient utilization of
resources or may even compromise with the security of the system itself. So, it may
also be desirable to remove the existing implementations of such services and
introduce new implementations. Also, there can be bugs in the code that may surface
over time as we use the services for various purposes. The design of the OS must
include provisions for easy introduction of new services and removing or improving/
replacing the existing services. The design must provide easy interfacing facility to
connect and communicate with new types of hardware devices and upgraded versions
of the existing hardware devices.
Hardware Components of Computer Systems
We understand from the discussion above that the operating systems control the
hardware components of computers. So, let us look at the major hardware
components of computers. The diagram shown in Figure 1.1 depicts the four major
hardware components of a computer system. They are processor or CPU, I/O devices,
memory and buses. Let us see a bit more details of each these components.
Busses

CPU Memory I/O


Devices

Fig. 1.1 Hardware Components of a Computer System


Self-Instructional
Material 5
Introduction to Operating Central Processing Unit: A CPU consists of various registers for holding
Systems
instructions and the operands of instructions and other functions, arithmetic/logic
unit for carrying out arithmetic and logic operations dictated by the instructions and
the control/execution unit for generating the control signals needed for fetching
NOTES instructions, operands and executing instructions. A modern CPU also includes the
primary cache memory for fast access of instruction and data.
As registers will be referred to at many points in the discussion of operating
systems, some more details of the use of the same is necessary. There are various
other functions or purposes for which registers are used. Registers for holding
operands or results of computation are called accumulators. There is a special register
to act as instruction pointer or Program Counter (PC). The status or state of CPU at
any point during computation is recorded and kept in a register normally called
status register. The top of a stack used for holding temporary and local variables is
pointed to by a register called stack pointer.
Input/Output Devices: The input/output devices of a computer include
keyboard, monitor, mouse, pen, printers, scanners, secondary storage devices like
hard disk, floppy disk, Compact Disk Read Only Memory (CD ROM), etc. These
are used for the interaction of the computer with the real world objects. A keyboard,
mouse and monitor are needed for the human interaction with the computers. The
programs and data are stored in permanent secondary storage devices before
execution. A huge amount of storage space at low cost is feasible with secondary or
permanent storage devices. However, the secondary storage devices are very slow
when compared to RAM, the primary or main memory storage devices.
Memory: The main memory or Random Access Memory (RAM) is the place
where programs and data are stored before execution begins. Later, when we study
virtual memory technique, we will see that only some part of the program/data
needed to be loaded in main in RAM before the start of execution. Other parts will
be brought as and when required during the execution time. The speed of access
(reading and writing) of RAM is normally about one tenth of CPU register/cache
memory access speed. So, high speed cache memory is normally placed between
CPU and main memory (RAM).
Bus: A bus is the electrical interconnection wires used for connecting the
CPU, memory and I/O devices so that data can be sent out and received by each of
the components. Each of the devices/components is connected to common buses.
The CPU communicates with memory and I/O devices through the buses. There are
various buses, for example address bus, data bus and control bus between a pair of
components.
Operating System Functions
In a computer system, users have to run their programs, store programs or data
permanently on secondary storage devices and have to determine the malfunctioning
programs and locate the information needed to identify the reasons for errors.
Processes (running programs) may want to communicate with each other for sharing
of data and for cooperated execution and may need to read data from input devices,
such as keyboard and write data to output devices, such as printer and monitor. It
will not be practicable for each user program to build these facilities for
accomplishing their task. Moreover, such facilities if built into each user program
may lead to a system that is unsecured and undependable. So, the operating system
Self-Instructional
6 Material
must provide the services needed to accomplish all these tasks. The functions Introduction to Operating
Systems
provided by an operating system for these and other purposes may be grouped under
the four headings as given below:
Program Execution, Control and Communication Services NOTES
A computer system provides various facilities to execute the programs (processes)
and control the programs. A program needs memory for loading the program before
the start of execution and other resources including the CPU for execution. In a
system, there will be many users and each user will be executing many tasks all of
which need memory, the CPU and other resources. These resources will be normally
limited and shared among processes in a space and/or time multiplexed fashion. In
some situations, an application may be executed as multiple cooperating processes
possibly on different computers connected through network. It may be necessary to
exchange information between processes. Also, processes will be competing for
using the available resources. So, these functions are to be done in a supervisory
mode by the operating system. Thus, an OS must provide the following functions:
 Creation and deletion of processes.
 Suspension and resumption of processes.
 Synchronizing the execution of processes.
 Communication between processes on a single or different computers.
 Preventing and handling deadlock situations.
 Keeping track of the amount of memory spaces allocated to different processes
and the addresses of such memory spaces.
 Allocating main memory when requested.
 De-allocating the main memory used by the process when it terminates and
adds it to the free space list for future allocation to other processes.
Services for I/O Operations
User programs need to do I/O operations on different types of devices during their
executions. Each device has its own controller and associated commands for I/O. It
will be highly inefficient that a user learns all these low level commands and
incorporate these in the program. The operating system must hide from users the
hardware details of the devices and provide high level commands like open, read
and write to handle I/O on all devices irrespective of their types. Also, from the
protection of files and efficiency point of view, it is not advisable to do the I/O
operations directly by a user program. Manufacturer of each device type will provide
a program appropriate to the device called device driver. The device drivers can
take high level commands, for example open, read and write as inputs and translate
them into low level commands that the controller of the device can understand. So,
an OS must provide the functions, such as open(), read() and write() to
handle all devices in a uniform manner.
Services for File Manipulation
We need files for storing data and programs permanently. We have heard of different
file types, such as text, image, executable, music, video and program source files.
A program takes input from some files and writes output to some other files. Generally
Self-Instructional
Material 7
Introduction to Operating speaking, we store organized information in files. Files are created on secondary
Systems
storage devices. File system is the part of the OS program that is used to create,
manipulate, organize and maintain the files. Files are organized using directories in
a file system. Users need not bother about how the file is stored and retrieved from
NOTES secondary storage. It is the duty of operating system to hide the hardware specific
details of secondary storages. The OS provides the following functions to manipulate
and maintain files in the system:
 Create files and directories
 Open files
 Close files
 Read files
 Write files
 Rename files
 Copy files
 Delete files and directories
 List files
 Search files and directories
 Allocate, de-allocate and manage secondary storage space
Services for Error Detection
A running program may have errors or bugs which are to be detected and corrected.
Errors may be due to many reasons including trying to execute illegal instruction or
accessing of memory (intentionally or unknowingly) not allocated for a user or
infinite loop in a process or trying to execute an illegal operation on I/O devices.
The operating system monitors the functioning of different programs to detect errors
and localize them. Users can confidently execute their programs without the worry
of malfunctioning.

1.3 OPERATING SYSTEM AS A RESOURCE


MANAGER
An operating system is a complex and normally huge software used to control and
coordinate the hardware resources, for example a CPU, memory and I/O devices to
enable easy interaction of the computer with human and other applications. The
objects or entities that an operating system manages or deals with include processes,
memory space, files, I/O devices and networks. Let us first briefly describe each of
these entities.
Process: A process allows operating system to interface with the installed
hardware and software to support any applications running on the system. For every
program to execute, the operating system creates a process. A process needs
resources, such as a CPU, memory and I/O devices to execute a program. These
resources are under the control of the operating system. In a computer, there will be
many programs in the state of execution, hence a large number of processes
demanding various resources are also needed to be maintained and managed in an
operating system. When the execution is finished, the resources held by that process
will be returned back to the operating system.

Self-Instructional
8 Material
Memory Space: As mentioned earlier, the execution of a program needs Introduction to Operating
Systems
memory. The available memory is divided among various programs that are needed
to execute simultaneously (concurrently) in a time multiplexed way. In normal type
of memory, at a time only one memory location can be accessed. So, in a uni-
processor environment, because the secondary storage devices are much slower NOTES
than main memory, the programs to be executed concurrently are loaded into memory
and kept ready awaiting the CPU for fast overall execution speed. The memory is
space multiplexed to load and execute more than one programs in a time interleaved
way. Even if more than one CPU is available, at a time only one program memory
area can be accessed. However, instruction that does not need main memory access
(access can be from local memory or from CPU cache) can be executed
simultaneously in a multiprocessor scenario.
Files: Files are used to store sequence of bits, bytes, words or records. Files
are an abstract concept used to represent storage of logically similar entities or
objects. A file may be a data file or a program file. A file with no format for interpreting
its content is called a plain unformatted file. Formatted file content can be interpreted
and is more portable as one knows in what way the data inside is structured and
what it represents. Example formats are Joint Photographic Experts Group (JPEG),
Moving Picture Experts Group (MPEG), Graphic Interchange Format (GIF),
Executable (EXE), MPEG Audio Layer III (MP3), etc.
Input/Output(I/O) Devices: The I/O devices of a computer include keyboard,
monitor, mouse, pen, joystick, scanner, printer, modem, secondary storage devices
like hard disk, floppy disk, CD ROMs, etc. Primary memory like RAM is volatile
and the data or program stored there will be lost when we switch off the power to
the computer system or when we shutdown it. Secondary storage devices are needed
to permanently preserve program and data. Also, as the amount of primary storage
that can be provided will be limited due to reasons of cost and a secondary storage
is needed to store the huge amount data needed for various applications.
Network: Network is the interconnection system between computers located
in the same desk/room, same building, adjacent building or in any geographical
locations across the world. We can have wired or wireless network connections to
other computers located anywhere in the world.
From the discussion above, it is clear that the operating system has various
functions to carry out. Therefore, it consists of many subsystems to accomplish its
various tasks. The major components or subsystems needed for an operating system
are as follows:
 Process management system
 Process scheduling system
 Memory management system
 File and secondary storage management system
 I/O system management system
 Networking system
 Protection system
 User interface system
All these subsystems are explained briefly.

Self-Instructional
Material 9
Introduction to Operating Process Management System
Systems
An operating system has to provide many services for the execution of user programs
and system programs. Programs are executed as processes. A process is a program
NOTES in execution. A program can be executed by many processes on behalf of different
users. For example, a C++ compiler will be executed by many users as different
processes. A running program has various data structures to represent its context.
Code, data, program counter, registers, open files and other resources in use all
together represent the context. A process encapsulates the whole context of a running
program. Once the execution of a process is completed, it should be removed or
killed or deleted from the system. A process requesting for the resource that is not
currently available must be made to wait or suspended and it must be resumed
when the resources are available. More than one process sharing resources must be
synchronized for the right and consistent use of such shared resources. A process
should not be allowed to wait for a resource that is already held by another waiting
process in a circular chain. In some cases, a job has to be executed as multiple
cooperating processes. So, for the execution, control and deadlock free cooperation
of processes, the process management subsystem must provide services for the
following:
 Creation and deletion of processes.
 Suspension and resumption of processes.
 Synchronizing execution of processes.
 Communication between processes.
 Preventing and handling deadlock situations.
Modern operating systems also support the concept of threads which are
lightweight processes. Basically, a thread is a sequential execution stream and it is
also the smallest scheduling unit of concurrency to run on a processor. A process
may have many threads to improve the response time of an application. In that case,
services similar to that needed for the process management are required for thread
management.
Process Scheduling System
In a computer system, there will be many processes in a ready state of waiting for
the CPU to execute them. When and in what order to allocate the CPU for different
processes, in the ready state, is called process scheduling or CPU scheduling. This
scheduling is done based on various scheduling algorithms used for this purpose. In
a multiuser computer system, the next process to be executed is selected based on
the scheduling algorithm. Also, process will be allocated the CPU for a duration
that is dictated by the scheduling algorithms. After the expiry of permitted time, a
hardware timer interrupts the current execution to enable the operating system to
select the next process to execute based on the scheduling algorithm. The context
of the outgoing process must be saved and the context of the new incoming process
must be restored before handing over the CPU to the newly selected process. This is
called a context switch. There are various scheduling algorithms that are in use for
optimizing the performance of computer systems. Common among them are round
robin, First In, First Out (FIFO), shortest time first, shortest remaining time next,
etc. So, the process scheduling subsystem must provide the given functions for the
execution of programs.
Self-Instructional
10 Material
 Services for selecting next process to execute based on some scheduling Introduction to Operating
Systems
algorithm
 Context switching
 Restarting the timer to interrupt at the end of the time duration allotted for NOTES
the new process
 Transfer control to the new process
Memory Management System
The main memory is arranged as an array of bytes or words as dictated by the low
level architecture of a CPU. Every memory location has different addresses. These
addresses can be from zero to the size of memory that can be accommodated in the
CPU. This is called the address space of a CPU. These are the memory addresses
that the CPU can access directly. As mentioned earlier, in a multiuser system there
will be many programs loaded and existing simultaneously in the main memory.
The available main memory will be allocated to such programs/processes. Processes
may also request memory during the execution time. So, the operating system must
allocate memory to satisfy the needs of different processes out of the free memory
available at any time. When the processes complete their execution, its memory
must be taken back to the free memory list. When sufficient main memory is not
available, the memory occupied by some of the waiting processes or a part of the
executing processes may be written to secondary storage and the memory thus freed
may be allocated to the demanding processes. So, the memory management
subsystem has to provide the following facilities for the execution of programs:
 To keep track of the amount of memory spaces allocated to different processes
and the addresses of such memory spaces.
 Allocate main memory when requested.
 De-allocate memory used by the process when it terminates and add it to the
free space list for future allocation to other processes.
File Management System
File is an abstract concept for recoding the memory locations where the information
is recorded on storage media. Files may be considered as information folders.
Information is recorded in secondary storage as sequences of bits or bytes or words
or records. Files are stored on secondary storage media. Hard disk (magnetic disks),
magnetic tapes and optical disks, such as CD ROM, Digital Versatile Disk (DVD),
etc) are examples of secondary storage devices. Different storage devices are
characterized by speed, capacity, data transfer rate and access methods. Files are
organized into directories based on the information content or the purpose for which
it is used or based on the owner name. The various functions that a file management
subsystem must provide are as follows:
 Creation and deletion of files.
 Creation and deletion of directories.
 Opening, reading, writing and appending files and directories.
 Allocation of storage block to files and de-allocation of storage blocks to free
list.
 Keeping track of the usage of storage by files.
 Backing up files.
Self-Instructional
Material 11
Introduction to Operating I/O Management System
Systems
Users of a computer system interact mainly through I/O devices. Through the
keyboard and mouse we can apply inputs and commands to the computer and through
NOTES the monitor we can get back the responses from the computer. I/O devices normally
communicate with the computer through hardware level interrupts. The operating
system has to respond to such events by executing interrupt service routines stored
as part of its code. The I/O subsystem provides utilities for all types of communication
needed with the I/O devices. Moreover, every device type will have its own special
program called device driver for interaction and communication with the operating
system.
Networking System
Modern operating systems support execution of programs in a remote computer
connected through communication network. Such a system is called network
operating systems. Network operating systems are loosely coupled software on
loosely coupled hardware (independent computers connected to the network). Such
a system must provide remote login facility for executing programs and remote
copy command facility.
It is also possible to have a system with tightly coupled software on loosely
coupled hardware. Such a system is called distributed operating system. A distributed
operating system creates the impression of one large uni-processor computer out of
many networked computers. A single operating system runs in all the computers
and they are tightly coupled through software. Files in such a system appear to have
the same name but can have different access privileges to different users working in
any of the networked computers. A distributed system must provide a single global
inter process communication mechanism so that any process can communicate with
any other process. Distributed operating system must also provide schemes for global
protection of files.
Protection System
In a multiuser system, there will be many users executing programs simultaneously
or concurrently. Also different users will have their own resources like programs
and data files. Some users may permit their resources to be shared by other users in
a controlled way. An operating system must provide facilities for protecting the
shared use of resources, for example programs and files and also provide facilities
for controlled access rights to such resources by the users. The protection system
Check Your Progress must ensure that each resource of the system is accessed correctly and only by those
1. What type of
processes that are allowed to do so.
programs were
executed in the User Interface System
earlier computers?
2. Name the important
Users interact with a computer using a command interpreter or shell program. Human
resources of the users can also communicate through a human computer interface. They can enter
computer system. commands through a terminal (keyboard/mouse and monitor) by typing on the
3. What is the use of a keyboard or clicking on an icon or button on the desktop. The shell interprets
file? commands and executes the operations by invoking operating system services. A
4. What is the need of user program can directly invoke the operating system services through software
the secondary
storage devices?
interrupts also known as system calls.

Self-Instructional
12 Material
Introduction to Operating
1.4 TYPES OF OPERATING SYSTEMS Systems

Operating systems may be classified based on the purposes for which they are
developed and the functions they support as given below: NOTES
 Early systems
 Batch processing system
 Multi programming system
 Time shared system
 Single user system
 Multitasking system
 Parallel system
 Distributed system
 Real-time system
Before we describe each of the above classes of operating systems, let us
look at the developments taken place in early computer systems in the following
subsection.
Early Systems
Operating systems have evolved through a number of phases during the last half a
century or earlier. The earliest electronic computer developed in the mid 1940s had
no operating system at all. Machines (computers) were equipped with a console
consisting of toggles switches and display lights. Eight or sixteen mechanical toggle
switches arranged on the console were employed to enter 8 or 16 bits of instruction
and data to the computer and other switches for reset, start and debug operations.
There were no programming languages or translators for developing high level
language programs and converting them to machine understandable instructions.
Programs were written in machine language instructions which the hardware or
CPU could decode and execute to do the work. Mainly the programmers were the
users of the then computer systems.
The scene improved in the 1950s. An input device known as punch card
reader was developed to read programs recorded on a deck of punch cards. A card
punching machine was used to record program instructions and data on punch cards.
Magnetic tape memory was used as an intermediate storage device for programs
and data read from punch card readers. Printers were also developed to record
hardcopy output of programs. Assemblers and high level programming languages
were developed. Programs for linking object program and library functions and
loading the linked machine code to memory were also developed. All these programs,
viz., compilers, linker and loaders were on punched cards or magnetic tapes. Users
wishing to use the system had to sign up manually to reserve the system use for a
specified period say, one hour. A user wanting to execute his program had to set up
card decks or mount magnetic tapes for the program, compilers, linker and loader.
The output of execution was printed on a line printer. The system was operated in a
serial fashion, one user at a time for the reserved time and after that another user.
All these set up were very costly. There was a lot of time spent for setting up the
needed devices like card readers/magnetic tapes for source programs of user,
compilers, library function, linkers and loaders manually for executing and debugging
a user program.
Self-Instructional
Material 13
Introduction to Operating Batch Processing System
Systems
To drastically reduce the setup time for executing a job and improving the system
utilization, a batch processing program was developed in the mid 1950s. This helped
NOTES to make the setup needed for executing a job automatically and executing the
programs (submitted for execution at the computer centre in the form of card decks)
of different users one after another without user intervention. This batch processing
system was called the first rudimentary operating system then known as resident
monitor. A set of commands called Job Control Language (JCL) for reading the
programs using card readers/magnetic tapes and loading, executing and printing
the output were developed. The commands of JCL were used to express the sequence
of actions that the resident monitor must do to select and execute a job from the
batch of jobs submitted by different users.
With the introduction of resident monitor, the users were not permitted to
directly execute their job. The system worked in two modes: one, privileged mode
where all types instructions could be executed and two, non-privileged user mode
where privileged instructions could not be executed. I/O and some other instructions
which are useful to control the execution of programs and to access sensitive
resources are privileged ones. Total memory is divided into two regions, one for the
operating system (monitor) and the other for loading user programs. The monitor is
loaded in the OS memory and executes in privileged mode and always resides in
memory hence it is called the resident monitor. The monitor now controls the entire
computer resources and their operations. As the I/O instructions are privileged,
only the monitor can do the I/O. An user program wishing to do I/O must request
the monitor (OS) for the same and the monitor takes back the control from the user
to do the I/O in privileged mode for the user and gives control again to the user
program. The users wishing to execute jobs on the computer submitted them to the
batch processing monitor. The monitor queued the submitted jobs and took one by
one based on some strategy to execute. During the execution of user jobs, the system
control is given to the user program and when the user program completes its
execution or come across some errors, the monitor takes back the control. The
monitor then takes the next job from the batch queue and handovers control to
execute it and so on. That is, the execution of the system worked in alternate periods
of monitor (privileged) and user modes. If the user program executes any privileged
instructions then an error condition occurs and the system control transfers to the
privileged monitor mode.
Even though batch processing system reduced the setup times, the CPU
utilization was still less as there was provision for loading only one program in the
memory and ready for execution.
To improve the response time, a technique known as swapping was introduced
to pre-empt the executing program and load a new high priority job for execution.
The swapping technique writes back to secondary storage, the memory image of
the process that waits for slow I/O devices and loads the new process to replace the
memory region of the saved process. Swapping improved the response time and
degree of multiprogramming at the expense of some additional I/O time.
Another major feature introduced to gain performance is the technique of
Simultaneous Peripheral Operation OnLine (SPOOLing). In SPOOLing, a high-
speed device like a disk is placed between a running program and a low speed
device used for input/output like printer. This makes many virtual devices from a
Self-Instructional
14 Material
physical device and a program can do I/O to shared devices as if they are dedicated Introduction to Operating
Systems
devices for individual program’s use. Further, this arrangement drastically reduces
the wait times of programs for slow I/O devices as programs can do I/O directly
from/to high speed disks.
High speed secondary storage hard disk drive was also developed for use in NOTES
place of slower tape drives.
Batch processing system was widely used for information processing.
Scientific computing and business data processing was the major applications of
computer systems. The need for organizing the data and programs of different users
motivated the development of file technology. Files are abstractions of storage
devices. Programmers and users maintained program and their input and output
data on files with identifiable names.
Subsequently, for better protection and control, the computer system further
equipped with features, for example, mechanisms for protecting memory, hardware
timer for preventing a job from monopolizing the use of CPU time and interrupts.
Multiprogramming System
Jobs in a computer system consist of alternate cycles of I/O bound operations and
CPU bound operations. In a computer system, I/O operations are done by special
processors called I/O processors and the main processor (CPU) of the system in
privileged monitor mode on behalf of the user program (process) request needs
only to start the I/O on the I/O processors. The main CPU then continues executing
the user programs if there is some available process ready with all the needed
resources. When the I/O is completed, the interrupt mechanism informs the same to
the monitor (OS). The interrupt mechanism switches the execution mode from the
user to the monitor and begins executing from the interrupt handler routine that is
part of the monitor (OS) code. The monitor then informs the completion of I/O to
the concerned waiting user process and selects the next ready process or the job or
process whose I/O is just finished for execution and transfers control to it. That is,
the main CPU waits for the completion of I/O when there are no other jobs to be
executed in the system. Therefore, in a uniprogramming system, at a time only one
program is ready for execution and if that program requests I/O during execution
then the CPU has to wait until I/O is completed. Thus, as the I/O operation time is
many times larger (100 or 1000 times) than CPU instruction execution time the
CPU utilization is very low normally less than 5 per cent. In general, in a
uniprogramming environment other resources, for example memory and I/O devices
are underutilized.
Now, we can improve resource utilization by making ready more than one
program or jobs for execution. This requires the loading of more than one program
in the memory. This requires partitioning the memory into more than two regions,
one for OS and the other for as many user memory partitions as there are user
programs. By providing sufficient memory and by loading two or more jobs in the
user memory regions, there will be processes that are ready for execution. Therefore,
we can allocate CPU to another process when one process is waiting for I/O
completion. This is called multiprogramming or multitasking. That is, the CPU
executes more than one program concurrently in a time interleaved fashion. This
also improves the memory and device utilization of the system as the idle time of
memory regions and I/O devices are now less than the uniprogramming case.
Self-Instructional
Material 15
Introduction to Operating With the introduction of multiprogramming, OS needs to manage the memory
Systems
and protect each user memory from other users in addition to protecting the operating
system memory from users.

NOTES Time Shared System


A multiprogrammed batch system does not permit real-time interaction between
users and computer as the user commands needed for executing jobs are prepared
as scripts of JCL and submitted to the batch system. As users are not permitted to
submit the job script input and observe or take output directly, it took many days to
debug and correct the mistakes in program development. The solution to the above
problem was the introduction of interactive time shared multiprogramming
techniques. This enabled many users to interact with the computer system
simultaneously, each one using a separate terminal keyboard and monitor connected
to the system. Actually, each user is given a small time quantum say, 100 milliseconds
to apply commands and receive responses from the computer system in a round
robin fashion. If there are 10 users, each will be served 100 milliseconds in every
one second. Because of this fast switching of execution among users, each one felt
that the entire computer system time is available for his own use. This drastically
improved the ease of use of computers and reduced the job processing time and
program development time. With this interactive timesharing technology, a single
computer system made available for many people simultaneously for doing many
different types of tasks.
The hardware of computer system is normally very costly. In a multiuser
system, as many users are sharing this costly hardware the cost is shared among
many users and the resource utilization is also high. However, as the operating
system has to switch between many users in a short time there are some unproductive
computations called overheads computations done for job switching and associated
work.
Single User System
A computer system in which only one user can work at a time is called a single user
system. The familiar Intel processor based Windows OS Personal Computer (PC) is
an example of single user system. Such a typical system will have a single keyboard,
mouse and monitor as I/O devices for the user to interact with the system. Users
apply commands through the keyboard and mouse and the computer displays its
responses (output) on the monitor. A user can do various tasks like preparation of a
document or editing a program or writing a letter and printing it using a printer. A
user can simultaneously or concurrently execute many tasks or jobs in currently
available personal computers. An important design issue of such interactive systems
is the response time which is the time taken by the computer to start producing
output after a command has been entered. The response time must be within a
predictable limit for user satisfaction and acceptability. When one user is working
on the computer, the other users have to wait till the current user finishes his work
and leaves the seat. Examples of single user operating systems are Microsoft Disk
Operating System (MS DOS), Windows 95, Windows NT, Windows 2000 and
Windows Vista each of which runs on Intel processor based computers. Other
examples are Macintosh OS X.x, Linux single user OS which are derivatives of
UNIX operating system.

Self-Instructional
16 Material
Multitasking System Introduction to Operating
Systems
Multitasking is concerned with a single user executing more than one program
simultaneously or concurrently. It may also mean a user executing his application
as many concurrent processes. An operating system with multitasking ability runs NOTES
many applications, for example Microsoft Word, Microsoft Excel, printing
documents, Internet Explorer, etc., simultaneously or concurrently. Operating system
executes each for a small time slice in a round robin fashion so that the user cannot
distinguish the switching of CPU among different applications. It appears to the
user that they are running at the same time.
Advantages
Following are the advantages of multitasking system:
 The ability of multitasking system to permit user to run more than one task
simultaneously leads to increased productivity.
 Improves system resource utilization, throughput and overall efficiency of
the system.
Disadvantages
Following are the disadvantages of multitasking system:
 Increased overhead processing time.
 Needs more resources like memory, CPU time and I/O devices for user
satisfaction.
Parallel System
A parallel system is the outcome of the thoughts concerned about the limits on the
ultimate speed of computation achievable using the propagation speed of electronic
signals. As we know, the speed of electronic signals is 10 × 10 10 centimetre per
second and hence there is a limit on the physical size of the CPU chip when operated
at speeds above 1 GHz (109 cycles per second). For example, a 10 GHz CPU chip
cannot be more than 3 cm wide, as the signal travels only 3 cm distance in a clock
period of 0.1 nanosecond. Moreover, the amount of heat generated becomes excessive
when the size is small at such high clock speeds. Therefore, we have now come to
the upper limit on the clock speed, and there is no way of increasing the processing
speeds of application by increasing the clock speeds of the CPU further. The outcome
of the above thoughts is the development of parallel processing systems with multiple
CPUs/computers. There are two classes of parallel processing system as given below:
 Tightly coupled bus based shared memory multiprocessor system.
 Loosely coupled distributed memory multiprocessor system.
Tightly Coupled Shared Memory Multiprocessor System
In this scheme, all processors share the same memory address space. Processors are
interconnected with one another using special hardware to the common memory
bus. If one processor writes a memory word, the change is visible to all other
processors. At a time, only one processor can access the main memory. However, as
each processor has its own private cache memory the processor access will be mainly
to this local cache. Processor needs to access the common shared memory only
when there is a memory access outside the cache memory address space. This is
Self-Instructional
Material 17
Introduction to Operating called a cache miss. The cache will be designed in such a fashion that the number of
Systems
misses will be normally less than 5 per cent. Thus, the presence of cache not only
speeds up the memory access but also reduces the main memory access to about
less than 5 per cent reducing chances of the bus contention out of access from
NOTES different processors. Processes on different processors can easily communicate
through shared memory. Figure 1.2 shows the arrangement of lightly coupled shared
memory system in which each processor has its own local memory, cache and Hard
Disk Drive (HDD).

Cache Cache Cache


MEMORY HDD
CPU CPU CPU

Fig. 1.2 Tightly Coupled Bus based Shared Memory Multiprocessor

Loosely Coupled Distributed Memory Multiprocessor System


In this scheme, each processor has its own memory, cache and hard disk storage
and they are interconnected through networks. Communication between processes
on different machines is carried out through message passing which is normally
slow due to network congestion when compared to shared memory communication.

Network
connection
M
CPU

M
CPU

M
CPU

Fig. 1.3 Loosely Coupled Distributed Memory Multiprocessor

Figure 1.3 shows the arrangement of loosely coupled distributed memory


system. Executing your program on a distributed memory multiprocessor involves
the organization of the program as a set of independent tasks that communicate
with each other using messages. The partitioning of the job or program into
independent tasks must be done in such a way as to avoid the communication
requirements between different tasks running on different distributed memory

Self-Instructional
18 Material
computers. Therefore, the programmer must have the knowledge of the data Introduction to Operating
Systems
processing need at various nodes of the distributed system.
Choosing to implement a program in shared memory versus distributed
memory is usually based on the amount of information that must be shared by
parallel tasks. Shared memory system might be better if the amount of shared NOTES
information is large as otherwise the distributed memory system communication
cost will be much higher.
Distributed System
A distributed system composed of large numbers of computers is connected by high
speed networks. The computers in the distributed system are independent, but they
appear to the users as a large single system. This is in contrast to the old mainframe
computers which are centralized and single processor systems with large memory,
I/O devices and connected to many terminals with no processing power, through
which many people can work or run applications concurrently.
In distributed systems, users can work from any of the independent computers
as terminals. The applications or programs run on any of the computers distributed
even geographically distant places and possibly on the computer (intelligent terminal)
from which the user entered command to run the program. That is, people can work
from any computers and applications can run on any of the member computers in
the system depending up on the availability and workload. There will be mechanism
built into the distributed OS to balance the load (CPU workload) on different
independent computers of the system. A distributed system will have only a single
file system with all files of a user accessible as dictated by the permissions associated
with each file from any computers of the system with the same access permissions
and using the same path name. Automatic Teller Machines (ATMs) of a bank is an
example of a distributed system but useful only for banking applications.
Advantages
Following are the advantages of distributed system:
 Data sharing: Allows data sharing access to common databases.
 Device sharing: Allows many users share expensive peripherals like high
resolution printers, scanners and digital cameras.
 Communication: Makes communication between users easier.
 Spreads the available workload over independent computers of the system in
a cost effective way.
Disadvantages
Following are the disadvantages of distributed system:
 Network communication is delayed due to saturation or other problems.
 Security: It needs tools and techniques for providing controlled access to
sensitive data.
Real-time System
A real-time operating system is the one which responds to real-time events or inputs
within a specified time limit. The importance of real-time systems has increased
especially in today’s increased use of embedded applications. Real-time systems
include satellite control systems, process control systems, control of robots, air
Self-Instructional
Material 19
Introduction to Operating traffic control systems and autonomous land rover control systems. A real-time
Systems
system must work with a guaranteed response time depending up on the task
otherwise, the application might fail.
In a real-time operating system, some of the tasks are real-time, and the others
NOTES are ordinary computing tasks. Ordinary computing tasks, for example commands
from interactive users, preferably demand small response time when compared to
the user interaction time. Faster response time keeps the users satisfied. Whereas,
with a real-time task there always exists a deadline to start responding after an
event and another deadline for the completion of the response. Real-time tasks are
classified as hard and soft. A hard real-time task must meet its deadline to avoid
undesirable damage to the system and other catastrophic events. A soft real-time
task also has deadline but failures to meet it will not cause a catastrophe or great
losses.
Most real-time operating systems are designed with the objective of starting
real-time tasks as rapidly as possible. This is possible only if the interrupt handling
and task dispatching are fast. There should be some hard limit on the amount of
execution time spent on an interrupt handler code as the event may occurs while an
high priority interrupt handler is at mid way its execution. The latency of response
to events may be predictably controlled by carefully choosing the interrupt priority
and limiting the amount of time that is needed by the CPU on interrupt handlers.

1.5 STRUCTURE OF AN OPERATING SYSTEM


An operating system is composed of a kernel and user level libraries. But, knowing
the structure of an operating system refers to know the basic concept of virtual
machine, kernel, CPU and I/O structure which are discussed below:
1.5.1 Virtual Machine Concept
The operating system provides applications with a virtual machine. This type of
situation is analogous to the communication line of a telephony company which
enables separate and isolated conversations over the same wire(s). An important
aspect of such a system is that the user can run an operating system as per choice.
The virtual machine concept can be well understood by understanding the
difference between conventional multiprogramming and virtual machine
multiprogramming. In conventional multiprogramming, processes are allocated a
portion of the real machine resources, i.e., a resource from the same machine is
distributed among several resources (refer Figure 1.4).

Conventional Multi-
programming OS

JOB 1 JOB 2 --------- JOB N

Fig. 1.4 Conventional Multiprogramming


Self-Instructional
20 Material
In the virtual machine multiprogramming system, a single machine gives an illusion Introduction to Operating
Systems
of many virtual machines each of them having its own virtual processor and storage
space which can be handled through process scheduling (refer Figure 1.5).

Virtual Machine NOTES


Operating System

Virtual Machine 1 Virtual Machine 2 Virtual Machine 3

Fig. 1.5 Virtual Machine Multiprogramming

Advantages
Following are the advantages of virtual machine:
 Each user is allocated with a machine which eliminates mutual interference
between users.
 A user can select an OS of the choice for executing his virtual machine.
Hence, the user can simultaneously use different operating systems on the
same computer system.
1.5.2 Kernel Approach
Kernel is the central part of an operating system which directly controls the computer
hardware. Following are the advantages of kernel.
 Kernel lies below system call interface and above the physical hardware.
 It provides large number of functions, such as CPU scheduling, memory
management, I/O management, synchronization of processes, inter process
communication and other operating system functions.
1.5.3 Central Processing Unit and Input/Output Structure
The Arithmetic and Logical Unit (ALU) and the Control Unit (CU) of a computer
system are jointly known as the central processing unit. You may call CPU as the
brain of any computer system. It takes all major decisions, makes all sorts of
calculations and directs different parts of the computer functions by activating and
controlling the operations.
For a computer to start running, it needs to have an initial program to run.
This initial program, also known as bootstrap program, tends to be simple. It is
stored in CPU registers. The role of the initial program or the bootstrap program is
to load the operating system for the execution of the system. The operating system
starts executing the first process, such as ‘init’ and waits for some event to occur.
Event is known to occur by an interrupt from either the hardware or the software.
Hardware can interrupt through system bus whereas software through system call.
When a CPU is interrupted, it immediately stops whatever it is doing and
returns to a fixed location. This fixed location usually contains the starting address
where the service routine for the interrupt is located.

Self-Instructional
Material 21
Introduction to Operating MEMORY
Systems

NOTES CPU

I/O
DEVICES

Fig.1.6 Structure of a Computer System

Input/Output Structure
There are various types of I/O devices that are used for different types of applications.
They are also known as peripheral devices because they surround the CPU and
make a communication between computer and the outer world. Following types of
devices are implemented with system unit:
Input Devices: Input devices are necessary to convert our information or data into
a form, which can be understood by the computer. A good input device should
provide timely, accurate and useful data to the main memory of the computer for
processing. Keyboard, mouse and scanner are the most useful input devices.
Output Devices: Visual Display Unit (VDU), terminals and printers are the most
commonly used output devices.

1.6 POST AND BOOTSTRAPPING


Power On Self Test (POST) is a diagnostic tool that provides the end user information
about the computer. The motherboard Basic Input Output System (BIOS) contains
POST function. It provides BIOS related diagnostic information in two forms and
these two forms are known as POST codes and beep codes. When the Personal
Check Your Progress
Computer (PC) is booted it first goes to the POST that builds diagnostic program.
It verifies whether the hardware is functioning properly before the BIOS starts the
5. How are operating
systems classified?
process of actual booting. It then continues with other tests, such as the memory
6. What was done to
test. POST indicates wrong process in the machine. Beep patterns can be used for
improve the diagnosing many hardware problems with the PC. The actual patterns depend on
response time of the the companies which manufactured the BIOS. The most common example is Award
computer systems? and American Megatrends Inc. (AMI) BIOS. Troubleshooting expert helps users to
7. Give an advantage figure out the POST codes and solution for occurred problem. Sometimes, POST
of the multitasking
system.
errors are considered as fatal error which halts the boot process immediately. POST,
8. What happens when
a hardware detecting program applicable for BIOS requires loading and detecting
a CPU is firmware, includes the following steps:
interrupted?
 A POST program is run to test and detect a hardware program.
9. What is the use of
the input devices?  When the hardware testing program sends back an error value it shows the
output of error messages corresponding to the hardware testing program to a
Self-Instructional
memory.
22 Material
 It reboots the computer, loads next sequence of detecting firmware to the Introduction to Operating
Systems
BIOS and runs the hardware testing program of detecting firmware.
 It continues to run the POST program when the hardware testing program
sends back a correct value. If the hardware testing program sends back an
error value then above process is repeated. NOTES
POST codes are different for all BIOS manufacturers. They provide visual
characters readout to show what stage the POST is at. A POST card is required to
see the coding that can be set in motherboard’s POST codes. The recent motherboards
are facilitated with built-in diagnostic capability tools. It is a 32-bit card that is
allotted in Peripheral Component Interconnect (PCI) slot on any type of motherboard.
The POST processes include verification test, register test, controller test, receive
digital signal path test and basic front end test to perform its task efficiently and
successfully. The POST is initiated, performed and completed within a short time,
for example it can take three seconds when power is switched on. The tests are
performed after the POST at the discretion of an operator. This process includes a
transmit test, a transducer element test, a front end voltage test and a receive test.
The various BIOS companies, such as Award, AMI and Phoenix provide own beep
codes. Beep codes occur if motherboard has an inbuilt speaker. Most chassis have a
speaker connector so if the motherboard does not come with a built-in speaker it
usually comes with a 4-pin speaker header. These codes occur if the board either
functions normally or get problem abruptly with system functioning. In most cases,
one time beep is produced if the board POST is executed successfully. There are
few beep codes coming in a chart format. It is easy and necessary to analyse the
beep codes. Beeping sound makes the users aware if the computer does not boot
successfully. Thus, beep sounds ensure that CPU works properly and POST performs
its functions at this stage. Following are the various types of POST method:
Microsoft POST Operating System: This POST starts immediately after power
is up. The Microsoft Windows XP operating system sends results to the front panel
for POST that works as per instructions but the results are not saved in a file.
Application POST: The application POST executes when the real-time
processor has booted up to check licensing requirements, missing Dynamic Link
Library (DLL) socket communications, with the real-time processor and the data
transfer processor.
Real-time Processor POST: The real-time processor POST is executed from
its own boot ROM. Its processed results are written in the power up status file.
Data Transfer Processor POST: The data transfer processor POST is started
by the real-time processor. Its processed results are written in the power up status
file.
Hardware Control Processor POST: The real-time processor POST
communicates with the hardware control processors. Real-time hardware includes
down converter, motherboard and Remote File Input Output (RFIO).
The POST was introduced with Reduced Instruction Set Computer Operating
System (RISC OS) 3.0 and later versions of the OS. When computer is switched on
the machine verifies the hardware for physical faults before using it. Then, it
highlights major errors so that hardware damage would not be possible. ROM,
RAM, VIDeo Controller (VIDC) and Input Output Controller (IOC) test are carried
out in POST process in which the color of the screen becomes blue. A limited
Self-Instructional
Material 23
Introduction to Operating memory test is carried out simultaneously with a second test of the VIDC and IOC.
Systems
When the screen again becomes purple the machine is tested for an ARM3 chip. At
the end of the sequence the screen color is set to green for pass status or red for fail
status. If POST is passed successfully through all processes the machine starts booting
NOTES and the RISC OS 3.0 welcome screen is seen. If any test fails the screen remains red
and the disk drive light blinks a fault code. A short flash is used for indicating a
binary ‘0’ and a long flash for binary ‘1’. The bits are grouped into eight nibbles,
i.e., blocks of four bits with the most significant bit first. The block constituted by
the lowest seven bits is known as status word. Each bit is coded in hexadecimal
format as shown in Table 1.1.
Table 1.1 Bit Values and their Function

Bit Value Function


00000001 POST is processed when power is on.
00000002 POST is processed by interface hardware.
00000004 POST is processed by test link.
00000008 POST is processed by long memory test.
00000010 POST is processed if ARM ID detected.
00000020 It disables long memory test.
00000040 POST is processed to detect IO interfaces.
00000080 POST is processed to detect Virtual Random
Access Memory (VRAM).

The fault code contains the bits value from bit-8 to bit-31. All bits are not used in
fault code. If the code is marked as reserved RiscPC it means error number is currently
unassigned. It states that older hardware is no longer sensible for the new machines.
Table 1.2 shows the bit values and their functions.
Table 1.2 Bit Values and their Functions

Bit Value Function


00000100 This bit value is used for CMOS RAM checksum error.
00000200 This bit value is used for ROM failed checksum test.
00000400 This bit value is used for failed MEMC CAM mapping.
00000800 This bit value is used for failed MEMC protection.
00001000 This bit value is used for reserved code on the RiscPC.
00002000 This bit value is used for reserved code on the RiscPC.
00004000 This bit value is used for Virq video interrupt.
00008000 This bit value is used for VIDC Sirq sound interrupt
00010000 CMOS unreadable.
00020000 RAM control line failure.
00040000 RAM test failure.
00080000 A reserved code on the RiscPC.

Self-Instructional
24 Material
The RiscPC (codenamed Medusa) is Acorn Computers’s next generation RISC OS/ Introduction to Operating
Systems
Acorn RISC Machine computer launched in the year of 1994 which superseded the
Acorn Archimedes. Virq (video interrupt) and Sirq (sound interrupt) are assembled
with microprocessor. If POST is failed with VIDC enhancer and machine is continued
to work systematically then Beginner’s All-purpose Symbolic Instruction Code NOTES
(BASIC) program runs and saves COMS settings. The following code is written in
BASIC language to save the CMOS settings:
REM saving POST CMOS settings
REM read byte
SYS “OS_Byte”,161, &BC TO, byte%
REM EOR byte for mask bit 1
byte% = byte% EOR %10000000
REM writing byte
SYS “OS_Byte”,161, &BC TO, byte%
END
The result of above coding is to save 1-bit while preserving the other bit which is
used to change the Complementary Metal Oxide Semiconductor (CMOS) setting.
Bootstrapping
In computing, booting (booting up) is a bootstrapping process that starts the operating
system when the user switches on a computer. A boot sequence is the initial set of
operations that the computer performs when switched on. The bootloader typically
loads the main operating system for the computer.
One can boot an operating system in two conditions: (i) where there is a
single OS installed and (ii) where there are multiple OSs installed on the computer.
Single OS Boot Process
Whenever a computer is turned on, BIOS takes control and performs many
operations, such as checking hardware and ports and then loads the Master Boot
Record (MBR) program into the memory (RAM).
In the next step, the MBR takes control of the booting process.
When only one OS is installed, the functions of MBR are as follows:
 The boot process starts by executing a code in the first sector of the
disk.
 MBR looks over the partition table to find the ‘Active Partition’.
 Control is passed to that Partition’s Boot Record (PBR) to continue
booting.
 The PBR locates the system specific boot files, such as Win98’s io.sys
or WinXP’s ntoskrnl.
 Then these boot files continue the process of loading and initializing
the rest of the OS.
Multiple OS Boot Process
When there are multiple OSs, be it multiple Windows or Windows with Linux, the
booting process is slightly different. There can be two different types of booting
processes in a multiple OS environment, the Microsoft way and non-Microsoft way
or third party boot loader way.

Self-Instructional
Material 25
Introduction to Operating
Systems 1.7 KERNEL
Kernel is the fundamental part of an operating system. It is a piece of software used
NOTES for providing secure access to the machine’s hardware for various computer
programs. Since, there are many programs which are used to access the hardware is
limited to the kernel and also responsible for deciding when and how long a program
should be able to make use of a piece of hardware in a technique. This process is
known as multiplexing. Accessing the hardware directly is a complex task therefore
the kernel is implemented for hardware abstractions. These abstractions are a way
of hiding the complexity and providing a clean and uniform interface to the
underlying hardware which makes it easier on application programmers. The kernel
is the central part of an operating system that directly controls the computer hardware.
Usually, the kernel is the first of the user installed software on a computer but
booting directly after the BIOS. Operating system kernels are specific to the hardware
on which they are running thus most operating systems are distributed with different
kernel options that are configured when the system is installed. Changing major
hardware components, such as the motherboard, processor or memory often requires
a kernel update. The two major types of kernels available in the computer markets
are the Windows kernel and the UNIX like kernels. The Windows kernel is available
only with the series of Microsoft Windows operating systems. UNIX like kernel is
a family of operating system kernels that are based upon the original Bell Labs
UNIX operating system. Common examples of UNIX like kernels are the Linux
kernel, Berkeley Software Distribution (BSD), Mac OS and Solaris. Following are
the functions of kernel:
 The function of kernel in the operating system is to improve system security
and performance.
 Kernel is used to increase the system stability and security.
 Microkernel, one of the prime types of kernel, is often used in embedded
robotic or medical computers because most of the OS components reside in
their own private or protected memory space.
 Exokernel which is also one of the prime types of kernel used for a very low
level interface to the hardware lacking any of the higher level functionalities
of other operating systems.
 The goal of kernel is to allow an application to request the specific piece of
memory and specific disk block. The main function of kernel is to check
whether the requested resource is free and the application is allowed to access
it.
Figure 1.7 shows the two modes of operating system known as user mode and
kernel mode. Both modes provide the system services for Hardware Abstraction
Layer (HAL) as well as for microkernel too.

Self-Instructional
26 Material
Introduction to Operating
Systems
Write

Login
Win16 Procedure
XWing NOTES

WOW
net use Security
Subsystem trueblue

Word 7
NTVDM

OS/2
rm Subsystem
POSIX
Subsystem Win32 Subsystem

User Mode

Kernel Mode

System Services

I/0 Object Security Process Local Virtual Graphics


Manager Manager Reference Manager Procedure Memory Subsystem
Cache Mgr Manager Call Manager
Facility Window
File System Manager
Drivers
Graphics
Network Device
Drivers Interface
Microkernel
Device Graphics
Drivers Device
Hardware Abstraction Layer Drivers

Hardware

Fig. 1.7 Kernel in an Operating System

The structure of operating system is separated into two sections in which the upper
section contains components that run in user mode and the lower section containing
those that run in kernel mode. The heart of the various types of operating systems,
such as Linux or Windows consists of the modules running in kernel mode. Most
interactions with the computer hardware take place via the HAL although some
device drivers also directly access the hardware. The core of the operating system Check Your Progress
refers to kernel which is the microkernel. It oversees the working of all of the other
10. What is POST?
modules and handles communications between them and the HAL (refer
11. What all POST
Figure 1.7). In the other components of the kernel, each has a single specific area of process includes?
responsibility. An I/O manager controls most input and output on the system. The 12. What is BOOTing?
role of object manager is to create, modify and delete the system objects. Data 13. What are the
structures correspond to a specific instance of a resource, for example a file, a conditions for
process or a port. The Security Reference Manager (SRM) is responsible for enforcing booting the system?
system security settings by granting or denying access to objects and system resources 14. What is a Kernel?
upon request from the object manager. This process relies on data structures known
Self-Instructional
Material 27
Introduction to Operating as Security Access Tokens (SAT). The Process Manager (PM) creates and manages
Systems
system processes but process scheduling is handled by the microkernel. The Local
Procedure Call (LPC) facility is responsible for communication between distinct
processes known as interprocess communication. The Virtual Memory Manager
NOTES (VMM) handles the allocation and use of the system’s memory. The Graphics
Subsystem (GS) provides services required for interfacing to graphical displays.

1.8 SUMMARY
 The first computers did not have operating systems and they simply ran
standalone programs.
 An Operating System (OS) can be defined as ‘Software responsible for the
direct control and management of hardware and basic system operations’.
 Operating systems hide the idiosyncrasies of hardware by providing
abstractions for ease of use. Abstraction hides the low level details of the
hardware and provides high level user friendly functions to use a hardware
piece.
 A computer system has various resources like the Central Processing Unit
(CPU), memory and I/O devices. Every use of the resources is controlled by
the OS.
 A Central Processing Unit (CPU) consists of various registers for holding
instructions and the operands of instructions and other functions, arithmetic/
logic unit for carrying out arithmetic and logic operations dictated by the
instructions and the control/execution unit for generating the control signals
needed for fetching instructions, operands and executing instructions.
 A bus is the electrical interconnection wires used for connecting the CPU,
memory and I/O devices so that data can be sent out and received by each of
the components. Each of the devices/components is connected to common
buses.
 A computer system provides various facilities to execute the programs
(processes) and control the programs. A program needs memory for loading
the program before the start of execution and other resources including the
CPU for execution.
 The operating system must hide from users the hardware details of the devices
and provide high level commands like open, read and write to handle I/O on
all devices irrespective of their types.
 The objects or entities that an operating system manages or deals with include
processes, memory space, files, I/O devices and networks.
 Operating systems may be classified based on the purposes for which they
are developed and the functions they support.
 To improve the response time, a technique known as swapping was introduced
to pre-empt the executing program and load a new high priority job for
execution. The swapping technique writes back to secondary storage, the
memory image of the process that waits for slow I/O devices and loads the
new process to replace the memory region of the saved process.

Self-Instructional
28 Material
 In a uniprogramming system, at a time only one program is ready for execution Introduction to Operating
Systems
and if that program requests I/O during execution then the CPU has to wait
until I/O is completed.
 In multiprogramming or multitasking, the CPU executes more than one
program concurrently in a time interleaved fashion. This also improves the NOTES
memory and device utilization of the system as the idle time of memory
regions and I/O devices are now less than the uniprogramming case.
 A distributed system composed of large numbers of computers is connected
by high speed networks. The computers in the distributed system are
independent, but they appear to the users as a large single system.
 A real time system (operating system) is the one which responds to real time
events or inputs within a specified time limit.
 An operating system is composed of a kernel and user level libraries. The
operating system provides applications with a virtual machine.
 In the virtual machine multiprogramming system, a single machine gives an
illusion of many virtual machines each of them having its own virtual processor
and storage space which can be handled through process scheduling.
 Power On Self Test (POST) is a diagnostic tool that provides the end user
information about the computer. The motherboard Basic Input Output System
(BIOS) contains POST function. It provides BIOS related diagnostic
information in two forms and these two forms are known as POST codes and
beep codes.
 Booting is a bootstrapping process that starts the operating system when the
user switches on a computer. A boot sequence is the initial set of operations
that the computer performs when switched on. The bootloader typically loads
the main operating system for the computer.
 Whenever a computer is turned on, BIOS takes control and performs many
operations, such as checking hardware and ports and then loads the Master
Boot Record (MBR) program into the memory (RAM).
 Kernel is the central part of an operating system which directly controls the
computer hardware. It is a piece of software used for providing secure access
to the machine’s hardware for various computer programs. The function of
kernel in the operating system is to improve system security and performance.

1.9 KEY TERMS


 Process scheduling: It is the method of timing and arranging the CPU for
different processes, in the ready state.
 Network operating systems: It supports execution of programs in a remote
computer connected through communication network.
 Distributed operating system: It is a system with tightly coupled software
on loosely coupled hardware.
 Multiprogramming: It is one of the types of operating systems in which the
CPU can be allocated to another process when one process is waiting for I/O
completion.
Self-Instructional
Material 29
Introduction to Operating  Single user system: It is a computer system in which only one user can work
Systems
at a time.
 Kernel: It is a piece of software used for providing secure access to the
machine’s hardware to various computer programs.
NOTES
 Power on self test: It is a diagnostic tool that provides the end user information
about the computer.

1.10 ANSWERS TO ‘CHECK YOUR PROGRESS’


1. The first computers did not have operating systems and they simply ran
standalone programs.
2. A computer system has various resources, such as CPU, memory and I/O
devices.
3. Files are used to store sequence of bits, bytes, words or records.
4. Secondary storage devices are needed to permanently preserve program and
data.
5. Operating systems may be classified based on the purposes for which they
are developed and the functions they support.
6. To improve the response time, a technique known as swapping was introduced
to pre-empt the executing program and load a new high priority job for
execution.
7. An advantage of the multitasking system is its ability to permit user to run
more than one task simultaneously which leads to increased productivity.
8. When a CPU is interrupted, it immediately stops whatever it is doing and
returns to a fixed location.
9. Input devices are used to convert our information or data into a form, which
can be understood by the computer.
10. Power On Self Test (POST) is a diagnostic tool that provides the end user
information about the computer. The motherboard Basic Input Output System
(BIOS) contains POST function. It provides BIOS related diagnostic
information in two forms and these two forms are known as POST codes and
beep codes.
11. The POST processes include verification test, register test, controller test,
receive digital signal path test and basic front end test to perform its task
efficiently and successfully. The POST is initiated, performed and completed
within a short time, for example it can take three seconds when power is
switched on. The tests are performed after the POST at the discretion of an
operator.
12. Booting (booting up) is a bootstrapping process that starts the operating system
when the user switches on a computer. A boot sequence is the initial set of
operations that the computer performs when switched on. The bootloader
typically loads the main operating system for the computer.

Self-Instructional
30 Material
13. One can boot an operating system in two conditions: (i) where there is a Introduction to Operating
Systems
single OS installed and (ii) where there are multiple OSs installed on the
computer.
14. Kernel is the fundamental part of an operating system. It is a piece of software
used for providing secure access to the machine’s hardware for various NOTES
computer programs. The kernel is the central part of an operating system that
directly controls the computer hardware.

1.11 QUESTIONS AND EXERCISES

Short-Answer Questions
1. Define operating system.
2. Name the various output devices.
3. What are the categories under which the services provided by the OS can be
grouped?
4. What is a network?
5. What are the functions of the process scheduling subsystem?
6. What is a batch processing system?
7. Define multitasking.
8. What are the disadvantages of a multitasking system?
9. What are the classes of parallel processing system?
10. What is a virtual machine?
11. Define POST.
12. How does a bootstrapping process works?
13. What is the goal of a kernel in an OS?
Long-Answer Questions
1. Explain the process of efficiently allocation as well as utilization of resources.
2. Elaborate about the hardware components of the computer system.
3. Describe the services provided by the operating system.
4. Describe the role of the operating system as a resource manager.
5. Explain the major components required for an operating system.
6. Write a short note on:
(i) Process management system
(ii) Memory management system
(iii) File management system
(iv) Networking system
7. What is the difference between user interface system and protection system?
8. Explain briefly about the history and development of the operating systems.
9. What is SPOOLing? Explain its functions and applications.

Self-Instructional
Material 31
Introduction to Operating 10. What are the functions of time shared systems as well as single user systems?
Systems
11. Describe the advantages and disadvantages of distributed systems.
12. Describe the architecture of the virtual machine multiprogramming.
NOTES 13. Differentiate between POST and BIOS with the help of examples.
14. Explain the functions of kernel.

1.12 FURTHER READING


Silberschatz, Abraham, Peter Galvin and Greg Gagne. Operating System Concepts.
John Wiley & Sons, 2004.
Tanenbaum, Andrew S. Modern Operating Systems. Prentice Hall, 2001.
Mano, M. Morris. Computer System Architecture. New Jersey: Prentice Hall Inc.,
1993.
Peterson, J.L., Abraham SIlberschatz and Peter B. Galvin. Operating System
Concepts. New York: Addison Wesley, 1994.
Louise I. Shelly 2020 Dark Commerce

1.13 LEARNING OUTCOMES


 Operating systems
 Understand the functions of operating systems
 The role of operating system as a resource manager
 The various types of operating systems
 The structure of operating system
 Know about POST and bootstrapping processes
 Understand the functions of kernel

Self-Instructional
32 Material
Process Management

UNIT 2 PROCESS MANAGEMENT AND and Operation

OPERATION
NOTES
Structure
2.0 Introduction
2.1 Unit Objectives
2.2 Process Management
2.2.1 Process Concept
2.2.2 Multithreading Models
2.3 Process Scheduling
2.3.1 Operations on Processes
2.3.2 Concurrent Processes
2.4 Interprocess Communication
2.4.1 Communication in Client-Server Systems
2.5 CPU Scheduling
2.6 Process Synchronization
2.6.1 Critical Section
2.6.2 Semaphores
2.7 Deadlocks
2.7.1 Deadlock Prevention
2.7.2 Deadlock Avoidance
2.7.3 Deadlock Detection
2.8 Summary
2.9 Key Terms
2.10 Answers to ‘Check Your Progress’
2.11 Questions and Exercises
2.12 Further Reading
2.13 Learning Outcomes

2.0 INTRODUCTION
In this unit, you will learn about process management. Process management is an
integral part of any modern day Operating System (OS). The OS must allocate
resources to processes, enable processes to share and exchange information, protect
the resources of each process from other processes and enable synchronization among
processes. In multiprocessing systems, scheduling is used to determine which process
is to be given control of the CPU. Scheduling may be divided into three phases:
long term scheduling, medium term scheduling and short term scheduling. The
communication done between processes is known as interprocess communication.
You will also learn about process scheduling. Process scheduling or CPU scheduling
is concerned with the allocation of a CPU to processes for execution. You will be
introduced to the concept of context switching, and various scheduling algorithms,
such as First In, First Out and round robin. At a time, only one process can be
executed in a uniprocessor system. Process synchronization is a mechanism used
by the OS to ensure a systematic sharing of resources amongst concurrent resources.
A deadlock is a situation in which some processes wait for each other’s actions
indefinitely.

Self-Instructional
Material 33
Process Management
and Operation 2.1 UNIT OBJECTIVES
After going through this unit, you will be able to:
NOTES  Define the concept of process management
 Explain the functioning of process scheduling
 Describe the process scheduling, such as operations on processes and
concurrent processes
 Understand CPU scheduling
 Know about process synchronization, such as critical section and semaphores
 Discuss deadlocks

2.2 PROCESS MANAGEMENT


Process management is an integral part of any modern day Operating System (OS).
The OS must allocate resources to processes, enable processes to share and exchange
information, protect the resources of each process from other processes and enable
synchronization among processes. In order to do this, the OS must maintain a data
structure for each process which describes the state and resource ownership of that
process and which enables the OS to exert control over each process.

2.2.1 Process Concept


A process is a program that is loaded into memory for execution. In a multiuser
multitasking computer system, there will be many users and each user will be
executing many programs. The primary resources needed for executing a program
are memory and processor time apart from the standard input devices, such as
keyboard, mouse and monitor and hard disk space. Of course, you may also need
output devices, such as a printer or scanner for some programs and applications.
Memory is needed to load your program before execution. Before you load the
program for execution, you have to create an executable file out of the source
program, for example, you can create programs using C++ and the library functions.
Library function codes are already available with the program development run
time environment. These functions are normally in compiled format and can be
linked with the new program that is being developed. That is, you need not rewrite
these functions. You can simply reuse these functions in your programs. Some of
these functions will be part of the operating system which you use through a system
call. To use the operating system codes, the library function may include calls to
appropriate system call numbers corresponding to the code that you want to use.
Normally, the codes needed to perform I/O operations will be part of the operating
system for reasons of system security.

Process of Producing Executable Files


The source program (example, C or C++) is first compiled to form the object code.
This object code and library function codes are linked using a linker to produce a
relocatable machine code. This machine code is relocated so that it is suitable for
the starting memory address of the memory region to which it is to be loaded. The
loader does the relocation and loading of the program into memory. The process is
Self-Instructional depicted in Figure 2.1.
34 Material
Process Management
and Operation

Compiler

Object NOTES
Code
Library
Linker Function Code
Re-Locatable Load Module
(executable file)

Loader

Executable Memory
Image of the Program
Loaded into Memory
Fig. 2.1 Process of Producing Executable Files

Memory Image of Program


The linker output, i.e., the relocatable machine code is stored as an executable file
which mainly contains two segments of the program, namely text and data.
Relocation information and symbol table are also included in the executable file.
The memory area for loading the executable file consists of four sections, namely
text, data, stack and free space (HEAP) as shown in Figure 2.2 where memory
allocated for the execution of three programs is shown. We assume that the programs
1, 2 and 3 respectively need 1000K, 1500K and 600K of memory. Details of memory
segments within the executable image of Program 2 are shown. Memory for stack
is dynamically allocated from heap and it grows to the free heap area as we store
more local variables on the stack and create more stacks for nested invocations of
functions. Dynamically allocated data structures for static and global variables are
also allocated from heap. Different segments of a program may be loaded into
different regions of the memory, i.e., they need not occupy physically contiguous
memory address space. However, the logical memory addresses of individual
segment must be contiguous.
Process Context
Once the program is loaded into memory, it is ready for execution as other resources
needed may be requested as and when their need arise during the execution. As you
know, the role of the CPU of a computer is to fetch, decode and execute the instruction
which is pointed by the Program Counter (PC) register (also called instructor pointer
register) as long as the power is switched on. The PC will be again automatically
made to point to the next instruction to be executed in the sequence or the current
instruction, for example jump instructions will change the value of the PC to the
address of the next instruction to be executed. Again, the CPU fetches, decodes and
executes that instruction pointed to by the PC. This process is repeated again and
again. A CPU has many registers, such as general purpose accumulator registers,
stack pointer register, segment pointer registers, base pointer registers and status
registers including the PC. The CPU uses its general purpose registers to hold the
operands of instructions and the results of instruction execution. Therefore, the
values of all these registers define the state of the CPU at any instance in the
Self-Instructional
Material 35
Process Management execution. This CPU state and the values associated with the memory locations
and Operation
(variables) which are used to store intermediate values of computation constitute
the context of the program in execution.
OK
NOTES 2000K Operating
System Memory
2000K
1000K Memory
Program 1
3000K
Free Memory
3300K
Text or Code Area
Global Data Area 1500 K
HEAP Memory of
Program 2
4800K STACK Grows to Heap
Free Memory
5000K

600K Memory
Program 3
5600K

Fig. 2.2 Memory Layout for Program 1, Program 2 and Program 3

Figure 2.2 also shows the memory layout for Program 1, Program 2 and
Program 3 in which 1000K memory is reserved for Program 1, 1500K memory is
reserved for Program 2 and 600K is reserved for Program 3.
Process Control Blocks
To keep track of the executing programs (programs loaded into memory) called
processes, we use some data structures to record the attributes or properties and
context of each of the processes. This data structure for a process is called a Process
Control Block (PCB). The list or array of process control blocks for all the processes
is called the process table of the operating system. Every process in a computer
system should be given a unique identity called process identification number
(process id). This id is assigned at the creation of a process by the operating system.
This process id is actually some index inserted into the table of process control
blocks. When a process is created, a free entry (a free block) in the process table is
identified and assigned to the process. That is, with every process id there will be a
process control block to represent or record the associated process details and context.
In a multiprogramming environment, each process is given a small time period
(time quantum) for CPU execution. After that time quantum, a hardware timer
interrupts the current execution and the operating system gains control of the system,
i.e., the execution branches to the operating system code. The operating system
now selects the next process for execution from the queue of ready processes
programs that are loaded into memory and not waiting for I/O or for resources other
than CPU. For the execution of the newly selected process, the old context of that
process should be restored in the registers which now have the context of the outgoing
process due to timer interrupt. Therefore, as we normally have only one set of
hardware registers the present content of the registers (the context of the outgoing
Self-Instructional
36 Material
process) must be saved somewhere to restore the same when the CPU is again Process Management
and Operation
assigned for its execution. The PCB of a process is used to save the state/context of
its computation. The context of the newly selected process is restored from its process
control block which was saved earlier when its CPU execution was interrupted.
The contents of the memory locations of the programs are not normally changed NOTES
when the CPU is switched as different programs are loaded into different memory
regions.
Figure 2.3 shows the process table of processes in a computer system. The
memory regions of some of the processes, for example, Processes 1, 7 and 10 are
shown. The process control blocks of Processes 7 and 10 are also shown. The contents
of a PCB for classic process include:
 Process id (internal process name)
 User id of the owner of the process
 The contents of the set of all CPU registers
 Process control and resources allocation information like
o Region of memory allocated to the process (description of the address
space)
o Name of the executable file loaded into the address space
o Total time of execution and elapsed execution time, etc.
o Status (ready, waiting, CPU running, etc.) of the process
o List of parent, child and sibling processes
o List of resources like files held by the process
o Process privileges
o Interprocess communication, such as messages status
Process 0 PCB

Process 1 PCB
Memory Needed
Process 2 PCB Process 1, Total
Memory of 1000K for Executing
Process 3 PCB Program 1
Process 4 PCB

Process 5 PCB

Process 6 PCB

Process 7 PCB Process 7, Total Memory needed for


Memory of 1500K executing Program
Process 8 PCB
2. Total 1500K
Process 9 PCB

Process 10 PCB

Process 11 PCB Memory needed


Process 10, Total
Process 12 PCB Memory of 600K for executing
Program 3

Process Table
PCB of Process 7 PCB of Process 10

Process Identification Process Identification

General purpose General purpose


registers, program registers, program
counter, status register counter, status register
and stack and stack

Process control Process control


information information

Process Control Blocks of Processes 7 and 10

Fig. 2.3 Process Table and Process Control Blocks of Processes


Self-Instructional
Material 37
Process Management You have seen that a process is a program loaded into memory for execution and
and Operation
when the CPU is available it will execute the instructions of the process for a time
that is decided by the policy of operating system. That is, there will be a thread of
execution in a process. This execution thread will be executing when CPU is available
NOTES until its permitted time expires or the process makes a system call.
System Calls
A system call is a request to the operating system to execute a region of operating
system code that refers to a region of the code identified by the number of the
system call on behalf of a user process. Operating system includes the code for
various functions, such as doing Input/Output operations on I/O devices, creating
processes/threads and many other tasks. The operating system also insists that some
operations especially I/O can be done only by the OS for enforcing security of the
resources like memory and files under its control. For this purpose, a CPU has
special privileged instructions and different hardware modes of operations. For
enforcing the security of a system, a CPU should have at least two modes of
operations, namely user and monitor (operating system). Privileged instructions
can be executed only in operating system (monitor) mode. All I/O instructions belong
to the privileged instruction set. If a privileged instruction is executed in the user
mode (user programs execute in user mode) it will cause an illegal instruction
execution error interrupt which is normally called trap leading to the change of
mode to operating system mode and transfer of execution to the operating system
code. Therefore, for doing I/O the user programs request the operating system through
system calls. A system call causes a software interrupt which transfers the execution,
i.e., transfer of control to the operating system and suspends the execution of the
requested process. This process will be made to wait for the completion of I/O in a
waiting queue. When an I/O operation is completed the process will be moved to
the ready queue of processes that wait for CPU. The I/O processor not the main
CPU does the actual I/O. The OS only needs to start it. When the I/O is completed,
the I/O device informs the same to the OS through an I/O completion interrupt. The
OS then executes the interrupt handler and informs the user program about the
completion of I/O and move the process into ready queue.
A process or program can also use other important functions of OS code
through system calls. However, using a system call requires much more time than
using a library function call as the system call involves switching the system mode
from user to monitor mode and then back to the user mode after completing the
system call execution. Therefore, library functions are preferred for tasks that do
not involve privileged instruction execution. Tasks, for example I/O involve the
execution of privileged instructions and hence are permitted only through the
execution of system calls.
Types of System Calls
A system call number identifies the function that should be executed and it should
be passed in some register while making system calls. Many system calls require a
set of parameters also to be passed to them. These are passed directly through registers
or indirectly through memory or stack. For example, sys_read system call is
used to read data from a file. The file descriptor of the open file to be read, address
of the buffer where the data should be placed and the number of bytes of data that
should be read are the parameters of the sys_read system call. The call is normally
Self-Instructional
38 Material
made from the source program using library procedures with the same or similar Process Management
and Operation
name as the system call. During compilation, the library procedure is translated in
to actual system call (software interrupt instruction) with the associated parameters
placed in registers or memory locations or stack. For example, the library function
call for sys_read may be through a statement, for example count = read(fd, NOTES
buffer, nbytes). Here, the name read stands for system call refers to
(sys_read); fd is the file descriptor, and buffer is the address of the memory
buffer where data is to be placed and nbytes is the number of bytes that is to be
read from the file and the system call returns the actual number of bytes read in the
variable count. If the call fails then it returns -1 in count. The steps involved in
the execution of read system call are shown in Figure 2.4. The compiler generated
code for read(fd, buffer, nbytes) is shown in Figure 2.4 as two parts
one, the user program for read (instructions 1, 2, 3 and 4) and the other, the library
procedure for invoking system call (instructions 5, 6 and 7). Instruction 1-3 pushes
parameters on to stack. Instruction 4 calls (jump P-P) the read library function. This
function loads the system call number 3 in register A and executes sys_call
instruction and then returns to user program after the return of the system call. The
sys_call instruction (int 0 × 80) interrupts the normal execution and transfers
control (jump 6-Q) to the dispatcher of OS. The dispatcher finds the parameter in
Register A and uses it to index the system call table to find the handler (read) for
system call number 3. This read handler is executed and the control is returned
(jump R-R) back to the user space library procedure which in turn returns (jump 7-
S) to the user program.

0 open
1 Kernel
Q
2 address
write space
Dispatcher3
4 R
read
sys call table sys call handlers

Start:
1. push nbytes
2. push & buffer User
3. push fd program User space
4. call read P read
S mov -,-

P
Library
procedure
R read

Fig. 2.4 Steps Required in System Call Execution

Process Creation and Hierarchy


Normally, the operating system is fully resident in memory and does not run as a
process. However, in some OS the important core part called microkernel is only
run as a non-process and the other parts run as processes in user mode as application
Self-Instructional
Material 39
Process Management servers. This is the recent trend in operating system design. We can still consider
and Operation
the OS as the first process in the system, and the parent or grandparent of all other
processes in the system. A process can create other processes called children
processes and the children processes can again create their children and so on. All
NOTES the processes of the same parent process are called sibling processes. Process
hierarchy is depicted in Figure 2.5. The operating system creates user process for
running its own services and for executing user applications or programs. A user
process creates a child process using process creation system call. A process is an
independent unit of computation. Normally, every operating system provides support
for communication and cooperation between processes. Therefore, a programmer
can build his application as a cooperating multiprocessing application where the
application runs as more than one cooperating processes. Applications which run as
multiple processes can produce fast responses to commands and inputs because
while one process is waiting for I/O completion the other processes of the application
can continue execution. However, the additional overhead computation needed to
create and manage processes of an application may reduce the overall throughput
(the number of jobs completed per unit time) of the system.
Modern Processes
The process that we described so far has only one sequence of execution or single
thread of execution. That is, there will be execution only at one part or at the region
of one function of the code of the program. This execution thread is part of the
process. A modern process consists of the old process with many threads of execution
as the programmer desires. Here, the threads are the units of computation. They are
separated from the process. At least one thread is required to execute a process. A
programmer can develop his program in such a way as to have many sequences of
executions (threads) at different parts of the code concurrently. Threads of a process
are managed separately.
Parent Process
P0

P1 and P2 are
P1 P2 Children of P0

P3 P4 P5 P6 P7

P7 and P10 are


Children of P2

P8 P9 P10

Fig. 2.5 Process Hierarchy

Threads
A thread is created explicitly when a modern process is created. The process now
includes only the process control block data structure and the resources. A thread is
Self-Instructional different from the process. A thread requires a program counter a stack and a set of
40 Material
CPU registers for execution. A process can have more than one thread of execution. Process Management
and Operation
All the threads of a process share the address space (code and global data) of the
process. Therefore, no new address space is needed while creating a thread unlike
process creation. Hence, a thread is called a LightWeight Process (LWP). However,
each thread must have its own CPU registers, program counter and stack. So, as in NOTES
the case of processes in an uni-processor system, if only one set of CPU registers
and PC are available then the resources must be shared in a time multiplexed way.
Each thread will have a data structure called thread control block or thread descriptor.
A thread descriptor includes:
 State: A thread’s current state like ready, blocked and running time of
execution, start time, etc.
 Process: A reference to the PCB of associated process.
 List of Related Threads: A reference to the list of parent/child/sibling threads.
 Stack: The location of the base thread’s stack in the main memory.
 Other Resources: A reference to the thread specific resources.
As in the case of processes, each thread will have a thread id and its context called
thread descriptors stored in thread control block. PCBs of processes will have pointers
to the thread control blocks of their threads.

2.2.2 Multithreading Models


A program or an application may be executed as follows:
 Single process, single threaded (refer Figure 2.6 (a)).
 Single process, multithreaded (refer Figure 2.6 (b)).
 Multiple processes, each single threaded (refer Figure 2.7 (a)).
 Multiple processes, each multithreaded (refer Figure 2.7 (b)).
Diagrammatic representation of threads in processes is shown in Figures 2.6 and 2.7.

(a) Single Threaded Process (b) Multithreaded Process


Fig. 2.6 Program Executed as Single Process (a) One Thread in One Process,
(b) Multiple Threads in One Multithreaded Process

Process 1, Thread 1 Process 1, Thread 1 Multiple Processes and Multiple Thread


(multiple processes, but one thread per process) Per Process

(a) (b)
Fig. 2.7 (a) Multiple Processes with Fig. 2.7 (b) Multiple Processes with
Single Thread Multiple Threads
Self-Instructional
Material 41
Process Management Single process, single threaded
and Operation
Applications are run as a single process with a single thread to execute the code.
Only one sequence of execution is possible in such applications as shown in Figure
NOTES 2.6(a). The response time of such applications will be more, as if the thread is
waiting for a slow user input, no processing can be done on the data that is already
read. This makes the user dissatisfied in an interactive system. However, the overhead
computation is much less in single threaded execution.
Single process, multiple threads
There will be more than one sequence for code execution in this model of
computation as shown in Figure 2.6(b). This improves the response time and user
satisfaction.
Multiple processes, single thread
Processes and threads in a multiple processes single threaded application are depicted
in Figure 2.7(a). The applications will be much more responsive than the previous
single process multithreaded applications. However, the overhead of creation and
termination of processes will be much higher than threads due to the following:
 Threads of the same process share the address space of the process. Code and
global data are shared among threads of same process.
 Thread control block involves the creation of only far less data structures
than that required for a process.
 Communication between threads can be done easily through shared data
without the intervention of operating system kernel unlike the case of processes
which require kernel intervention for communication.
Multiple processes, multiple threads
Programs can also run as multiple processes multithreaded applications as illustrated
in Figure 2.7(b). The program is developed to run as two processes: one process
with two threads and the other with three threads. As there are more threads per
process, the application response time will be better than all the above three cases.
The overhead will be slightly higher than the previous multiple process multithreaded
case, as more threads are to be created and managed per process.
User Level and Kernel Level Threads
The two categories of thread implementations are as follows:
User Level Threads Model (N:1 Model): The User Level Threads (ULTs) are created
and managed by the user. Here, a process is executed as many user level threads as
shown in Figure 2.8(a) where four user threads are mapped to one kernel threads.
This is called many to one (N:1) mapping. The kernel is not aware of the existence
of user threads. These are created, managed and scheduled by the user using thread
library functions in the user space. User thread creation and termination is faster
than kernel threads as user thread creation/ termination does not involve kernel
mode change. However, the blocking of a single user thread may lead to the blocking
of the entire process.
Kernel Level Thread Model (1:1 Model): The Kernel Level Threads (KLTs) are
created and managed by the kernel itself. A user process will be executed as one or
Self-Instructional
42 Material
more kernel threads. That is, every user thread is mapped to separate kernel thread Process Management
and Operation
as shown in Figure 2.8(b). This is called one to one (1:1) mapping. Threads are
scheduled directly by kernel. No user level library is needed for the creation and
management of threads. One major advantage is that when one thread get blocked
due to a system call, the kernel may choose to schedule the other threads in the NOTES
process making applications to run faster with improved response time. However,
kernel thread creation/termination are costly as it involves the time consuming kernel
mode change.
User Threads

User Space

Kernel
Kernel Space
Thread

Process

(a) Four User Threads mapped to One Kernel Thread

User Threads

User Space

Kernel
Kernel Space
Thread
Process

(b) Every User Thread is mapped to Separate Kernel Thread

User Threads User Thread

User Space

Kernel
Space

Process Process

(c) Combined Approach


Fig. 2.8 User Level and Kernel Level Threads
Self-Instructional
Material 43
Process Management Combined Approach
and Operation
In this model of computation, both many to one mapping and one to one mapping
models are combined (Fig. 2.8(c)). Multiple user threads are mapped to more than
NOTES one kernel thread. This model is useful for parallel execution of threads on different
processors in multiprocessor systems. The number of kernel threads can be adjusted
to achieve the needed performance thus eliminating the disadvantages of pure user
thread model and pure kernel thread model.
Multithreading vs Multiple Processes
Benefits of Threads
A process provides the context for executing program instructions and managing
resources, for example memory and I/O. Every process works independently of
others in separate address space. The address space and resources of the process are
protected from the unauthorized access from other processes using memory
management techniques and access control mechanism.
However, creating a new process and scheduling it is a highly expensive
procedure in most operating systems. Communication, such as Interprocess
Communication (IPC) and data exchange between processes require special tools
and more time.
Creating a thread in the same time is much cheaper. Threads share the same
process address space, so data exchange is faster. When one thread is waiting for
I/O, the other threads can do the computation in the background.
Multithreading can impprove the response time of applications even on uni-
processor environments. Multithreading can improve the speed of computation if
more than one CPU is available. Multiple threads can run parallel on multiple CPUs
and finish the computation faster.
Disadvantages of Threads
An operating system may choose to do scheduling at the process level or at the
thread level. If scheduling is done at the process level, allocation of CPU time for
the threads will be the responsibility of the applications. In such situations, the
allocated CPU time will be shared by various threads of the process. If a system call
on one thread blocks then the entire process will be blocked as the kernel is unaware
of the threads in the process. Under such situations, a multithreaded application on
an uniprocessor environment does not improve the performance. Also, compute
bound applications on a uniprocessor would not benefit from multithreading, since
computation and communication cannot run in parallel. Moreover, with fine grain
locking (locking shared variables for almost every instruction execution) of shared
data structures (all threads share the global data structures of the process) the thread
synchronization overhead for communication and sharing will be high.

2.3 PROCESS SCHEDULING


In multiprocessing systems, scheduling is used to determine which process is to be
given control of the CPU. Scheduling may be divided into three phases: long term
scheduling, medium term scheduling and short term scheduling as shown in
Figure 2.9.
Self-Instructional
44 Material
Long Term Scheduling Process Management
and Operation
Long term scheduling, also known as job scheduling, determines the job to be
admitted for immediate processing. Typically, once the job scheduler makes a job
active, it stays active until it is terminated. The main objective of the job scheduler NOTES
is to provide the medium term scheduler with an appropriate number of jobs. If
there are too few jobs, the CPU may sit idle because all jobs are blocked. If there
are too many jobs with the overloaded memory management system, the efficiency
of the system is degraded.
Long-term Short-term
Scheduler Scheduler

Ready Queue CPU End of a Program

Suspended Queue

Fig. 2.9 Long Term and Short Term Scheduler

Medium Term Scheduling


There are running processes which require some I/O operation. In such cases, these
processes may get suspended for an I/O operation after having run for a while. They
can be suspended from the main memory and placed on a hard disk to make room
for other processes. These processes can be reloaded into memory and continued
from where they were left earlier. When you save the suspended process on a hard
disk, it is said that you have swapped out or rolled out. Swapping in and swapping
out of the processes are done by the medium term scheduler as shown in Figure
2.10.
Suspended and
Long-term Scheduler
Swapped Out Queue

Jobs End
Ready Queue CPU

Suspended Queue

Fig. 2.10 Medium Term Scheduler

Short Term Scheduling


In the short term scheduling, processes are immediately allocated to CPU from the
ready queue in order to start immediate processing. The short term scheduling
primarily aims at maximizing CPU utilization.
Context Switch
Switching the CPU to another process after saving the state of the older process and
loading the saved state of the new process is called context switch. The main features
of a context switch are as follows:
Self-Instructional
Material 45
Process Management  Context switch time is pure overhead because the system does no useful
and Operation
work while switching.
 Context switch time is highly dependent on hardware support.

NOTES 2.3.1 Operations on Processes


The two important operations provided by an operating system on processes are
process creation and process termination.
Let us look at each one in detail.
Process Creation
To create a process, we use the create process system call. The process in
which the create() system call is called is known as parent process. Create()
system call creates a new process called child process. When a child process is
created by a parent process, the parent and child processes can execute concurrently.
The child process must be terminated before the parent process. In the UNIX
operating system, the child process is created using the fork() system call and
this call is used to create a new process from an existing process (refer Figure 2.11).
The fork() system call returns 0 for child and > 0 for parent. The newly created
child process contains a copy of the address space of the parent process.

Fig. 2.11 Parent and Child in Process Creation

The following ‘C’ program creates the child process.


int main()
{
pid_t pid;
/* fork another process */
pid = fork();
if (pid < 0) {/* error occurred */
fprintf (stderr, “Fork Failed”);
exit(–1);
}
else if (pid ==0) {/ child process */
execlp (“/bin/1s”, “1s”, NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf (“Child Complete”);
exit(0);
}
Self-Instructional }
46 Material
Process Termination Process Management
and Operation
When the last instruction of the process finishes execution, the operating system
must delete it by calling the exit() system call. The abort() system call is
also used to terminate a process. The exit() system call is used to terminate itself NOTES
whereas the abort() system call is used to terminate the other process.
A parent process can be terminated only when all its child processes have
been terminated. The parent process calls the wait system call and waits for its
children to terminate. When all the child processes have terminated, the parent
process can use the exit() system call.
2.3.2 Concurrent Processes
In a multiprogramming environment, where there are more than one processors, we
can execute more than a single process. Each processor can execute a process and
multiple processors can execute multiple processes. All the processes executing in
the system simultaneously are called concurrent processes.
Concurrent processes are of two types—independent and cooperative. If a
concurrent process cannot affect or be affected by the other process executing in the
system, it is called independent process.
If a concurrent process can affect or be affected by other processes in the
system, it is called cooperating process.
A cooperating process must share data and information with other processes.
To share information, cooperating processes must communicate with each other
using interprocess communication and process synchronization techniques.

2.4 INTERPROCESS COMMUNICATION


Processes very often need to communicate with each other or with many other
processes for accomplishing their tasks. For example, the output of one process
may be input to another. The communication thus done between processes is known
as interprocess communication or IPC for short.
The issues involved in IPC are as follows:
 How to pass information between two processes; the mechanism for passing
information. Check Your Progress

 To keep away the interference from each other, i.e., protecting each process 1. What is a process?
2. What is the role of a
from the other. CPU?
 Establishing the proper synchronization between processes. For example, the 3. When is a thread
sender must send data or produce the data before a receiver can retrieve it. Or created?
the receiver must wait until the data is available. 4. What is the function
of job scheduling?
All the three issues involved in IPC are also true with the communication between 5. Which two
threads. The first issue, passing information is easy with threads as threads share operations are
global data of their process without the involvement or support of OS kernel. The provided by an
other two issues are also critical to threads. Therefore, the IPC technique can also operating system on
processes?
be applied to inter thread communication. The overheads of communication between
threads are lower than that of IPC as the latter necessarily involves the support from
OS in the form of system calls.
Self-Instructional
Material 47
Process Management IPC Mechanism
and Operation
As processes are independent and protected entities so that do not share any memory
locations for communication and they cannot communicate without the help of
NOTES operating systems. The system must impose some format for interpreting the content
of the message and some protocols to indicate the information buffer and the sender
and receiver processes involved. The actual protocol used depends on the operating
system.
Message passing is the popular technique of passing information between
processes. This technique shown in Figure 2.12 uses message boxes which are
mechanisms maintained by operating system for posting (sending) and receiving
messages. Two major system calls available for this purpose are as follows:
Process P1 Process P2
Mailbox for P2
send(info, P1,) Receive(info)
Information Information
to be Send Received
Messages

Send sys call Receive sys call


Operating System

Fig. 2.12 Interprocess Communication Mechanism

To send information to Process P2, Process P1 executes the following system calls:
Send( …, P2,..): In this system call process P1 sends a message to
process P2’s message box.
To receive the information send to process P2 by any processes, P2 executes:
Receive(.…): This system call retrieves message is retrieved from it’s
(P2’s) message box.
A process must own a mail box for receiving messages. The address of this
message box must be known to the sender process (P1 in this case). A receiver need
not know the address. It can simply execute to retrieve the message posted in its
message box.
Alternatively, message boxes may be owned by the OS, and then the receiver
can execute Receive( P1,..) with or without indicating the sender process id
and the actual protocol depends on OS.
2.4.1 Communication in Client-Server Systems
Client-server architecture consists of two different computer programs—client and
server. Client sends a service request to the server for accessing various resources.
The server fulfils the request by providing shared access to resources, such as printer,
database and modem. Client-server architecture is mainly used in a network for
efficient distribution of resources across different clients.
You can use Application Program Interface (API) and Remote Procedure Calls
(RPC) for communicating between client and server processes. API is a set of
Self-Instructional
48 Material
software functions implemented as a library used by an application program as a Process Management
and Operation
means for providing access to an operating system’s capabilities. RPC is a method
of calling the procedure located at remote location by sending service request to the
server. The components of client-server architecture are as follows:
 Client NOTES
 Network
 Server
Client contains components such as Graphical User Interface (GUI), Database
Management System (DBMS) communication package and operating system. Clients
having GUI package creates a user friendly interface with the server. DBMS
communication package is used for communicating with the server database.
Network is used for communicating the clients with the server. A network
can be Local Area Network (LAN), Wide Area Network (WAN) or the Internet. The
Transmission Control Protocol/Internet Protocol (TCP/IP) protocol is the most
commonly used protocol for communication between various users.
Server contains various components, such as authentication module, network
communication package, database package and operating system. Authentication
module verifies various clients for their verification using passwords. Database
package contains various protocols for accessing the database that includes protecting
the information from users by revoking permissions for reading and writing records.
Figure 2.13 shows the client-server architecture.

Client Client Client

Client Network Client

Client Client
Server

Fig. 2.13 The Client-Server Architecture

The advantage of using client-server architecture is that it provides flexibility and


scalability for adding essential resources in the server computer afterwards. Since,
all the computers are connected to the server and incorporating a new resource does
not need to configure the client computers.
The disadvantage of using client-server architecture is that it has complex
configuration that requires greater expertise, which results in higher cost. It is less
reliable because of the availability of large number of clients that makes the system
dependable on different clients.

Self-Instructional
Material 49
Process Management
and Operation 2.5 CPU SCHEDULING
We have seen that in a multiprogramming operating system, there will be many
NOTES programs loaded into memory called processes, making them ready for execution
when CPU is available. In some of the OS design, parts of OS will also be run as
processes. The CPU has to be shared between these user and kernel processes using
time multiplexing.
Process scheduling or CPU scheduling is concerned with the allocation of a
CPU to processes for execution. At a time, only one process can be executed in a
uniprocessor system. That is, processes will undergo many state changes during its
lifetime in the system. The lifetime of a process is the time from creation to the time
of its termination after completing its execution.
The states that a process can undergo may be depicted as in Figure 2.14.
When programs are loaded into memory, it first goes to ready state. Following a
timer interrupt or system call, the OS saves the context of outgoing process and
scheduler chooses one eligible process from the list of waiting processes in the
ready queue (refer Figure 2.14) for allocating a CPU. The context of the selected
process is restored and the time interval for execution is loaded in the timer. The OS
then transfers control to the selected process. Instructions of the selected process
will be executed until the occurrence of timer interrupt after the expiry of the allotted
time or the process makes a system call. The process will be moved directly to the
ready queue (normally to the tail of the queue or to a position as decided by the
scheduling algorithm) following the timer interrupt. System calls are made for the
execution of the operating system code on behalf of the process. Following the
system calls, the process will be normally moved to the I/O waiting state for the
completion of the call. system call exit() terminate the process (as process
execution completed) and move the process out of the scheduling queues. When I/
O or other requested operations are completed, the waiting process will be moved
to the ready queue waiting for execution on the CPU. Meanwhile, the scheduler
again chooses the next process from the ready queue, restores context, reloads timer
and transfers control to the process. The above scheduling process continues as
long as there are processes in the ready list otherwise, the OS does its own low
priority background work and then waits for the arrival of user processes in the
ready queue (ready list).
Preemption Due to
Timer Interrupt
Process Running

New Ready List Scheduler CPU


of Processes Done,
Terminated

I/O Request

Processes Waiting
for I/O
I/O Completed
Waiting or
Blocked List
Fig. 2.14 Process Scheduling Diagram showing Three States of Processes
Self-Instructional
50 Material
Scheduling Criteria Process Management
and Operation
The scheduling strategy of a system is chosen to satisfy the following performance
criteria or goals of scheduling:
 Utilization/Efficiency: Keep the CPU busy 100 per cent of the time with NOTES
useful work.
 Throughput: Maximize the number of jobs completed per unit time.
 Turnaround Time: From the time of submission to the time of completion.
 Minimize the Time: In this, the batch user waits for output.
 Waiting Time: Minimize the time spent in ready queue.
 Response Time: Time from submission till the first response is produced;
minimize response time for interactive users.
 Fairness: Make sure each process gets a fair share of the CPU.
Context Switching
There are several tasks to perform in a computer system. Therefore, if one process
requires some I/O operation we want to initiate the I/O operation and go on to the
next process for execution. The resumption of the interrupted task will be again
taken for execution on the CPU later after the completion of the system call and by
moving the process again to the ready queue. This act of switching from one process
to another is called a context switch. When the scheduler again selects the process,
the execution must resume the instruction from where it left last time. For all practical
purposes, this process should never know there was a switch and it should look like
this was the only process in the system. To implement this, on a context switch we
have to save the context of the current process, select the next process to run and
restore the context of this new process.
Saving the context of the current process and restoring the context of the
incoming new process is called a full context switch. The context of a process is
usually the following:
CPU registers includes PC, stack pointer and status registers, stack, program
code, data, state of the process and the information of the resources, such as files
and allocated devices. All this information is stored in a structure called PCB. All
the above has to be saved following a hardware or software interrupt and restored
when a new process is selected for execution.
Code, data and stack will be in the memory address space of the process and
hence need not be saved separately during a context switch, if memory is not pre-
empted. Information in the CPU registers is to be saved and restored during a context
switch as these registers are required for the use of incoming process execution.
Other information is already available in the PCB, which is maintained in the OS
address space.
Non-pre-emptive vs Pre-emptive Scheduling
Non-pre-emptive: Non-pre-emptive algorithms are the one in which once the CPU
starts the execution of the process, it is not forcibly taken from the process; the
process is allowed to complete the execution as long as the process does not block
or terminate. A context switch is done only when the process terminates or blocks.

Self-Instructional
Material 51
Process Management Pre-emptive: Pre-emptive algorithms are driven by the notion of prioritized
and Operation
computation. The process with the highest priority should always be the one currently
using the processor. If a process is currently using the processor and a new process
with a higher priority enters the ready list, the process running on the processor
NOTES should be removed and returned to the ready list. This process is executed again
when it again becomes the highest priority process in the system. Context switch is
done even when the process execution is interrupted via timer interrupts.
Scheduling Algorithms
We can have various scheduling algorithms for choosing the next job for execution
from the list of ready processes. Most common algorithms are the following:
 First In, First Out (FIFO)
 Round Robin (RR)
 Shortest Job First (SJF)
 Multilevel Feedback Queues (MFQ)
SJF and MFQ are priority scheduling algorithms.
First In, First Out
This is a non-pre-emptive scheduling algorithm. First In, First Out (FIFO) strategy
assigns priority to processes in the order in which they request the processor, i.e.,
the order in which processes arrive in the ready queue. The process that requests the
CPU first is allocated the CPU first. When a process comes in, PCB (only a pointer
to PCB like process id) is added to the tail of ready queue. When the running
process terminates, take the process at the head of ready queue and run it.
Consider the example of three processes with execution time as follows:
P1=18, P2=7, P3=5
The total time required to complete the execution of all the three processes is 30
time units. CPU is given to P1 during 0–18 time units, to P2 during 19–25 time
units, and to P3 during 26–30 time units. The Gantt chart for First Come First
Served (FCFS) is shown in Figure 2.15.
P1 = 18, P2 = 7, P3 = 5

P1 P2 P3
0 10 20 25 30

Fig. 2.15 Gantt Chart for FCFS Scheduling

Average Turnaround Time: Turnaround time of a job is the time taken for
completion since the submission for execution. Assume that all the processes (jobs)
have arrived at time zero (at the same time) in the order P1, P2 and P3.
The turnaround time for each of the processes is calculated as follows:
Turnaround time for P1 = 18
Turnaround time for P2 = 18 + 7 = 25

Self-Instructional
52 Material
Turnaround time for P3 = 18 + 7 + 5 = 30 Process Management
and Operation
Average Turnaround Time or ATT = (18*3 + 7*2 + 5*1) / 3 = 73/3 = 24.33
In general, turnaround time is given by the following formula:
ATT= (n*a + (n-1)*b + ) / n NOTES
Here, a, b,… are the execution time of the processes P1, P2,…..Pn given in the
order of their arrival and order of execution.
If we want to minimize this ATT, a should be the smallest, followed by b, and
so on. That is, FCFS cannot give minimum turnaround time, as it is not ordered in
the ascending order of time.
Average Response Time: Response time is the time to start producing the first
response since the submission of jobs. As the jobs have arrived at the same time, the
response time for P1 is zero, for P2 is 18 and for P3 is 25.
Average response time = (0 + 18 + 25)/3 = 14.33
FCFS algorithm is simple to implement; however, the average turnaround
time is high and average response time is unacceptably high. Another serious
drawback of this algorithm is that one process can monopolize the use of CPU. A
process with large execution time will block the execution of all processes arrived
after it for a long time.
The poor response time makes the algorithm unsuitable for interactive jobs.
A solution for this is to limit the amount of time a process can run without a
context switch. This time is called a time slice or time quantum and the resulting
algorithm is called round robin.
Round Robin
Round Robin (RR) allocates a CPU to each of the jobs for the duration of a time
quantum or time slice. That is, CPU time is distributed equally among all the
processes in the ready queue. The basic algorithm works like this: The algorithm
takes the process at the head of the ready queue and runs it for one time slice and
then moves it to the tail of the ready queue; then takes the next process at the head
of the queue, runs it for one time slice and so on. Each process gets equal share of
the CPU. Most systems use some variant of this.
Choosing the right value for time slice is important for achieving good
performance and for reducing the overheads. A large value for time slice may decrease
the I/O utilization and a too small value will increase the overheads substantially
due to frequent context switching. For example, consider two processes: one doing
1 unit of computation followed by 5 units of I/O, the other doing only computation.
Suppose we use 10 unit time slice and round robin scheduling. Gantt chart is shown
in Figure 2.16. The I/O process runs during 6 time slices out of every 11 time slices.
That is, the I/O devices are utilized only for 5 time slices out of 11 slices. The I/O
intensive process has to wait for another 5 time slice for CPU operations.

Self-Instructional
Material 53
Process Management P1: Alternate bursts of 1 unit computation, 5 unit I/O
and Operation P2: Only computation bursts

P1
NOTES
P2

1 6 11 17 22 28 33 39
Round Robin Time Slice = 10 Units

I/O Execution CPU Execution


Fig. 2.16 Round Robin with 10 Unit Time Slice

Now, consider the case of 1 ms time slice. The Gantt chart is shown in Figure 2.17.
The compute bound process now gets interrupted 4 times unnecessarily before
I/O bound process is runnable. So, a small time slice increases the overheads due to
the computations needed for switching processes after each of the timeout interrupts.
However, the response time of I/O bound job has improved over the previous 10
unit time slice case.
Round robin assumes that all processes are equally important and each receives
an equal portion of the CPU. However, this sometimes produces bad results in
terms of the average turnaround time. As an example, consider three processes A, B
and C that start at the same time and each requires four time slices to finish. We will
compute the turnaround time and response time for the cases of FCFS and RR and
compare their performance with respect to turnaround time and response time.
P1: Alternate bursts of 1 unit computation, 5 unit I/O
P2: Only computation bursts

P1

P2

1 6 7 12 13 18 19

Round Robin Time Slice = 1 Unit

I/O Execution CPU Execution


Fig. 2.17 Round Robin with 1 Unit Time Slice

Figure 2.18 shows the Gantt charts for FIFO and RR respectively which depicts
a comparison overview of time and jobs performances.

Self-Instructional
54 Material
FIFO: Time Process Management
and Operation
0 1 2 4 5 6 7 8 9 10 11 12
Jobs A
B
C NOTES
ATT = (4 + 8 + 12)/3=8
Round Robin:
0 1 2 4 5 6 7 8 9 10 11 12
A
B
C

ATT = (10 + 11 + 12)/3 = 11


Fig. 2.18 Comparison of FIFO and RR

FIFO
Turnaround Time: Process A finishes after 4 slices, B after 8 slices and C after 12
slices. The average turnaround time is (4+8+12)/3 = 8 slices.
Average response time: ( 0 + 4 + 8 )/3 = 4
Round Robin
Turnaround Time: Process A finishes after 10 slices, B after 11, and C 12 so the
average is (10+11+12)/3 = 11 slices.
Average response time: ( 0 + 1 + 2 )/3 = 1
The values of turnaround time and response time clearly indicate that round
robin treats all processes with fairness and provides good response time but
turnaround time is lower than FCFS.
Priority Based Scheduling
In this, every process is assigned a priority and the highest priority job in the ready
queue is assigned the CPU until its completion or until when it requests for I/O or
makes other system call. Round robin or FCFS may be used among processes with
equal priority. The process will be reinserted in the ready queue behind all processes
of greater or equal priority. Priority scheduling permits the allocation of more CPU
time to important processes. Priorities are assigned to processes externally and not
based on OS policy for improving overall performances and fairness. So, there is a
chance that some of the lower priority jobs/processes will be denied CPU for a long
time. This is called starvation of processes.
A solution to starvation in priority scheduling is aging. In this, the priority of
each process is incremented based on its waiting time. So, after long wait in the
ready queue every process will attain the priority required for getting it scheduled.
Multilevel Feedback Queue
In Multilevel Feedback Queue (MFQ), several queues are arranged in some priority
order. Each queue can have a different scheduling priority and time quantum.
Generally, a lower time quantum is given for higher priority jobs as shown in
Figure 2.19.

Self-Instructional
Material 55
Process Management Scheduling Queue 1, Highest Priority Process Terminated
and Operation time quantum = 3 ms
Admit Job
CPU

NOTES Scheduling queue 2


time quantum = 10 ms
CPU

Scheduling queue 3
time quantum = 50 ms
CPU

Scheduling queue 4
time quantum = 100 ms
CPU
Lowest Priority

Fig. 2.19 Multilevel Feedback Queue

A multilevel feedback queue is defined by the following factors:


 The number of queues.
 Scheduling algorithm for each queue.
 When to upgrade a priority and move the job to higher priority queue.
 When to decrease priority and move the job to lower priority queue.
Multilevel feedback queue addresses both efficiency and response time problems.
Processes that arrived recently are given high priority and very low time slice. If a
process uses up the time slice without blocking then the priority may be decreased
Check Your Progress so that the process will be moved to the lower priority queue where it will be
6. State any one issue scheduled for a larger time quantum. This is normally implemented using separate
involved in IPC. queues for each priority and time slice as shown in Figure 2.19. Four queues are
7. Name the computer used with different priorities and different time quanta for processing with multiple
programs found in
feedback queue. The lowest priority queue may be scheduled using FCFS.
client-server
architecture. A process in a lower priority queue may be increased, based on aging or it
8. What is the variants. One approach may be to increase the priority by one level, if the process
advantage of using
does not use time slice in the present queue for a long time.
client-server
architecture? A process with heavy CPU operations at the beginning and then waits for I/O
9. What is the lifetime may find itself at the bottom lowest priority queue. The priority of such a process
of the process? must be increased to a high value when the process returns from I/O.
10. What is a full
context switch?
11. In what type of 2.6 PROCESS SYNCHRONIZATION
processes is round
robin or FCFS
used?
Process synchronization is a mechanism used by the OS to ensure a systematic
12. What types of
sharing of resources amongst concurrent resources. When the correctness of the
problems are computation performed by cooperating processes can be affected by the relative
addressed by timing of the processes execution, it is referred to as a race condition.
multilevel feedback
queue? Several processes access and manipulate the shared data concurrently. The
final value of the shared data depends upon which process finishes last. In order to
prevent race conditions, it is essential that concurrent processes are synchronized.
Self-Instructional
56 Material
Racing Problem Process Management
and Operation
Let us consider two processes P0 and P1 which are accessing the same integer
value A.
Let A=1000 NOTES
P0 : Read (A);
A: = A – 100;
Write (A);
P1 : Read (A);
A: = A + 200;
Write (A);
The execution of these two processes will result in the change of value of A as
A=1100. This will only happen if P0 and P1 will execute in any one of the following
sequences:
(a) P0 followed by P1
(b) P1 followed by P0
But, if P0 and P1 are allowed to execute in an arbitrary fashion then there would be
the following two possibilities:
Possibility 1:
P0: P1:
Read (A);
Read (A);
A=A–100;
Write (A);
A=A+200;
Write (A);
The sequence followed is: P0, P1, P0, P1 the end result value of A is 1200 which is
wrong.
Possibility 2:
P0: P1:
Read (A);
Read (A);
A = A + 200;
Write (A);
A = A – 100;
Write (A);
The sequence followed is P0, P1, P0 which leads to A = 900. This is again wrong.
Such a situation is called a racing problem which should be avoided.
Self-Instructional
Material 57
Process Management 2.6.1 Critical Section
and Operation
It is basically a sequence of instructions with a clear indication of beginning and
end for updating shared variables. In critical section, only one process is allowed to
NOTES access the shared variables and all others have to wait. This condition is known as
mutual exclusion which ensures that at most one process at a time has access to it
during critical updates, i.e., it helps the system to maintain its integrity by allowing
only one process to share the common resources.
Problems of Critical Section
Any mechanism to control access to critical sections must satisfy the following
three requirements so that it can be ensured:
 Mutual Exclusion: When one process is in a critical section that accesses a
set of shared resources, no other processes can be in a critical section accessing
any of those shared resources.
 Progress: When no processes are in its critical section and one or more
processes are waiting to enter the critical section. A process that terminates
outside its critical section may not prevent other processes from entering
their critical sections.
 Bounded Wait: When a process requests access to a critical section, a decision
that grants it access may not be delayed indefinitely.
A process may not be denied access due to starvation or deadlock.
Process A Enters Process A Leaves
the Critical Region Critical Region
Process A
Process B Attempts
to Enter the Critical Region

Process B Enters Process B Levels


Critical Region Critical Region

Process B
Process B Blocked

T1 T2 T3
Time

Fig. 2.20 Mechanism to Control Access to Critical Section

Initial attempts to solve the problem of critical section were to have only two
Processes P0 and P1 with the general structure as follows:
do {
Entry Section
Critical Section
Exit Section
Remainder Section
} While (1);

Self-Instructional
58 Material
Processes may share some common variables to synchronize their actions. Process Management
and Operation
 Entry Section: This refers to the code segment of a process that is executed
when the process intends to enter its critical section. This code appears at the
entry of a critical section. The execution of this code checks whether or not
the process has the eligibility to enter the critical section. NOTES
 Critical Section: This refers to the code segment where a shared resource is
accessed by the process. At a time, only one of the cooperating process can
enter into the critical section. Hence, the shared resource is being used by
only one process.
 Remainder Section: This is the remaining part of a process’s code. When a
process is executing in this section, it implies that it is not waiting to enter its
critical section. Hence, the processes in the remainder section are not
considered to enter into the critical sections.
Critical Section Algorithms
Following algorithms are discussed in critical section:
Algorithm 1:
This algorithm is applicable for only two processes P0 and P1. Both are cooperating
through a shared integer variable ‘turn’. At a time its value will be either 0 or 1.
If turn equals 0, P0 enters the critical section, and if the value is 1, then P1 enters
the critical section.
P0: do {
While (turn = = 1); /* keep looping as long as turn
equals 1*/
/* this is entry section*/
< Critical section >
Turn = 1; /* P1 enters into the critical section*/
/* this is Exit Section*/
< Remainder Section >
} While (1);
P1: do {
While (turn = = 0); /* keep looping as long as turn
equals 0 */
/* this is the Entry Section */
< Critical Section >
Turn = 0; /* P0 enters into the critical
section*/
/* this is Exit Section*/
< Remainder Section >
} While (1);
Let us observe the three conditions for controlling access to critical section:
 Mutual Exclusion: The value of turn is either 0 or 1. Hence, at a time only
one cooperating process will be there in the critical section. Thus, the
requirement of mutual exclusion is satisfied.

Self-Instructional
Material 59
Process Management  Progress: Here the two cooperating processes are entering strictly alternatively
and Operation
only. In other words, if the value of turn is 0, then P0 enters and if the value of
turn is 1, P1 enters the critical region. Hence, a sequence followed is: P0, P1,
P0, P1, P0, P1 . . . and if the initial value of turn is 1, then sequence followed
NOTES is: P1, P0, P1, P0, P1, P0……
Consider the following two situations:
o Turn = 0 but P1 tries to enter the critical section earlier than P0; it cannot,
until P0 enters the critical region, executes and exits the critical region
and changes the value of turn to 1.
o When P0 exits the critical region, it changes the value of turn to 1. Suppose
at this point, P1 is executing in its remainder section and does not want to
enter into the critical region again but since the value of turn is set to 1
then no process is executing in the critical region at this time. But still P0
cannot enter the critical region until and unless P1 enters the critical region
and it sets the value of turn equal to 0. Thus, this is the situation that no
cooperating processes are in the critical-section but still P0 has to wait.
So, the requirement of progress is not satisfied.
 Bounded Wait: Suppose a process P0 requests to enter the critical section.
There are two possibilities:
o If turn = 0, then P0 immediately enters the critical section.
o If turn = 1, then P1 enters the critical section. In this way, P0 has to wait
until P1 finishes executing in the critical section. Once exited, the value
of turn is changed to 0 and P0 can enter into critical section. Hence, the
requirement of bounded wait is met.
Algorithm 2:
This algorithm also works for only two processes. This takes into consideration as
to who wants to enter the critical section. Boolean variables flag [0] and flag
[1] are used to synchronize the two cooperating processes. Initially, they are set to
false and are accessible to both the cooperating processes.
Whenever a process P0 intends to enter its critical section, it sets its flag[0]
which is accessible to process flag [1] also. Now, the process P [0] will
examine the flag[1] of the other cooperating process P [1]. If flag[1] is
not set, then P [0] enters its critical section immediately. Else, if flag[1] is
also found to be set, it indicates that P [1] is also interested to enter its critical
section. In that case,
P [1] has to wait till flag[1] is cleared by P [1].
Typedef enum Boolean {false, true};
Boolean flag [2]; /* initially both set to false*/
P0:
do {
flag [0] = true; /* intend to enter critical section*/
while (flag [1]); /* keep looping as long as flag is
true*/
/*Entry Section*/
< Critical Section >
flag[0] = false; /* Exiting from the critical section*/
< Remainder Section >
Self-Instructional
60 Material
} while (1); Process Management
and Operation
P1:
do { flag [1] = true;
while (flag[0]) /* keep looping as long as flag is true*/
NOTES
/* Entry Section */
< Critical Section >
flag[1] = false; /* Exiting from the critical section*/
< Remainder >
} while (1);
Let us observe the three conditions for controlling access to critical section:
(a) Mutual Exclusion: The value of Flag is either 0 or 1, i.e., either flag[0]
is set or flag[1] is set. Hence, at a time only one cooperating process will
be there in the critical section. Thus, the requirement of mutual exclusion is
satisfied.
(b) Progress: Let us observe when process P0 is running and it wants to enter in
its critical section. It executes the statement flag[0] = true, and is pre-
empted thereafter prior to execution of “while” statement. Now, if P[1] is at
RUN state. P[1] also intends to enter the critical section, and sets flag[1]to
true. Now both the processes flag are set to true but none is in the critical
section hence deadlock as both will continue looping in the while statement
each waiting for the other to reset its flag. This is the situation when none is
in the critical section, both waiting to enter, but none is able to enter. So, the
requirement of progress is not met.
(c) Bounded Wait: When process P0 sets its flag [0] to true. it checks for
flag [1].
There are two possibilities:
(a) flag [1] is ‘false’. P0 enters its critical section immediately.
(b) flag [1] is ‘true’. Process P1 is executing in its critical section.
Now, p0 waits for the moment when P1 exits its critical section, resets its flag
[1] to false, thus enabling P0 to enter its critical section. Thus, after P0 indicates
its intention to enter its critical section, and before it enters, P1 can enter critical
section at most once. Hence, the requirement of bounded wait is met.
Unfortunately, a distinct possibility exists that both processes may set their
Flags to true almost simultaneously, thus preventing each other from entering their
respective critical section (a deadlock).
An algorithm is required for breaking the tie in case of a deadlock. Peterson’s
algorithm serves this purpose. It has a synchronism mechanism to take into
consideration both ‘who intends to enter the critical section’ and ‘who should enter
the critical section’.
Algorithm 3:
Following algorithm is known as Peterson’s algorithm:

Int turn: /* initial value does not matter*/


Boolean flag [2]; /* initially set to false*/
P0: Self-Instructional
Material 61
Process Management do { flag[0] = true; /*intend to enter critical
and Operation section*/
turn = 1;
while ( flag[1] && turn= =1); /* keep looping as long
NOTES as flag[1] is set to true && turn equals 1*/
/* Entry Section*/
< Critical Section >
flag[0] = false; /* exiting from critical
section*/
< Remainder Section >
} while (1);
P1:
do { flag[1] = true; /*intend to enter critical
section*/
turn = 0;
while ( flag[0] && turn= =0); /* keep looping as long
as flag[0] is set to true && turn equals 0*/
/* Entry Section*/
< Critical Section >
flag[1] = false; /* exiting from critical
section*/
< Remainder Section >
} while (1);
This algorithm meets all the three requirements of an ideal critical section solution.
Here, if both processes set their flag to true, then the value of turn will break the tie
since it can assume only one value, either 0 or 1.
If both flags are set to true and turn equals 0, then P0 is allowed to enter the
critical section. If the value of turn equals 1, then P1 proceeds.
2.6.2 Semaphores
A semaphore represents an abstraction of many important ideas in mutual exclusion.
It is a protected variable which can be accessed and changed only by operations. It
also controls synchronization by using an abstract data type. The synchronization
tool called semaphore is used for the solution of the critical section problem, as
discussed in the hardware based solution using TestAndSet() and Swap()
instructions. A common example of a semaphore is the flag like signalling device
that is used by railroads for indicating whether or not a track is clear. In case the
track is clear, the semaphore’s arm is raised. On the other hand, if the track is not
clear or is busy then the arm of the semaphore is lowered and the train is not allowed
to proceed.
In an operating system, if a resource is free then the semaphore signals and
can be used by the process.
Binary Semaphore
A semaphore is a non-negative integer variable upon which two atomic operations,
wait and signal, are defined.
Self-Instructional
62 Material
int S = 1; /* Let S be a binary semaphore, initialized to Process Management
1*/ and Operation

wait (S); while S< = 0 do no operation S = S–1;


A semaphore is an integer variable that accepts non-negative integer values only by
NOTES
using two standard atomic operations: wait() requesting to enter into the critical
section, then process Pi has to wait. So, at a time only one process will be executed
or allowed to enter into the critical section. Process Pi will repeatedly check for the
semaphore value to become 1. Then the value will be decremented by 1 by the
statement (S=S–1) and the process will be allowed to enter into the critical section.
The above mentioned two instructions are executed atomically in order to ensure
that no two waiting processes find the semaphore value as 1.
Signal (s); S = S + 1;
This primitive is executed only when a cooperating process is exiting from the
critical section. This operation increments the value of semaphore to 1 in order to
ensure that only one of the waiting processes enters into the critical Section.
A process Pi can be synchronized to provide access to its critical cection, as
follows:
do{
Wait (& S) ;
<Critical Section>
Signal (&S);
<Remainder Section>
} while (1);
Let us observe the three conditions of an ideal critical section solution:
 Mutual Exclusion: If no process is executing in critical section, semaphore
value will be 1. The first process, executing wait operation, will decrement
the value to 0 and enter its critical section. The process, which execute ‘wait’
operation while a cooperating process is executing in its critical section, will
find the semaphore value to be 0 and keep looping in the ‘while’ loop of
‘wait’ operation. Due to this ‘spinning’ of a waiting process in the ‘while’
loop, the binary semaphores are also known as ‘spin locks’. ‘Signal’
operation is executed as soon as a process exits from a critical section. The
value of semaphore is incremented to 1. One of the processes in ‘while’
statement of ‘wait’ operation will find the value to be 1, exits the ‘while’
loop, decrements the value by 0 and enters the critical section.
‘Wait’ operation is to be executed atomically. The other processes will now
find the value of semaphore as 0 and continue to loop in the ‘while’ loop. It
means that at a time only one cooperating process is executing in the critical
section, subject to satisfaction of the condition that ‘wait’ operation is
executed atomically. So, the requirement of mutual exclusion is met.
 Progress: When in the critical section, there is execution of any process, the
semaphore value is 1. Then, one of the waiting processes, looping in the
‘while’ loop of ‘wait’ operation, will find the semaphore to 0 and enter
the critical section. So, if there is no execution of any process in the critical
Self-Instructional
Material 63
Process Management section, then one of the waiting processes will soon occupy its critical section.
and Operation
Thus, the requirement of progress is met.
 Bounded Wait: One of the waiting processes will get an arbitrary entry into
its critical section when a cooperating processes executing in its critical section
NOTES
exits. This selection of a process being arbitrary, a process waiting to enter its
critical section is likely to face starvation. So, the requirement of bounded
wait is not met.
Implementation of Semaphores with a Waiting Queue
The main disadvantage of the semaphore definition is that it requires busy waiting.
In other words, a process in critical section prevents all other processes from entering
the critical section. Hence, the process should necessarily loop continuously in the
entry code. Such a looping faces a severe problem in a real multi programming
system, in which various processes have to share a single CPU. In such a semaphore,
the process has to spin while awaiting the lock. This is why this type of semaphore
is also termed as spinlock.
In order to overcome the problem of busy-waiting, the process has the feature
to block itself. The process is placed in the waiting queue associated with the
semaphore by the block operation. Now the process is in the waiting state. The
control is transferred to the CPU scheduler which selects another process to execute.
This blocked process, waiting on a semaphore S, should be restarted when
some other process executes a signal() operation. The process is restarted by
wakeup() operation which changes the state of the process from waiting to ready
state. The process is now located in the ready queue (refer Table 2.1).
Table 2.1 Implementation of Semaphores

Action Results

State Calling Operations Running in Blocked Value of S


Number Process Critical Region on S

0 1
1 P1 P(S) P1 0
2 P1 V(S) 1
3 P2 P(S) P2 0
4 P3 P(S) P2 P3 0
5 P4 P(S) P2 P3, P4 0
6 P2 V(S) P3 P4 0
7 P3 P4 0
8 P3 V(S) P4 0
9 P4 V(S) 1

Self-Instructional
64 Material
Table shows that P3 is placed in the Wait state on State 4. In States 6 and 8, when a Process Management
and Operation
process exits the critical region, the value of S is reset to 1 indicating that the critical
region is free. This, in turn, triggers the awakening of one of the blocked processes,
its entry into the critical region and the resetting of S to zero. In State 7, processes
P1 and P2 are not trying to do processing in that critical region and P4 is still NOTES
blocked. After State 5, the longest waiting process, P3, was the one selected to enter
the critical region but that is only possible in case FCFS algorithm is used. In fact,
this purely depends on the choice of the algorithm used by the process scheduler.

2.7 DEADLOCKS
A deadlock is a situation in which some processes wait for each other’s actions
indefinitely. In real life, deadlocks can arise when two processes wait for phone
calls from one another or when persons crossing a narrow bridge in opposite
directions meet in the middle of the bridge. Deadlock is more serious than indefinite
postponement or starvation because it affects more than one job. Because resources
are tied up in deadlocks, the entire system is affected.
Processes involved in a deadlock remain blocked permanently which affects
the throughput, resource efficiency and the performance of the operating system.
A deadlock can bring the system to standstill.
Operating system handles only deadlocks caused by sharing of resources in
the system. Such deadlocks arise when some conditions concerning resource requests
and resource allocations are held simultaneously.
Deadlock detection detects a deadlock by checking whether all conditions
necessary for a deadlock hold simultaneously. The deadlock prevention and deadlock
avoidance ensure that deadlocks cannot occur, by not allowing the conditions for
deadlocks to hold simultaneously.
The most common example for deadlock is a traffic jam. In the Figure 2.21
shown below, there is no proper solution to a deadlock; no one can move forward
until someone moves out of the way, but no one can move out of the way until either
someone advances or a rear of a line moves back. Only then can the deadlock be
resolved.

Fig. 2.21 A Classic Case of Traffic Deadlock


Self-Instructional
Material 65
Process Management Thus, we can say that a deadlock refers to a situation in which two or more competing
and Operation
actions are waiting for the other to finish and thus neither ever does this. For example,
consider about the two trains approaching each other at a crossing. In this situation,
both the trains stop and none of them can restart until the other has gone.
NOTES In computer science, deadlock refers to a specific condition when two or
more processes are each waiting for another to release a resource or more than two
processes are waiting for resources in a circular chain.
Following are the examples of deadlock:
 The occurrence of deadlocks is common in the multiprocessing system. The
reason for this is that in the multiprocessing system, several processes have
to share a specific type of mutually exclusive resource known as a software,
or soft, lock. There often exists a hardware lock (or hard lock) in computers
that intend for the time sharing and/or real time markets. This lock provides
an exclusive access to processes. This leads to a forced serialization. Deadlocks
create troubles as we lack a general solution to this problem.
 Think of two people drawing diagrams with only one pencil and one ruler
between them. If one person possesses the pencil and the other possesses the
ruler, this would lead to a deadlock if the person having the pencil needs the
ruler and vice versa. As it is not possible to satisfy both the requests, a deadlock
is inevitable.
 In case of telecommunications, deadlock is a little more complex. Here,
deadlock occurs when neither of the processes meets the condition for moving
to another state as described in the process’s finite state machine and each
communication channel is empty. The second condition is ignored in case of
other systems but is very important in the context of telecommunications.
 We may consider an example of a deadlock in database products. Client
applications using the database may need an exclusive access to a table. To
acquire such an access, a lock may be demanded by the applications. Think
of a client application holding a lock on a table and attempting to obtain the
lock on a second table which is already held by a second client application.
This may lead to deadlock if the second application tries to obtain the lock
possessed by the first application. However, this particular type of deadlock
is easily prevented, for example, by using an all or none resource allocation
algorithm.
Characteristics of a Deadlock
A deadlock occurs when the following four conditions are met:
 Mutual Exclusion: Each resource is allocated to only one process at any
given point of time.
 Hold and Wait: The previously granted resources are not released by processes.
 No Pre-emption: The previously granted resources are not taken away from
the processes which hold them.
 Circular Wait: There exists a chain of two or more processes. These processes
should exist in such a way that each process in the chain holds a resource
requested by the next process in the chain. There must exist a set (P0, P1, P2,
P3,……., Pn) of waiting processes such that P0 is waiting for a resource that
Self-Instructional
66 Material
is held by P1, P1 is waiting for a resource that is held by P2, ............ Pn–1is Process Management
and Operation
waiting for a resource that is held by Pn and Pn is waiting for the a resource
that is held by P0.

R1 NOTES
P1 P1

R4 R2

P1 P1
R3

Fig. 2.22 Circular Wait

Resource Allocation Graph


Resource Allocation Graph (RAG) is very useful tool which helps in characterizing
allocation of resources. This graph was introduced by Holt. It is a directed graph
which describes a state of the system of resources as well as process. Each and
every resource and process is represented by a node.
Three events concerning resource allocation can occur in a system: request for a
resource, allocation of a resource and release of a resource. Table 2.2 summarizes
the request allocation and release of resources.
Table 2.2 Request Allocation and Release of Resources
Request A process requests a resource through a system call. If the resource is
free, the kernel allocates it to the process immediately; otherwise, it
changes the state of the process to block.
Allocation The process becomes the holder of the resource allocated to it. The
resource state information gets updated and the process’ state changes
to ready.
Release A process releases a resource through a system call. If some processes
are blocked on the allocation event for the resource, the kernel uses
some tie-breaking rule, e.g., FCFS allocation, to decide which process
should be allocated the resource

Symbols used in RAG


Following symbols are used in RAG:

 Process

 Resource type with four instances

Request Edge
 Pi requests instances of Rj Pi

Assignment Edge
 Process Pi is holding an instance of Rj
Pi
Self-Instructional
Material 67
Process Management Basic Facts:
and Operation
Following are the basic facts of RAG:
 If a graph contains no cycles, no deadlock.
NOTES  If a graph contains a cycle then,
o If only one instance per resource type then a deadlock.
o If several instances per resource type possibility of a deadlock
Possibility 1 for a Deadlock
Figure 2.23 shows the probability 1 for a deadlock.
R1 R3

P1 P2 P3

R2 R4
Fig. 2.23 Possibility 1 for a Deadlock

E = {P1  R1, P2  R3, R1  P2, R2  P2, R2  P1, R3  P3}


Two possibility cycles are as follows:
 P1  R1  P2  R3  P3  R2  P1
 P2  R3  P3  R2  P2
Possibility 2 Cycles but no Deadlock
Figure 2.24 shows probability 2 for a deadlock.

R1
P2

P1 P3
R2

P4

Fig. 2.24 Possibility 2 for a Deadlock

Cycle is P1  R1  P3  R2 P1.
No deadlock, observe that process P4 may release its instance of resource
type R2. That resource can then be allocated to P3 breaking this cycle.
Self-Instructional
68 Material
Methods for Handling Deadlocks Process Management
and Operation
Following are the methods to handle a deadlock:
 Deadlock Prevention: It ensures that the system will never enter a deadlock
state. NOTES
 Deadlock Avoidance: It allows the system to avoid a deadlock.
 Deadlock Detection: It allows the system to enter a deadlock and then recover.
o Ignore the problem and pretend that deadlock never occur in the system
can be considered as good solution.
2.7.1 Deadlock Prevention
Let us discuss the four conditions that should be met in order to produce a deadlock:
Mutual Exclusion
 It is not required for sharable resources.
 It must hold for non-sharable resources.
Hold and Wait
 Require a process to request and be allocated all its resources before it
begins execution or allow process to request resources only when the
process has none.
 It may lead to low resource allocation.
 Starvation is a problem. A process may be held for a long time waiting for
all its required resources.
 If it needs additional resources, it releases all of the currently held resources
and then requests all of those it needs; one should be aware of all the
needs well in advance.
No Pre-emption
 Pre-empting a resource is necessarily a compulsory sharing. It can be
applied to such devices whose state can be saved and later restored.
 If a process that is holding some resources requests another request that
can not be immediately allocated to it, then all the resources currently
being held are released.
 Pre-empted resources can be added to the list of resources the process is
waiting for.
 Process can be restarted only if it can regain its old and new resources it is
requesting in an alternative manner.
 When a process requests some resources, first of all we check whether
or not they are available. If yes, they are allocated. If no, we check if
they are allocated to some other process waiting for some additional
resources. If they are so allocated, the desired resources are pre-empted
from the waiting process and are allocated to the requesting process. In
case the resources are neither available nor held by a waiting process,
the requesting process has to wait.
Circular Wait
 It imposes a total ordering on all resources types.
 It requires each process to request resources only in a strict increasing
order.
 Resources from the same resources type have to be requested together.
Self-Instructional
Material 69
Process Management Let R = {R1, R2, R3 …Rn} be the set of resources types. Then one to one function
and Operation
is defined as:
F: R  N, where N is the set of natural numbers.
NOTES R {tape drive, disk drive, printer}
Then:
F (tape drive) = 1,
F (disk drive) = 5,
F (printer) = 12.
Protocol
Following protocols are needed for deadlock prevention technique:
 Each process can make a request only in an increasing order. In other words,
any number of instances of resource type Ri can be initially requested by a
process. Following this, the process can request instances of resource type Rj
if and only when F (Rj) is greater than F (Ri). If you need several instances of
the same resource type, you need to issue a single request for all of them.
 Alternatively, we may need that whenever a process makes a request of an
instance of resource type Rj, it has released any resource Ri, such that F (Ri)
is greater than equal to F (Rj).
If the above mentioned two protocols are used, then the circular wait condition can
not hold.

2.7.2 Deadlock Avoidance


We have seen that in deadlock prevention one of the conditions that must be present
for a deadlock to exist is prevented. In deadlock avoidance, a resource which may
eventually lead to a deadlock is never allocated. This can be done by allocating
resources to just one process at a time.
Safe State
A system is considered to be in a safe state if there exists a safe execution sequence.
By execution sequence we mean an ordering for process execution such that each
process, on being executed, runs so long as it does not terminate or is blocked and
all requests for resources are immediately granted in case of their availability.
A safe execution sequence means an execution sequence wherein all processes run
to completion.
Hence a safe state can be decided as per following conditions
 There is no deadlock.
 There is some sequence by which all requests can be satisfied.
 To avoid deadlocks, we try to make only those transactions that will take
us from our safe state to another.
Unsafe State
An unsafe state refers to a state that is not safe not necessarily in a deadlocked
state.
Figure 2.25 shows safe and unsafe states which refer to the process of deadlock
Self-Instructional avoidance.
70 Material
Process Management
and Operation

Safe

Unsafe NOTES

Fig. 2.25 Safe and Unsafe States

An unsafe state may currently not be deadlocked but there is at least one sequence
of request from process that would make the system deadlocked.
Simplest Algorithm
Each process tells a max number of resources it will ever need. As a process runs, it
requests resources but never exceeds the max number of resources. System schedules
process and allocate resources in a way that ensures that no deadlock results. For
example a system is assembled with 12 tape drives.
Table 2.3 summarizes the defined processes, such as P0, P1 and P2 along
with mase need and current needs for an algorithm.
Table 2.3 Process, Max and Current Needs

Process Max need Current needs


P0 10 5
P1 4 2
P2 9 2

Can a system prevent a deadlock even if all processes request the max? Well, right
now, the system has three free tape drives.
If P1 runs just and completes, it will have (3+2) =5 free tape drives. P0 can
run to completion with those 5 free tape drives even if it requests max. Then P2 will
execute. So, this schedule will execute without a deadlock.
If P2 requests two or more tape drives, can system give it the drives? No,
because it cannot be sure that it can run all jobs to completion with only 1 free
drive. So, the system must not give P2 two more tape drives until P1 finishes. If P2
asks for two more tape drives, the system suspends P2 until P1 finishes.
RAG Algorithm
The features of RAG algorithm are as follows:
 It maintains a graph with a directed edge from each process to each resource
it might request. Needs a prior knowledge.
 Allocated resource reverses the edge direction.
 Released resource returns the edge to its original direction.
 The algorithm allocates a resource only if it can do that without creating a
cycle in the graph. Self-Instructional
Material 71
Process Management Figure 2.26 {(a) – (e)} shows the various stages of RAG algorithm.
and Operation

Resource A
NOTES
P1
P2

Resource B

(a)

Resource A

P1 P2

Resource B

(b)

Resource A

P1 P2

Resource B

(c) (c)

Resource A

P1 P2

Resource B

(d) (d)

Self-Instructional
72 Material
Process Management
Resource A and Operation

P1 P2
Denied!!! NOTES
A cycle found. Will have to wait

Resource B

(e) (e)
Fig. 2.26 Stages of RAG Algorithm

Banker’s Algorithm
RAG is not applicable to a resource allocation system with multiple instances of
each resource type. The deadlock avoidance algorithm that we will be describing
next is applicable to such a system. However, this algorithm, commonly known as
Banker’s algorithm, is not as efficient as RAG scheme.
When a process enters the system, it must declare the maximum number of
instances of each resource type that it may need. When a user requests a resource,
we must ensure that after allocating it the system must be in a safe state. If it is
ensured, the resources are allocated else the process has to wait until some other
process releases resource types.
Data Structures
Following are the data structures for banker’s algorithm:
 Available: vector [1…….m], // m indicates the number of available resources
of each type.
If available [j] =k // the number of instances currently available for resource
j.
 Max: matrix [1….n, 1….m], Max [i, j] =k // the maximum number of instances
of resource j that process i can request at any one time.
 Allocation: matrix [1….n, 1….m], Allocation [i, j] = k // Process i currently
holds an instance of resource j.
 Need: matrix [1…n, 1…m], // Process i needs more (additional) resource
(instances) of type j.
Need [i, j] =Max [i,j]–Allocation[i,j]
Banker’s Algorithm – Safety Procedure
Following steps are required for Banker’s algorithm, which refers to safety procedure.
Step 1. Let Work and Finish be two vectors defined as follows:
Work [1….m], Finish [1….n]
Initialize Work = Available and Finish [i] = false for i=1,2,3,…..n
Step 2. Find an I such that:
a. Finish[i] = false
b. Needi<=Work
If yes, GOTO Step 3.
Self-Instructional
Material 73
Process Management Step 3. Work = Work + Allocation;
and Operation
Finish[i]:= true
GOTO Step 2
NOTES a. If Finish [i] = true for all i, then the system is in safe state.
Resource Request Algorithm
Let Requesti be the request vector for process Pi. If Requesti [j] = k, then process Pi
wants k instances of resource type Rj. When a request for resources is made by
process Pi then following actions are taken as follows:
Step 1. If Requesti <= Needi, go to Step 2. Otherwise, raise an error condition since
the process has executed its maximum claim.
Step 2. If Requesti <= Available, go to Step 3, otherwise, Pi must wait since the
resources are not available.
Step 3. Have the system pretend to have allocated the requested resources to process
Pi by modifying the state as follows:
Available = Available – Requesti
Allocation = Allocation + Requesti
Needi = Needi – Requesti
If the resulting resource allocation state is safe, the transaction is completed and
process Pi must wait for Requesti and the old resource allocation state is restored.
Let us consider the following example.
Process Allocation Max Available
A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 2 2 2
P4 0 0 2 4 3 3
Following formula will be taken to find need value:
Need = Max–Allocation
Process Allocation Need Available
A B C A B C A B C
2 3 0
P0 0 1 0 7 4 3
*P1 3 0 2 0 2 0 -------- (1)
P2 3 0 2 6 0 0
P3 2 1 1 0 1 1 -------- (2)
P4 0 0 2 4 3 1
Now, we have to perform the safety algorithm to find the safe sequence. After
executing our safety algorithm, we find that the safe sequence is < P1, P3, P4, P0,
P2>. So, the request for P1 can be immediately granted.

Self-Instructional
74 Material
Now suppose that P2 requests one additional resource of type A and two of Process Management
and Operation
type C so request <1, 0, 2> is sent to the OS. For this, first we have to check the
condition available.
Now suppose that Process P1 requests one additional instance of resource
type A and two instances of resource type C, then consider the following logic: NOTES
So, request1= (1, 0, 2)
request1<=available
[(1, 0, 2) <= (3, 3, 2)] which is true.
Safety Algorithm
(i) Work = <2 3 0>
(ii) Work= <2 3 0> + <3 0 2> = <5 3 2><P1, P3, P4, P2, P0>
(iii) <5 3 2> + <2 1 1> = <7 4 3>
What if P4 then requests (3, 3, 0)? And if P0 requests (0, 2, 0)?
2.7.3 Deadlock Detection
In RAG, a direct arrow is drawn from the process to the resource rectangle to
represent each pending resource request (refer Figure 2.27). To indicate each granted
request, on the other hand, a direct arrow is drawn from a resource dot to the process.

P2 P3 P4

ooo o o o o o o

Fig. 2.27 Resource Allocation Graph

Table 2.4 summarizes the process, current allocation, outstanding requests


and available resources which are sued to detect deadlock.
Table 2.4 Resource Usage

Current Outstanding Resources


Process Allocation Requests Available

R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 3 0 0 0 0 0 0 0 0
P2 1 1 0 1 0 0
P3 0 2 0 1 0 1
P4 1 0 1 0 2 0

To reduce a RAG, you need to check the arrows associated with each process and
resource.
Self-Instructional
Material 75
Process Management  If a resource contains only arrows pointing away from it (meaning it has no
and Operation
request pending), all its arrows are erased.
 If a process contains only arrows pointing towards it (meaning all its requests
have been granted), all its arrows are erased.
NOTES
If a process has arrows pointing away from it but for each such request arrow, there
is an available resource dot (a dot without an arrow leading from it) in the resource
the arrow points to, erase all processes arrows. Figure 2.28 shows the reduced
resource allocation graph.

P1 P2 P3 P4

ooo o o o o o o

R1 R2 R3
Fig. 2.28 Reduced Resource Allocation Graph

Solved Examples of RAG and Reduced RAG


Let us consider the following examples:
Example 2.1:
From the following resource usage table, draw the resource allocation graph.

Current Outstanding Resources


Process Allocation Requests Available

R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 2 0 0 1 1 0
P2 3 1 0 0 0 0 0 0 0
P3 1 3 0 0 0 1
P4 0 1 1 0 1 0

Solution:

P2 P4
P1 P3

o o o o o o o o o o o o

Resource Allocation Graph


Self-Instructional
76 Material
Example 2.2: Process Management
and Operation
From the resource usage table given in Example 2.1, draw the reduced resource
allocation graph.
Solution: NOTES

(a)
o o o o o o o o o o o o

R1 R2 R3
(b) Process P2 only has arrows pointing towards it. So, the links can be erased
and requests can be granted to Process P1 from the Resources R1 and R2.
Hence, we have the following graph:

P1 P2 P3 P4

o o o o o o o o o o o o
R1 R2 R3
(c) Process P1 only has arrows pointing towards it. So, the links can be erased
and requests can be granted to Process P3 from Resource R2. Hence, we
have the following graph:

P1 P2 P3 P4

o o o o o o o o o o o o

Partially Reduced Allocation Graph


(d) Processes P3 and P4 only have arrows pointing towards them. So, the links
can be erased.

P1 P2 P3 P4

o o o o o o o o o o o o
Reduced Resource Allocation Graph

Self-Instructional
Material 77
Process Management Example 2.3:
and Operation
From the table given below, draw the resource allocation graph.

Current Outstanding Maximum Resources


NOTES Process Allocation Requests Allocation Available

R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 2 0 0 1 0 0 2 0 1 0 2 0
P2 1 2 0 0 0 1 2 5 2
P3 0 1 1 0 0 0 1 4 2

P4 0 0 1 0 0 1 2 0 1

Solution:

P1 P2 P3 P4

o o o o o o o o o o
RAG
Example 2.4:
From the table given in Example draw the reduced RAG.
Solution:
(a) Process P3 has only arrows towards it. So, erase those arrows and allocate
the resources to Process P4:

P1 P2 P3 P4
Check Your Progress
13. What is process
synchronization?
14. What is needed for
breaking the tie
between processes
in case of a o o o o o o o o o o
deadlock?
R1 R2 R3
15. What is the use of a
semaphore? (b) Process P4 has only arrows pointing towards it. So, they can be erased and
16. Define the term the resource can be allocated to Process P2.
deadlock.
17. What happens to
the processes P1 P2 P3 P4
engaged in a
deadlock?
18. When is a system
considered to be in
a safe state?
o o o o o o o o o o

Self-Instructional R1 R2 R3
78 Material
(c) Process P2 has only arrows pointing towards it. So, they can be erased and Process Management
and Operation
the Resource from R1 can be given to Process P1.

P1 P2 P3 P4
NOTES

o o o o o o o o o o

R1 R2 R3
(d) Process P1 has now all the arrows pointing towards it. So, they can be finally
erased to get the reduced resource allocation graph.

P1 P2 P3 P4

o o o o o o o o o o
R1 R2 R3

2.8 SUMMARY
 The OS allocates resources to processes, enable processes to share and
exchange information, protect the resources of each process from other
processes and enable synchronization among processes.
 A process is a program that is loaded into memory for execution. In a multiuser
multitasking computer system, there will be many users and each user will
be executing many programs. The primary resources needed for executing a
program are memory and processor time.
 The role of the CPU of a computer is to fetch, decode and execute the
instruction which is pointed by the Program Counter (PC) register (also called
instructor pointer register) as long as the power is switched on.
 The list or array of process control blocks for all the processes is called the
process table of the operating system. Every process in a computer system
should be given a unique identity called process identification number (process
id). This id is assigned at the creation of a process by the operating system.
 A system call is a request to the operating system to execute a region of
operating system code that refers to a region of the code identified by the
number of the system call on behalf of a user process. Operating system
includes the code for various functions, such as doing Input/Output operations
on I/O devices, creating processes/threads and many other tasks.
 A system call number identifies the function that should be executed and it
should be passed in some register while making system calls.
 A thread is created explicitly when a modern process is created. A thread
requires a program counter a stack and a set of CPU registers for execution.
Self-Instructional
Material 79
Process Management A process can have more than one thread of execution. All the threads of a
and Operation
process share the address space (code and global data) of the process.
 The User Level Threads (ULTs) are created and managed by the user. The
Kernel Level Threads (KLTs) are created and managed by the kernel itself. A
NOTES user process will be executed as one or more kernel threads.
 Every process works independently of others in separate address space. The
address space and resources of the process are protected from the unauthorized
access from other processes using memory management techniques and access
control mechanism.
 In multiprocessing systems, scheduling is used to determine which process is
to be given control of the CPU. Scheduling may be divided into three phases:
long term scheduling, medium term scheduling and short term scheduling.
 Switching the CPU to another process after saving the state of the older process
and loading the saved state of the new process is called context switch.
 A parent process can be terminated only when all its child processes have
been terminated. The parent process calls the wait system call and waits for
its children to terminate.
 Processes are independent and protected entities so that do not share any
memory locations for communication and they cannot communicate without
the help of operating systems.
 Client-server architecture consists of two different computer programs—client
and server. Client sends a service request to the server for accessing various
resources.
 Process scheduling or CPU scheduling is concerned with the allocation of a
CPU to processes for execution. The lifetime of a process is the time from
creation to the time of its termination after completing its execution.
 First In, First Out (FIFO) strategy assigns priority to processes in the order in
which they request the processor, i.e., in the order in which processes arrive
in the ready queue.
 Round Robin (RR) allocates a CPU to each of the jobs for the duration of a
time quantum or time slice, i.e., CPU time is distributed equally among all
the processes in the ready queue.
 Every process is assigned a priority and the highest priority job in the ready
queue is assigned the CPU until its completion or until when it requests for I/
O or makes other system call.
 Priority scheduling permits the allocation of more CPU time to important
processes. Priorities are assigned to processes externally and not based on
OS policy for improving overall performances. Multilevel feedback queue
addresses both efficiency and response time problems.
 Process synchronization is a mechanism used by the OS to ensure a systematic
sharing of resources amongst concurrent resources.
 Critical section is basically a sequence of instructions with a clear indication
of beginning and end for updating shared variables. In it, only one process is
allowed to access the shared variables and all others have to wait.

Self-Instructional
80 Material
 A semaphore represents an abstraction of many important ideas in mutual Process Management
and Operation
exclusion. It is a protected variable which can be accessed and changed only
by operations. It also controls synchronization by using an abstract data type.
 A deadlock is a situation in which some processes wait for each other’s actions
indefinitely. Processes involved in a deadlock remain blocked permanently NOTES
which affects the throughput, resource efficiency and the performance of the
operating system. A deadlock can bring the system to standstill.
 Resource Allocation Graph (RAG) is very useful tool which helps in
characterizing allocation of resources. Each and every resource and process
is represented by a node.
 A system is considered to be in a safe state if there exists a safe execution
sequence. A safe execution sequence means an execution sequence wherein
all processes run to completion.

2.9 KEY TERMS


 Process control block: These are the data structures that are used to record
the attributes or properties and context of each of the processes.
 Process table: It is the list or array of process control blocks for all the
processes.
 Context switch: It is the switching of CPU to another process after saving
the state of the older process and loading the saved state of the new process.
 Cooperating process: It is the process wherein a concurrent process can
affect or be affected by other processes in the system.
 Interprocess communication: It is the communication done between
processes.
 Remote procedure calls: It is a method of calling the procedure located at
remote location by sending service request to the server.
 Application program interface: It is a set of software functions implemented
as a library used by an application program as a means for providing access
to an operating system’s capabilities.
 System call: It is a request to the operating system to execute a region of
operating system code on behalf of a user process.
 Semaphore: It is a non-negative integer variable upon which two atomic
operations, wait and signal, are defined.

2.10 ANSWERS TO ‘CHECK YOUR PROGRESS’


1. A process is a program that is loaded into memory for execution.
2. The role of the CPU of a computer is to fetch, decode and execute the
instruction pointed to by the program counter register as long as the power is
switched on.
3. A thread is created explicitly when a modern process is created.
4. Job scheduling determines the job to be admitted for immediate processing.
Self-Instructional
Material 81
Process Management 5. The two important operations provided by an operating system on processes
and Operation
are process creation and process termination.
6. Keeping away the interference between two processes; that is, protecting
each process from the other is one of the issues involved in IPC.
NOTES
7. Client-server architecture consists of two different computer programs client
and server.
8. The advantage of using client-server architecture is that it provides flexibility
and scalability for adding essential resources in the server computer afterwards.
9. The lifetime of a process is the time from creation to the time of its termination
after completing its execution.
10. Saving the context of the current process and restoring the context of the
incoming new process is called a full context switch.
11. Round robin or FCFS may be used among priority based scheduling processes
with equal priority.
12. Multilevel feedback queue addresses both efficiency and response time
problems.
13. Process synchronization is a mechanism used by the OS to ensure a systematic
sharing of resources amongst concurrent resources.
14. An algorithm is required for breaking the tie in case of a deadlock. Peterson’s
algorithm serves this purpose. It has a synchronism mechanism to take into
consideration both ‘who intends to enter the critical section’ and ‘who should
enter the critical section’.
15. A semaphore represents an abstraction of many important ideas in mutual
exclusion. It is a protected variable which can be accessed and changed only
by operations. It also controls synchronization by using an abstract data type.
16. A deadlock is a situation in which some processes wait for each other’s actions
indefinitely. A deadlock can bring the system to standstill.
17. Processes involved in a deadlock remain blocked permanently which affects
the throughput, resource efficiency and the performance of the operating
system.
18. A system is considered to be in a safe state if there exist a safe execution
sequence. A safe execution sequence means an execution sequence wherein
all processes run to completion.

2.11 QUESTIONS AND EXERCISES

Short-Answer Questions
1. What are the primary resources needed for executing a program?
2. Define a system call.
3. What are the components of a thread descriptor?
4. What is the main objective of a job scheduler?
5. What are the features of a context switch?
6. What are the various issues involved in interprocess communication?
Self-Instructional
82 Material
7. What is the disadvantage of using client-server architecture? Process Management
and Operation
8. What are the various goals of scheduling?
9. What is starvation of processes?
10. What are the properties that define multilevel feedback queue? NOTES
11. Name the various problems of critical section.
12. Define a deadlock.
13. What are the methods of handling deadlocks?
14. Give the features of RAG algorithm.
Long-Answer Questions
1. Explain the process of generating executable files.
2. Describe the process table and process control blocks of processes.
3. Explain the various steps involved in system call execution.
4. With the help of a diagram, explain the hierarchy of a process.
5. Distinguish between single threaded and multithreaded processes.
6. What is the difference between ULTs and KLTs? Elaborate.
7. What is a short term scheduler? How is it different from a long-term scheduler?
8. Briefly describe the mechanism of IPC.
9. Describe the various components of client-server architecture.
10. Explain the three states of processes with the help of a diagram.
11. Write short notes on:
(i) FIFO
(ii) RR
(iii) MFQ
12. Explain the mechanism for controlling the access to critical section.
13. With the help of examples, explain the concept of deadlocks, its advantages
as well as disadvantages.
14. Explain the various steps for preventing deadlocks among processes.

2.12 FURTHER READING


Silberschatz, Abraham, Peter Galvin and Greg Gagne. Operating System Concepts.
John Wiley & Sons, 2004.
Tanenbaum, Andrew S. Modern Operating Systems. Prentice Hall, 2001.
Mano, M. Morris. Computer System Architecture. New Jersey: Prentice Hall Inc.,
1993.
Peterson, J.L., Abraham SIlberschatz and Peter B. Galvin. Operating System
Concepts. New York: Addison Wesley, 1994.

Self-Instructional
Material 83
2.13 LEARNING OUTCOMES
 The concept of process management
 The functioning of process scheduling
 The process scheduling, such as operations on processes andconcurrent processes
 Understand CPU scheduling
 Know about process synchronization, such as critical section and semaphores
 Learn deadlocks
Storage Management

UNIT 3 STORAGE MANAGEMENT


Structure NOTES
3.0 Introduction
3.1 Unit Objectives
3.2 Memory Management
3.2.1 Address Binding
3.2.2 Contiguous Allocation
3.2.3 Dynamic Loading and Linking
3.2.4 Overlay
3.3 Paging
3.3.1 Paging Process
3.3.2 Hardware Support for Paging
3.4 Segmentation
3.4.1 Segmentation with Paging
3.5 Virtual Memory
3.5.1 Demand Paging
3.6 Page Replacement
3.6.1 Thrashing
3.6.2 Allocation of Frame
3.7 Summary
3.8 Key Terms
3.9 Answers to ‘Check Your Progress’
3.10 Questions and Exercises
3.11 Further Reading
3.12 Learning Outcomes

3.0 INTRODUCTION
In this unit, you will learn about the concept of memory storage management which is
the act of managing computer memory. The memory manager keeps a record of the
usage of each block of memory available for allocation with the help of various techniques,
such as address binding, contiguous allocation, dynamic loading and linking as well as
overlay. The main function of designing memory management techniques is to divide the
main memory to incorporate with multiple processes and allocate memory for each
process. You will also learn about paging and segmentation. In paging, non-contiguous
physical addresses are allocated to a process. It helps in solving the problem of external
and internal fragmentations whereas segmentation allows a program to be divided into
various segments such as instruction segment and data segment.
You will also learn the concept of virtual memory management in which blocks of
information are taken from the disk and then placed in the memory of the processor.
Virtual memory supports programs that are larger than physical memory and also allows
several programs to reside in physical memory at a time. The common ways of
determining the sizes of the memory blocks to be moved into and out of memory are
done by paging, swapping and segmentation. The various page replacement algorithms,
such as optimal page replacement algorithm, least recently used page replacement
algorithm, etc., are discussed with the help of examples to ensure the minimum page
fault. You will learn the basic concepts of thrashing and frames. Thrashing happens
when a hard drive has to move its heads over the swap area many times due to the high
Self-Instructional
Material 85
Storage Management number of page faults. The physical memory is divided into fixed size memory blocks
known as frames. The number of frames to be allocated to each process plays an
important role in the performance and efficiency of a system. Allocation of frame is
considered as deciding factor in design issue for paging system.
NOTES
3.1 UNIT OBJECTIVES
After going through this unit, you will be able to:
 Understand the concept of memory management
 Explain address binding, contiguous allocation, overlay, dynamic linking and loading
 Define paging, paging process and hardware support for paging
 Discuss segmentation and paging with segmentation
 Define virtual memory and demand paging
 Describe the various page replacement algorithms
 Explain the concept of thrashing and allocation of frame

3.2 MEMORY MANAGEMENT


Memory management refers to moving the processes back and forth between main
memory and disk during paging and swapping. The prime objective of memory
management is to divide the main memory for accommodating multiple processes. For
this, if uses various techniques, such as address binding, contiguous memory allocation
and overlay process. These techniques are discussed below:
3.2.1 Address Binding
All programs reside on the hard disk and they must be brought to main memory for the
execution. While doing so, the process moves between the hard disk and main memory.
If we consider the various software and hardware components of a system they can be
identified by three names:
 Symbolic Name: It refers to the name with which a user identifies the components.
Examples include file names, program names, printer/device names, user names.
We must specify the names in the context of location or the path.
 Logical Name: Alogical name refers to the name used to label a specific entity.
Examples include inodes for file, major/minor device numbers, process id (pid),
user id (uid), gid, etc.
 Physical Name: It refers to an actual physical address of entity, such as address
of file or data on disk or memory. It can be fixed once it enters or variable
relocatable address.
Thus, the binding of instructions and data to actual memory location can occur at three
different stages, namely compile time, load time and execution time.
Compile Time
The absolute code can be generated if the exact location of the process in the memory
can be observed at compile time. This type of binding is termed as compile time binding.
The complier can be structured to generate code starting at address location. This code
Self-Instructional
will work till the starting memory changes. If there is any change then the whole program

86 Material
will have to be rewritten. Thus for a system which allows a program to leave the main Storage Management
memory for some reason and to be reloaded later, the starting address of the program
may change and the compiler will have to recompile the code to generate an absolute
address. Hence, a compiler will typically bind the symbolic address to a relocatable
address. If data binding is done at the compiler level then this process is called early NOTES
binding.
The advantages of this binding scheme are as follows:
 The compiler produces an efficient code.
 It performs checking at an early stage.
 It can estimate the running time and space required for execution of the code.
Load Time
If the exact address where the program has to reside in the main memory is not known at
compile time then the compiler must generate a relocatable code. The final binding will
be done at load time. The loader loads the system library and other required data for the
execution of program and also incorporates the changed value if the starting address is
changed. If the code is generated at load time then it is called delayed binding. The linker
and loader are used to generate the code. The advantages of delayed binding are as
follows:
 It produces an efficient code.
 It allows the same code to be used at different places using separate compilations.
Thus, it allows the sharing of object code.
 It is portable as the program can be loaded at any place.
Execution Time
If a process can move from one segment to another during execution, then binding is
delayed till run time. We need special hardware support for performing the required
address translation, for example base and limit registers. The generation of code at run
time is called late binding. The advantages of late binding are as follows:
 It supports techniques, for example virtual memory, dynamic linking/loading,
overlaying, interpreting, etc.
 It is flexible in nature which allows dynamic reconfiguration.
However, the code is less efficient as the checking is done at run time.
3.2.2 Contiguous Allocation
The main memory is divided into two segments in which one is used to load the operating
system and the other is used as user memory. The operating system is loaded and
present in the system as long as the system is running. The user memory is for storing
the user processes. In a multiprogramming environment, we want several processes to
be in the memory. In contiguous memory allocation, each process is present in a contiguous
memory location. Memory can be allocated in the following ways:
Fixed Size Partition
The entire memory is divided into fixed size blocks or partitions. The size of the partition
is fixed. Aprocess is loaded into a single partition. To accommodate every process in the
partition, the partition size is selected based on the largest process size. If the partition
can accommodate the largest process, then it can easily accommodate all other processes.
Self-Instructional
Material 87
Storage Management The problem in the fixed size partition memory allocation scheme is that when the
process size is less than the partition size, there would be wastage of memory. For
example, if the partition size is 100K (assuming that all the processes are less than the
100 k) and the process size is 25K, then if 25K is loaded into the 100K partition, there
NOTES would be wastage of 75K memory. If all the process sizes are approximately equal to
the partition size, then wastage of memory is minimum. The wastage of memory is
internal to the process hence it is called internal fragmentation. Fixed size partition
allocation scheme suffers with internal fragmentation.
Multiple Size Partition
In this allocation scheme, the memory initially is seen as a single large partition. When a
process with size ‘x’ needs memory, then the memory is divided into two parts—a part
for the process with size x and another part which is free. When another process
requests the memory, then the free part is further divided into two parts to accommodate
the new process. Hence, in this scheme, the memory is divided into variable size partitions.
Consider the memory size as 100K and let four processes each with size 25K request
the memory. Then the memory is allocated as follows:
Process 1
25k

25k Process 2
100k
25k Process 3

Process 4
25k

Fig. 3.1 Multiple-size Partition

If process 1 and process 3 finish execution and their memory is freed, then there
would be 25K + 25K = 50K memory free. The free 50K memory is distributed in two
partitions of size 25K each. If a new process comes with memory request 50K, then the
available 50K memory cannot be allocated, as the memory is not present contiguously
(refer Figure 3.1). This problem is called external fragmentation. Then, external
fragmentation is defined as the division of free storage into small pieces over a period of
time, due to an inefficient memory allocation algorithm, resulting in the lack of sufficient
storage for another program. This process is done because these small pieces are not
centiguous.
The variable size partition scheme suffers with external fragmentation.
Holes
An operating system keeps track of memory segments that are free and occupied. The
operating system allocates memory to the process when process is to be executed and
de-allocates the memory when the process terminates. When the process requests for
memory, then the operating system searches for the block (hole) of memory that is large
enough to accommodate the process. In the variable size partition, different sizes of
memory are scattered throughout the memory. When a process requests the memory,
the system searches for the set of variable memory holes and if it finds the hole that is
large enough to hold the process, then that hole is allocated to the process. If the hole is
very large then the hole is partitioned into two. One is allocated to the process and the
other is returned to the free hole pool. In dynamic storage allocation, the free hole is
selected using the following strategies:
Self-Instructional
88 Material
First Fit: As the searching takes place from the beginning, the first hole that is Storage Management
big enough to accommodate is allocated to the process. Once the allocation is
done, the searching takes place from the current position.
Best Fit: The entire memory is searched and the hole that is smallest to hold the
process is allocated to the process. Here the entire memory is to be searched. NOTES
Worst Fit: In this strategy, the largest hole is allocated to the process. Scanning
the entire memory searches the largest hole.
All the above strategies suffer from external fragmentation problems.
Compaction
Compaction is a technique that is used to solve the external fragmentation problem. In
this technique, the non-contiguous memory holes are combined together that is all the
used memory is moved towards one end of the memory and the unused memory is
moved towards the other end. To do this, we need to move the running process to a new
location. Moving a running process affects the performance as all the dependants are to
be informed about the new location.
Logical Physical Address Space
An address generated by the CPU is referred to as logical address and physical address
is the address of the physical memory. The set of all logical addresses, also called virtual
addresses, generated by a program is called logical address space. This space is to be
bound into physical address space by the memory management techniques. The compile
time and load time binding schemes generate the same logical and physical addresses.
However, they differ during execution time in the address binding scheme.
Base Register Memory

CPU

Logical Physical
Address Address

Fig. 3.2 Translation of Logical Address to Physical Address

The base address register is also called relocation register. The CPU generates the
logical address from 0 to max. This CPU code can be loaded anywhere in the physical
memory. The value of relocation register is added to every logical address generated by
the CPU to get physical address where data actually resides. This helps to relocate the
code into memory. Suppose that the base register has value of 15,000 and logical address
generated is 330. The physical address will be given by 15,330. Thus, the memory
management technique maps the logical address space to physical address space (refer
Figure 3.2).

3.2.3 Dynamic Loading and Linking


Dynamic loading refers to the process of copying the loadable image into memory,
connecting it with any other programs already loaded and updating addresses as needed.
Dynamic linking refers to the process of combining a set of programs including library
routines to create a loadable image. These two techniques are discussed below:
Self-Instructional
Material 89
Storage Management Dynamic Loading
The dynamic loading technique does not load a routine until it is called. All routines are
kept on disk in relocatable load format and are loaded into memory whenever needed
NOTES for execution. As unused routines are never loaded, this scheme provides better memory
space utilization. It is also useful in the cases where there are large amounts of code
which are not frequently required. Now no special support from the operating system is
required the user implement this concept by proper program. The concern of design
operating system is to provide library routine to implement dynamic loading.
Dynamic Linking
Some operating systems support only static linking where the system library is treated
like another object module and is combined to the code by the loader. But dynamic
linking, such as dynamic loading, postpones the linking of code until execution time. This
technique is used to load system library functions, subroutine libraries, etc. Asmall piece
of code called stub is included in the image for each library routine reference. The stub
replaces itself with the address of the routine and executes the routine. Thus, it is used
for locating the appropriate memory resident library routine and loading it if the routine is
not already present.

3.2.4 Overlay
The function overlay helps a process to be allocated even if it has a size larger than the
amount of memory allocated to it. The underline principle is to keep only those instructions
and data that are needed at any given time in the memory. When other data or instruction
is required, it is loaded into space occupied by the processor that is no longer needed.
The implementation is performed by the user with simple file structure. Reading from
the file into memory and then jumping to another memory location and execute the
newly read instruction. There is no special support from operating system there is just an
overlay manager that bringing in and out the required overlay code as per demand of
program.
Figure 3.3 shows the management of an overlay in which overlay manager loads
an overlay segment when it is not in RAM. Overlay 1, overlay 2 and overlay 3 are
interconnected with overlay area. The function of an overlay area is to signal the overlay
handler which swaps out the old program segment and swaps in the next program
segment with the help of device drivers, interrupt handlers and exception handlers.

Main
Program

Overlay
Manager

Fig. 3.3 Management of an Overlay

Self-Instructional
90 Material
Let us consider an example in which there is a two pass assembler: Pass1 creates a Storage Management
Symbol Table and Pass 2 generates the machine code. In order to perform this task,
both tasks require Symbol Table and some other common subroutines. But as both tasks
are executed independently, there are some routines which are specific for particular
task. We can divide the routines into the following components: NOTES
Pass1 80 KB
Pass2 70 KB
Symbol Table 30 KB
Common Routines 40 KB
Consider a memory of size 200 KB. If we try to load both on them simultaneously, it is
not possible as both of them do not execute simultaneously. It is assumed that two
overlays A and B are defined in which overlay driver (10KB) starts with overlay A in
memory.
Let us assume that OverlayA consists of Symbol Table, Common Routines and
Pass 1. Overlay B consists of Symbol Table, Common Routines and Pass 2 (refer
Figure 3.4).
An Overlay Manager of 15 K that manages the complete process.
Initially, Overlay A is loaded into memory. Once it is over, only Pass 2 of
Overlay B will be loaded, as Symbol Table and Common Routine are same. It will be
faster as lesser number of data is to be fetched.

Symbol Table

Common Routines

Overlay Driver

Pass 1 Pass 2

Fig. 3.4 Overlays for a Two Pass Assembler

3.3 PAGING
Check Your Progress
The two types of memory allocation techniques are known as: contiguous allocation and 1. Define memory
non-contiguous allocation. In the contiguous allocation technique, each process occupies management.
a continuous memory location. This technique is used in batch operating system in which 2. What is early
the main memory is divided into two partitions. One part is occupied by the resident binding?
operating system, which is usually held in the low memory area with interrupt vector. 3. Define compaction.
The other part is occupied by user processes, which are held in high memory area. 4. What does dynamic
linking refers to?
Relocation register is used to protect the user process from modifying the operating
5. What is the
system code. The relocation register thus holds the value of smallest physical address function overlay?
which a process can use. We can say it is the limit register which tells us the lower limit
of logical address.
Self-Instructional
Material 91
Storage Management The same scheme can be used in a multiprogramming environment. However,
now instead of a single partition, there are multiple partitions. The process has to find
a free space out of available space. These free spaces are called holes, i.e., continuous
blocks of available memory. These holes are scattered throughout the memory and
NOTES have variable size. Operating system provides the information about number and size
of holes. When a process arrives, operating system allocates a memory hole to the
process such that it is large enough to accommodate the process. Since it is not
possible to execute a process if a hole big enough to accommodate the process is not
available. Thus, the idea of a non-contiguous memory allocation arises where the
process is dispersed in different locations in memory. In this, the process is divided
into pieces: either logical pieces, as in case of segmentation or physical partitions, as in
case of paging.
In paging, non-contiguous physical addresses are allocated to a process. It solves
the problem of external fragmentation and to some extent internal fragmentation. Loading
the pages before letting processes run is known as prepaging.
3.3.1 Paging Process
The physical memory is divided into fixed size memory blocks known as frames. The logical
memory is divided into fixed size memory location called pages. The size of the frame is
equal to the size of the page. Typically, the size of the page is 2n. When the process is to be
executed the logical pages are loaded into the physical frames. The address generated by the
CPU is divided into two parts—the page number and the page offset.
Address Translation Scheme
Let the page number be p and the offset be d.

Fig. 3.5 Address Translation Scheme

The CPU generates the logical address which is the combination of page number
(p) and the displacement (d). Displacement is inside the page. Consider the page as a
set of instructions, say 1000 instructions. If the program consists of 40, 000 instructions,
then the process can be broken into 40 pages each with 1000 instructions. If the user
wants to execute the 22200th instruction then that instruction is present in the 22nd page
with displacement 200. The CPU generates the logical address with page number p = 22
and displacement d = 200. For executing the instruction (22,200), the page is to be
brought into the physical memory frame. Apage table is a table that stores the mapping
details of which page is loaded into which frame. In Figure 3.5, the logical address p + d
is converted into the physical address f + d. The corresponding frame f for the page p
can be found in the page table.
Self-Instructional
92 Material
Storage Management

NOTES

Fig. 3.6 Mapping of Pages to Frames

Consider a process with four pages numbered from 0 through 3. When the process
needs to be executed then these 4 pages must be brought into the physical memory. The
pages related to a single process are allocated non-contiguous frames. The page table in
Figure 3.6 shows the mapping of the pages to frames. The Page 0 is loaded into the Frame
1; similarly, the Page 1 is loaded into Frame 4, Page 2 into Frame 3 and Page 3 into Frame
7. All the pages are scattered into the main memory into non-contiguous blocks.
Figure 3.7 shows the physical memory of 32 bytes. With the logical memory of 4
pages and a page size equal to 4 bytes the page table stores the mapping details. If the
user wants to execute the instruction k which is present in the Page 3 with displacement
3, the Frame address of the Page 3 is Frame 2. This information can be obtained from
the page table. In frame two, the instruction is fetched with displacement 3.

Fig. 3.7 Physical Memory of 32 Bytes

When a process is to be executed then its size is given in terms of number of


pages say n. The process requires n free frames to load n pages of the processes.
Self-Instructional
Material 93
Storage Management If there are n free frames then the first page is loaded into one of the free frame and the
frame number is written in the page table. The subsequent pages are also loaded into the
free frames and their corresponding frame numbers are written in the page table. Figure
3.8 depicts the allocation of frames to the pages and their page table entries.
NOTES

Fig. 3.8 Allocation of Frames to Pages and their Page Table Entries

The user considers the memory as single contiguous memory but the actual physical
memory allocated is non-contiguous.
3.3.2 Hardware Support for Paging
To execute each instruction, the memory manager must resolve the page frame mapping.
If the processor executes thousands of instruction per second then for each instruction
the page table is consulted. To improve the performance, the page table entries are
stored in registers. The register memory is the fastest memory and storing the page
table entries in the register memory improves the performance. However, the register
memory is costlier and the page table size for a typical process consists of millions of
entries. To store the entire page table in the registers is very much costlier in the
multiprocessing environment.
To solve the above issue, the page table entries are stored in the main memory
and the pointer to this memory is stored in the Page Table Base Register (PTBR). To
find an instruction, first the PTBR is found and then from the page table the actual
address of the instruction is fetched. This approach needs two memory accesses—one
for the PTBR and the other for page table. The performance is decreased by a factor of
two. To solve this problem, the page table is put in a fast lookup cache hardware known
as Translation Lookaside Buffers (TLBs). The TLB is a hardware cache within the
processor’s bus interface unit which stores recently used copies of page table entries.
The main function of TLB is to speed up conversion from virtual address to physical
address. With TLBs, the searching for a page is faster. The TLBs store a part of the
page table. The entire page table resides in the main memory. If the page number is
found in the TLB then we call it a hit and the frame number is retrieved. If the desired
page is not found in the TLB then it is a miss. When a miss occurs, then the page table
present in the main memory is referenced.
Self-Instructional
94 Material
The hit ratio is calculated which is the number of page numbers found in the TLB. Storage Management
60 per cent hit ratio means 60 per cent of times the page number is found in the TLB;
40 per cent of times, the page number is not found in the TLB.

3.4 SEGMENTATION NOTES

The memory management technique that supports the users’ view of memory is known
as segmentation. Segmentation is different from paging. In paging, the logical memory is
different from the users’ view of memory in segmentation, the logical memory is same
as the users’ view of memory. Users view the logical memory as the collection of
segments. Segments are of different sizes. Segment ordering is not important. The user
thinks the program consists of main program, few routines, procedures, or functions.
Figure 3.9 shows the users’ view of the memory.

Fig. 3.9 Users’ View of Memory

Figure 3.9 has main program, symbol table, stack, sqrt function and subroutine.
All the segments must be in the memory but they can be in any order. Each segment has
a segment name and size. All the segments are of different sizes. Elements in a segment
are identified using the offset. The logical address in the segmentation is the tuple with
segment name and the offset and the syntax used for its is as follows:
<Segment-name, offset> Check Your Progress
The physical memory is one-dimensional. It is a sequence of bytes. The logical 6. Classify the types
address is generated in two-dimensional address. The role of segment table is to store of memory
allocation
the mapping of two-dimensional address to one-dimensional address. The entries in the techniques.
segment table are the base and limit of the segments. Base is the starting address in a 7. Define the term
segment and the limit is the size of the segment. pages.
Figure 3.10 shows how the segment table maps the logical address to the physical 8. What is the prime
function of TLB?
address.

Self-Instructional
Material 95
Storage Management

NOTES

Fig. 3.10 Mapping the Logical Address to the Physical Address

The segment number s is used as the index to the segment table. The offset d
must be less than or equal to the segment limit. If the offset is greater than the segment
limit or segment size, then the operating system generates a trap indicating illegal offset.
Figure 3.11 demonstrates segment table usage.

Fig. 3.11 Segment Table Usage

The example has five segments 0 through 4. All the segments are of variable size.
Segment 0 is 1000 bytes; Segment 1 is of 400 bytes; Segment 2 is of 400 bytes; Segment
3 is of 1100 bytes and Segment 4 is of 1000 bytes. The size of each segment is stored in
the limit column. The base column in the segment table is the starting address of the
location where the segment is loaded in the memory. For example, if the CPU generates
the logical address as <2, 500>, here the segment number is 2 and the offset is 500. The
offset 500 is greater than the limit of the Segment 2 (400). Hence, the memory reference
<2,500 is illegal. If the CPU generates <3,200> where 3 is the segment number and the
200 is the offset. The offset 200 is less than the limit of Segment 3. Hence, the memory
Self-Instructional
96 Material
reference is the legal reference. The Segment 3 starts from the location 3200. From Storage Management
3200, the segment takes 1100 memory bytes, i.e. from 3200 to 4300. For the <3, 200>
reference, the actual physical memory reference is 3200 + 200 = 3400.
Protection, Sharing and Fragmentation NOTES
Protection, sharing and fragmentation processes are discussed below:
Protection: Segmentation allows a program to be divided into various segments, for
example instruction segment and data segment. The architecture demands the instructions
to be non-modifiable during the execution. The instruction segment is read only or can
be executed only. The hardware that performs the memory mapping will check whether
the access to the segment is legal or not. Each segment has protection bits. If the
instruction segment is modified then it will treat it as illegal access. Any access outside
the segment boundaries are also considered as illegal access. Hence, the program errors
that are common are detected using the hardware. This helps to protect against serious
damage.
The page table may contain one more column to store the valid–invalid bit (refer
Figure 3.12). If the bit is set to valid, the page is present in the physical memory and the
reference to the page is valid. If the valid–invalid bit is set to invalid, then the page is not
present in the memory and any reference to the page is considered as invalid.

Fig. 3.12 Valid–Invalid Bit

In Figure 3.12, the page references from 0 through 5 are valid as they are present
in the memory. Pages 6 and 7 are not present in the memory; hence, they are invalid.
Sharing: The segment contents can be shared. Each process has its own segment
table. The dispatcher uses the segment table. Sharing is done at the segment level.
Hence any information that is to be shared is put in the segment. For example, consider
the 5 users using the text editor program. Rather than keeping the 5 text editor segments
(instruction segment) in the memory, the memory management module keeps only one
segment of text editor program that contains the text editor instruction that is to be
shared. If a user wants to share the function then the function can be put in a separate
segment.

Self-Instructional
Material 97
Storage Management Sharing introduces problems as all the users who are sharing the segment must
have their own copy of the program counter. The register contents must also be stored
before the context switching occurs.
Fragmentation: The segments are of variable size and are loaded into the memory for
NOTES execution. Segmentation suffers with external fragmentation. To solve the external
fragmentation problem, the compaction technique is used. When the memory is full and
two segments that are present at two corners of the memory are executed, their memory
is released. If a segment equal to the size of the sum of the two segments just released
is to be allocated then the memory that is available at two corners must be combined
together.

Fig. 3.13 Address Translation of Segmentation with Paging

This combination of the memory available at different places into a single large memory
is called compaction. In compaction, all the occupied memory is moved to one side of
the memory and the unoccupied memory is moved to the other side of the memory. If
we put a constraint on the segments size to be fixed, then it becomes paging. Paging
eliminates external fragmentation. The last page in the process suffers with internal
fragmentation.
3.4.1 Segmentation with Paging
Paging and segmentation techniques have their own advantages and disadvantages.
The Motorola 68000 microprocessor is based on the flat address space. The Intel Pentium
Self-Instructional
98 Material
80 * 86 is based on segmentation. The Intel 386 merges the two paging and segmentation Storage Management
techniques. The segment is divided into equal size partition called pages. This is called
segmentation with paging where each segment is paged.
In the MULTiplexed Information and Computing System (MULTICS), the problem
of external fragmentation is solved by using segmentation with paging. The lengthy NOTES
search times is reduced by paging the segments.
The address translation of segmentation with paging is shown in Figure 3.13.

3.5 VIRTUAL MEMORY


With an increase in the degree of multiprogramming and size of the programs, it is not
possible to load complete program before the execution of program giving rise to the
idea of virtual memory.
Virtual memory is a technique that allows the execution of processes that may
not be completely loaded in the memory. It enables to execute a program or software
with a size larger than the physical memory available. Virtual memory is commonly
implemented by demand paging or demand segmentation. The basic principle behind the
virtual memory technique is to store those sections of program instructions and data that
are not currently used in hard disk. Only those portions processes that are currently
required are brought into main memory. The remaining part of process is brought to
main memory as and when necessary required. Most of current operating systems work
on the principle of virtual memory. The virtual memory is based on concept of lazy
swapper. A lazy swapper never swaps a page into memory unless that page is needed.
The virtual memory is implemented either by demand paging or demand
segmentation.
Demand paging and demand segmentation are similar to paging and segmentation
with swapping, respectively. All processes reside on the hard disk. Only those instructions
and data that are currently required are kept in the main memory. If the required page is
not currently in physical memory then the execution of that program is aborted and can
be restored again when the required information is placed in main memory from the disk
by the memory controller. An operating system decides the amount of memory allocated
to process and the algorithm decides which page to swap in and swap out. The OS
implements the virtual memory technique with the help of hardware support and various
algorithms.
Check Your Progress
3.5.1 Demand Paging 9. What is
segmentation?
Demand paging is a better approach than paging and it also increases the degree of 10. Write the syntax of
multiprogramming which allows a process to run even it exceed the physical space logical address in
allocated for it. Demand paging is based on the following concept: the segmentation.
11. What is the role of
Bring a page into memory only when it is required. segment table in
memory
As less memory is allocated for each process, more processes can be reside management?
in the main memory, i.e., enabling a higher level of multiprogramming. 12. Why MULTICS
When a process is executed, it needs to access pages. If the required page is system is used?
resident in the main memory, execution proceeds normally. However, if the required
page is not available it results in a page fault trap.
Self-Instructional
Material 99
Storage Management Now the obvious question is how to determine whether the required page is in the
main memory or on hard disk. In order to determine this, a valid–invalid bit is associated
with each page table entry. If the valid bit is indicated, the page is in memory and legal to
use. 0 represents that the page is either invalid or not in memory. Initially, all bits are set
NOTES 0 indicating that all required pages are to be brought from memory. After translation of
virtual address to physical address, the valid–invalid bit is checked. The operating system
ensures that a page corresponding to which the valid bit is 0 should never be accessed
and page fault is reported. The sequence of the procedure for handling this page fault is
as follows:
 When a page is required the table is checked to see if the reference has a valid
memory access.
 If the reference is invalid, we terminate the process. If it is valid, use the page and
if the page is not present in the main memory bring it from the hard disk.
 A free frame from the free frame list is found.
 The desired page is brought to the allocated space.
 If the disk is full, new page has to replace an existing page (page fault).
 During page fault, the hardware traps the operating system.
 The operating system reads the desired page into the memory and restarts the
process.
Figure 3.14 shows the implementation process of multiprogramming using virtual memory
concept in which virtual address (0–1023) is assigned for Page 0, (1024–2047) is assigned
for Page 1, (2048–3071) is assigned for Page 2 and (3072–4095) is assigned for Page 3
respectively. The role of MMU is to incorporate the assigned virtual addresses with
processes as well as physical memory segments.
While the memory manager fetches the required information from the hard disk,
the processor can be continued to execute another program. Thus, processor time is not
wasted in seeking information from hard disk. Although selection of virtual management
gives overhead for managing the system, it is the only solution for handling large programs.

Virtual Physical
Addresses Virtual Memory Physical Memory Addresses
0 – 1023 Page 0 MMU Page Frame 0 0 – 1023
1024 – 2047 Page 1 Page Frame 1 1024 – 2047
2048 – 3071 Page 2 Page Frame 2 2048 – 3071
3072 – 4095 Page 3 Page Frame 3 3072 – 4095
... Page Frame 4 4096 – 5119
Process II Page Frame 5 5120 – 6143
0 – 1023 Page 0 Page Frame 6 6144 – 7167
1024 – 2047 Page 1
2048 – 3071 Page 2
3072 – 4095 Page 3
4096 – 5119 Page 4

Fig. 3.14 Implementation of Multiprogramming using Virtual Memory Concept


Self-Instructional
100 Material
A page fault results in the following sequence of events: Storage Management

 A trap is generated by the operating system.


 The user register and process state are saved.
 The page reference is checked if legal by checking the validity bit. NOTES
 If there is a page fault then the location of the page on the disk is found.
 A read command is issued to read the required page from the disk and it is loaded
on to the free frame.
 While the process is waiting for the page, the processor is allocated to another
process.
 Once a read is completed, an interrupt is generated by the disk informing that the
I/O operation is complete.
 The content of a processor register and the state of the process which is loaded
in place of the previous process are saved.
 The page is loaded into memory.
 The page table is modified so that it tells us that desired page is in the memory.
 The process is now waiting to be allocated again.
 Once the processor is allocated the user register is restored a new page table is
generated to continue the process after the interrupt.

Page is on
3 Backing Store

Operating
System 2
Trap
Reference
1

Load M i

6
Page Table
Restart
Instruction Free Frame

5 4
Reset Page Bring in
Table Missing Page

Physical
Memory

Fig. 3.15 Internal Operation of MMU

Figure 3.15 shows an internal address of MMU in which virtual page number is used as
an index into the page table to find the entry for that virtual page. For this, it uses six
phases in which Phase 1 keeps reference for page table, Phase 2 refers to trapping
process, Phase 3 keeps page is on backing store, Phase 4 brings missing page into
physical memory, Phase 5 resets page table and phase 6 restarts instruction. If we see
Self-Instructional
Material 10
1
Storage Management the performance of a processor when there is page fault, three major additional steps
involved are as follows:
 Service the page fault
NOTES  Read the page from memory
 Restart the process
Thus, the Effective Access Time (EAT) for system based on demand paging is directly
proportional to the page fault ratio and is given by:
EAT= (1–p) * memory-access + p * (page fault overhead + swap page out
+ swap page in + restart overhead)
Where p is the page fault ratio and range from –0  p  1.0, such that p = 0, when
there no page faults, and p = 1, when every reference is a page fault. Lets p be 0.5, i.e.,
50 per cent page needs replacement. Let memory access time be 0.01 millisec and page
fault service time is 10 millisec.
Hence, EAT = (1 – p) *.01 + p (10)  10.01*.5 = 5.005 ms.
Demand paging has proved an efficient operation because complete program
code is not really required for execution. The 90/10 rule states that 90 per cent of the
time, the program executes only 10 per of the code. This rule is based on the locality
model which requires that the working set of a process must reside in the memory.
Advantages and Disadvantages of Demand Paging
The advantages of demand paging are as follows:
 It saves memory as it does not load pages that are never accessed.
 It makes the pages available to other programs increasing the degree of
multiprogramming.
 There is less loading latency at program startup.
 There is less initial disk overhead because of fewer page reads.
 It can be easily implemented in a system that supports paging memory
management. It does not require any additional hardware support apart from
what is required in implementing the paging scheme. The protection bit in the
page map table can be used to get the page fault status.
 It allows the sharing of resources. Pages can be shared by multiple programs if
they are read only files. However, if one of them is modified, it should be intimated
to all the programs and a design change should be replicated in all.
 It is able to run programs with larger requirements than available on the machine.
Check Your Progress This method is easier than the old manual overlay as it in done implicitly by the
operating system and the programmer does not have to take care of it.
13. What is the basic
principle behind the The disadvantages of demand paging are as follows:
virtual memory
technique?  Memory management uses page replacement algorithms to decide which page to
14. What is the replace, which makes it slightly complex.
function of demand  Individual programs have extra page fault when they are accessed for the first
paging?
time. Using prepaging method where we remember which pages a process used
15. Which system
generates trap? when it was last executed and preloading a few of them reduces page fault and
improves performance.

Self-Instructional
102 Material
 Small systems like low power embedded systems cannot implement this Storage Management
concept because their memory management unit does not support page
replacement.

3.6 PAGE REPLACEMENT NOTES

If the size of a process is ten pages, only five of them will be in use at a given point in
time. According to the principle of demand paging, only five pages are loaded so that
memory requirement is less and more programs can be loaded in the memory or we can
say the degree of multiprogramming can increase. Thus, logical address space, which is
the address generated by the CPU and corresponds to the complete program, can be
much larger than the physical address space. If a page is required but not present in the
main memory a page fault occurs which results in a page trap. The operating system
determines where the desired page resides in the hard disk and loads it into the main
memory. What will happen if there is no free frame to load the page? As the page miss
results in an interrupt which reduces the system efficiency, it is advisable to design an
algorithm to reduce the frequency of page faults. Although inclusion of this algorithm
results in increased complexity, it improves overall efficiency. The function of page
algorithm is to find a page that is not in use or will not be used in the near future and
swap it with the page required. The aim of any page replacement algorithm is to ensure
minimum page fault. There are two classes of replacement schemes:
 Fixed Replacement Schemes: In these algorithms, the number of pages allocated
to a process is fixed.
 Variable Replacement Schemes: In these algorithms, the number of pages
available for a process varies during the whole life cycle of the process.
Now, we should modify the page fault handling technique to incorporate the page
replacement algorithm as follows:
 Find the desired page on the hard disk.
 Find a free frame to load the page.
o If a frame is available, use it.
o If no frame is free, select a page (using the page replacement algorithm) to be
swapped to the hard disk.
o Write the victim page on hard disk and load the required page to main memory
and make a change in the frame table accordingly.
 Restart the processor.
The aim of designing the replacement algorithm is to minimize page fault. We study the
system of pure demand paging where each page is brought to main memory only if it is
required. We evaluate an algorithm by calculating the page fault for the particular memory
reference sequences, also called reference string. Let us assume the reference string to
be:
0,1,2,3,1,0,1,4,0,1,2,3,4,6,1
Let there be three frames in the system, i.e., three pages per process can be in
the memory at a given time.
The first and simplest algorithm is the First In, First Out (FIFO) algorithm. This
algorithm suggests that the oldest page should be removed. The concept is implemented
Self-Instructional
Material 10
3
Storage Management through a fixed size queue thus a page is inserted at the tail of the queue and all elements
move one step such that the head of the queue is taken out. Let us see how many page
faults are reported for page replacement algorithm.
Reference String
NOTES
0 1 2 3 1 0 1 4 0 1 2 3 4 6 1
0 0 0 3 3 3 4 4 4 6 6
1 1 1 0 0 0 2 2 2 1
2 2 2 1 1 1 3 3 3
1 2 3 4 5 6 7 8 9 10 11

The last row shows the page fault in the table below.
Let us now consider a case where there are four frames available per page. The
obvious observation should be that if we increase the number of pages the page fault
should reduce.
Reference String
0 1 2 3 1 0 1 4 0 1 2 3 4 6 1
0 0 0 0 4 4 4 4 3 3 3 3
1 1 1 1 0 0 0 0 4 4 4
2 2 2 2 1 1 1 1 6 6
3 3 3 3 2 2 2 2 1
1 2 3 4 5 6 7 8 9 10 11 12

But from the above table we see that on increasing the available frames, the number
of page faults has increased from 11 to 12. This is called Belady anomaly. For
some page replacement scheme, the page fault rate increases with an increase in
the frame number. However, we should not choose the algorithm which has Belady
Anomaly.
Let us now discuss the various page replacement algorithms.
Optimal Page Replacement Algorithm
This algorithm replaces the page that will not be used for the longest time period.
Reference String
0 1 2 3 1 0 1 4 0 1 2 3 4 6 1
0 0 0 0 0 2 3 6
1 1 1 1 1 1 1
2 3 4 4 4 4
1 2 3 4 5 6 7 8

The optimal algorithm gives the minimum number of page faults. However, at the same
time, it is difficult to implement it as it is not possible to have complete knowledge of the
reference string in advance, i.e., it is difficult to project which page will be referred to
next. Thus, optimal algorithms give the best result. However, they are just theoretical
concepts as it is not possible to know which page will be needed next especially when
there is dynamic binding.

Self-Instructional
104 Material
Random Page Replacement Storage Management

The random replacement algorithm randomly selects the page to be replaced from the
pages present in main memory. It is a simple technique and does not require any additional
hardware overhead. However, its performance is unpredictable as there is no strategy NOTES
for choosing a page to be replaced from memory.
LRU Page Replacement
LRU page stands for least recently used page. This algorithm is based on the principle
of reference of locality, which states that if a page is used in the recent past, there are
good chances that it will be used in the near future. Thus, for choosing a page for
replacement the choice will be the page that has not been used for the longest period of
time.
Reference String
0 1 2 3 1 0 1 4 0 1 2 3 4 6 1
0 0 0 3 3 4 2 2 2 6 6
1 1 1 1 1 1 1 4 4 4
2 2 0 0 0 3 3 3 1
1 2 3 4 5 6 7 8 9 10 11

Thus, the number of page faults is 11. Least Recently Used (LRU) does not suffer from
Belady Anomaly and is considered to be a good page replacement algorithm. Now, the
question arises how to implement it through the hardware.
Counter Implementation
The simplest technique to implement LRU page replacement is to attach a clock or
logical counter to each entry in the page table. This clock is implemented to determine
the page to be replaced. Whenever a page is referred, the counter is updated. We
replace the page with the smallest time value, indicating that it is the least recently used.
But in this case, one has to be very careful for the overflow of the clock.
Stack Implementation
Another way to implement this concept is the use of stack. A stack in the form of a
doubly linked list is used for storing the page number. Whenever a page is referred, it is
moved to top of the stack and page number which is at the tail of stack is replaced as this
is the least recently used. To implement it, changing of six pointers for every reference,
which make this scheme complex, is required. However, the advantage of this scheme
is that no additional search is required for finding the page to be replaced.
LRU Approximation Page Replacement
Often systems do not provide sufficient hardware support to implement LRU page
replacement which is implemented with approximation using the reference bit concept.
We attach a reference bit with each page table entry and set it initially to 0. Whenever
the page is referred, the bit is set to 1. Although this scheme does not provide the order
in which the pages are referred to. However, it is a simple way to implement the partial
ordering. If a page is to be replaced, the obvious choice will be the page with reference
bit 0.

Self-Instructional
Material 10
5
Storage Management Additional Reference Bits Algorithm
Better ordering information can be obtained if we use more bits for keeping the reference
record. Let there be 8 bits associated with each page in the table. These reference bits
NOTES are regularly updated by operating system. Whenever a page is referred the operating
system shifts the reference bit for each page to a high order, shifting the other bits right
and discarding the low order bit. Thus, the page with a history register value of 1110
0010 will be more recently used as compared to the one having a register value of 0110
0111. We interpret the value stored in history register as 8-bit unsigned number and the
one with the smallest value should be replaced.
Second Chance Algorithm
Using this technique, we implement the FIFO (clock) replacement algorithm with some
advancement by including a reference bit. Here when a page is to be selected for
replacement, we inspect the reference bit. If its valve is zero, we replace it. If it is one,
then it indicates the page is recently used and we give a second chance to the page to
stay in memory and move to next FIFO page. When a page gets second chance, its
reference bit is cleared and its arrival time is reset to the current time. Thus, a page that
is given a second chance will not be replaced until all other pages are replaced. One way
to implement this algorithm is by using circular queue. The pointer marks the page to be
replaced. If the reference bit of marked page is 0, replace the page. Otherwise, the
pointer will advance until it finds a page with reference bit 0. At the same time, it sets all
reference bits to 0 for all in between pages having reference bit 1. The new page is
inserted in position of the page that 1 replaced.
Enhanced Second Chance
In this technique, we use two bits to find the page to be replaced: one is reference bit and
the other is modify bit. Thus, we have an ordered pair associated with each page. With
these two bits, we have the following four possible situations:
 (0,0): It is best page to replace as it is neither recently referenced nor modified
 (0,1): It is not as good as (1). Here, although the page is not recently referenced,
it is modified ,hence needs to be written out before replacement.
 (1,0): It can be replaced because it is used recently. However, it cannot be
modified and has a probability that it will be used again soon.
 (1,1): It is both recently used and modified. Hence, it also has high probability to
be used again. This page also needs to be written back before replacement.
The set of pages in which a process is currently used known as its working set. Many
paging systems keep track of each process working set and make sure that it is in
memory before letting the process run. This approach is known as working set model. It
uses following algorithms to reduce the page fault rate.

3.6.1 Thrashing
In a multiprogramming situation when a large number of processes reside in memory, a
situation can arise where a process does not have sufficient number of pages and frequent
page faults are reported. This may lead to a low CPU utilization because the number of
processes completed is less. As the CPU utilization is reduced, the operating system
thinks there are less number of processes to be performed and hence increases the
degree of multiprogramming. This allows new process to be loaded to the system,
Self-Instructional
106 Material
increasing further the page faults. As a result, the system throughput plunges down to Storage Management
zero. This situation is called thrashing (refer Figure 3.17). Thus, thrashing is a situation
where processor is busy in handling the page faults, i.e., it swaps page in and swaps
page out. In other words, we can say that thrashing spends more time in handling page
faults than in executing. Thus, thrashing is a situation where the system output reduces NOTES
drastically to zero and should be avoided under all conditions. Thrashing happens when
a hard drive has to move its heads over the swap area many times due to the high
number of page faults.
The causes of thrashing are as follows:
 The operating system monitors CPU utilization and if the latter decreases below
a certain value, the operating system introduces a new process to the memory
without viewing the reason for low CPU utilization.
 No time is spent doing useful work; the time is simply wasted in swapping in and
out pages between hard disk and main memory.
 The system is overcommitted.
 A global replacement algorithm is used. So, the processor can remove a page
irrespective of the process to which it belongs.
 The page replacement algorithm does not have an idea as to which pages should
be removed to reduce page faults.
 The process is very large, so there could not be just enough physical memory for
all the processes.
Thus, a new process requiring more pages starts stealing pages from other processes
using page in and page out devices. This process enters the queue of the hard
disk, requesting for pages. As the scheduler sees a decrease in CPU throughput, it
further increases the degree of multiprogramming through introducing a new process.
This may result in a breakdown like situation where the CPU throughput reduces to
zero.
The best way to avoid thrashing is to use the local replacement algorithm so that
no process can steal frames from other processes.
Working Set Strategy
Another way to avoid thrashing is to provide as many frames as is required for the
completion of the process. Now the question arises how to determine in advance the
number of frames required. To determine this, the working set strategy which is based
on the locality model is used. As we know, according to the reference of locality principle,
the process of near locality has a brighter chance to be used again. A locality is a set of
pages that are actively used together. Aprogram is generally composed of several localities
which may overlap. For example, if a process calls a procedure or subroutine the reference
will be made to instruction of the subroutine instead of main program. Thus, a process
can move from one locality to another.
Suppose we allocate enough frames to a process to accommodate the current
locality. It will fault for the pages in its locality until all these pages are in memory and it
will not fault again until it changes localities. Figure 3.16 shows the relationship graph of
number of frames and page faults.

Self-Instructional
Material 107
Storage Management

Number of
Page Faults

NOTES

Number of Frames

Fig. 3.16 Relationship between the Number of Frames


Allocated and Number of Page Faults

CPU
Utilization Thrashing

Degree of Multiprogramming

Fig. 3.17 Relationship between CPU Utilization and Degree of


Multiprogramming

Figure 3.17 shows the relationship graph of CPU utilization and degree of multi-
programming.
Working Set Model
We have seen that the working set model is based on the assumption of locality. This
model defines a parameter Ä, called the working set Window. The idea here is to examine
the most recent page reference and collect them as a set of pages. If a page is active, it
will be in the working set. If it is not in use, it will be dropped from working set. An
important property of working set is its size. It can be of fixed size, i.e., there are a fixed
number of page references, for example 1,000 instructions. We can compute the total
number of pages referred in the recent  as WSSj (Working Set Size of Process Pj). If
 is too small, it will not encompass the entire locality. If  is too large it will encompass
several localities and if  = , it will encompass the entire program.
Let D be the total demand for frames and m be the total number of frames
available, such that:
D = WSSj
If D is greater than m , i.e., the total number of frames demanded is greater than
the number of frames available, a thrashing may occur. Thus, process j needs WSSj
frames. As some processes may not have enough frames to complete, we should suspend
one process instead of withdrawing few pages from all processes.
The functioning of the working set model is simple.The operating system monitors
the working set requirement of each process and allocate it. If there are extra frames
Self-Instructional
108 Material
available, a new process can be started. If the number of frames is less, one process has Storage Management
to be suspended. Thus, the working set model prevents thrashing while keeping the
degree of multiprogramming as high as possible.
Page Fault Frequency Scheme NOTES
Although the working set model is a successful technique and it also provides prepaging
information which improves the overall performance, it has a clumsy approach. So another
technique, called the page fault frequency scheme, is used which takes more direct
approach.
Thrashing occurs if there is a high page fault rate. To control it, we need to
establish an acceptable page fault rate. If the page fault rate is too low, the process holds
too many frames decreasing the number of frames available or it loses frame. However,
if page fault rate is too high, the process needs more frames and gains a frame.
Page Rate for Single Process
Working Set
too Small

Reasonable
Working Set
Page
Fault Rate

Working Set
too Large

Number of Pages

Fig. 3.18 Working Set Allocation and Page Fault

In order to avoid thrashing, we decide a range such that if the actual page fault rate
exceeds the upper limit, we allocate another frame to that process and if it falls below
the lower limit, we remove a frame from that process (refer Figure 3.18).
If page fault is too high then process needs more frames. Upper and lower bounds
are established on the desired page fault rate (refer Figure 3.19). In this way, the page
fault rate is directly measured and controlled to prevent thrashing.

Increase Number
Page Fault Rate

of Frames

Upper Bound

Lower Bound
Decrease Number
of Frames

Number of Frames

Fig. 3.19 Page Fault Frequency and Number of Pages

Self-Instructional
Material 109
Storage Management As with the working set strategy, a process is suspended. If the page fault rate is increased
and no free frames are available. For this, you need to select some process and suspend
it.
Remember the following points in page fault frequency design:
NOTES
 Increase the number of pages allocated to the process by one whenever the PFF
is greater than the upper bound.
 Decrease the number of pages allocated to the process by one whenever the
PFF is less than the lower bound.
 If the lower bound is less than PFF which, in turn, is less than upper bound then
replace a page in memory by some other reasonable policy.
The thresholds upper bound and lower bound are the system parameters and depend on
the amount of physical memories available.
Many issues are to be considered while designing a paging system for an operating
system, such as the size of pages, number of frames to be allocated, page replacement
policy to be adopted (global or local replacement policy), etc. We have already discussed
the page replacement policy. The number of frames to be allocated to each process in
case of a multiple process system plays an important role in the performance and
efficiency of a system. Allocation of frame is considered as deciding factor in design
issue for paging system. This concept is discussed below:
3.6.2 Allocation of Frame
In case of a single user, the system is very simple. We can allocate as many free frames
as the process desires. However, the situation is complex for a multiprogramming
environment where each process wants to get a frame. Each process requires a minimum
number of pages depending on its instruction set architecture. However, there are two
policies on which the number of frames allocated to a process depends: fixed allocation
and priority allocation. These two policies are discussed below:
Fixed Allocation
In this scheme, the number of processes allocated is proportional to degree of
multiprogramming. If multiprogramming increases, each program has to lose some pages
to accommodate new process. If multiprogramming decreases, the frame is departed
over the remaining process.
Equal Allocation: This is the simplest technique for allocating the processes. In
this technique, pages are divided equally to all processes. For example, if we have 20
frames and there are 4 processes, 5 pages are allocated to each process. However,
such an allocation is not advisable as all processes are not of the same size. If there are
four process and there requirement are 1, 2, 10, 15 respectively and we allocate 5 pages.
Process 1 and process 2 will have 5 pages of only 1 and 2 will be utilized thus 4 and 3
pages are respectively allocated to each process free while process 3 and 4 need page
and will result in page fault.
Proportional Allocation: To solve above the problem that arises in the fixed
allocation method, we allocate the frames according to size of the processes. Let the
size of virtual memory for the process Pi be Si and m be total number of frames available.
If S is the number of total frames required, then S = Sj

Self-Instructional
110 Material
The number of frames allocated to each process would be defined as follows: Storage Management

Pi ai = Si/S* m.
If total number of frame available is m = 50, S1 = 20, S2 = 180 then:
Number of frames allocated to process 1 is a1 = 20/200 * 50 = 5
Number of frames allocated to process 2 is a2 = 180/200 * 50 = 45 NOTES

Priority Allocation
In fixed allocation algorithms, a high priority process is treated same as a low priority
process. However, in priority allocation algorithms, more memory is allocated to a high
priority process than a low priority process. In this scheme, the distribution of pages is in
proportion to priorities instead of size. Often in a system, distribution of pages is based
on combination of size and priority.
Global vs Local Allocation
Another important design issue of virtual memory is the page replacement. If a process
generates a page fault, a question arises whether to select one of its own frames or to
select the frame from some other process having a lower priority. Thus, the page
replacement techniques are divided into two categories: global replacement and local
replacement. These categories are discussed below:
Global Replacement: Global replacement allows a process to select a replacement
frame from the set of all frames even if a frame is currently allocated to some other
process. Thus, one process can swap the page occupied by another process. In this
scheme, a high priority process is able to replace a low priority process. This scheme
gives a high priority to complete the process. However, the process may not be able to
control its page fault rate.
Local Replacement: The number of frames allocated to a process does not
change. Thus, a page has to be replaced only from the process’ own set of allocated
frames.
The global replacement technique gives better throughput than local replacement.
Hence, it is more commonly used. With global replacement, a process may replace a
frame allocated to other process, thus increasing the number of frames allocated to it.
This leads to a faster completion of the process. In the local replacement technique, on
the other hand, the process completion is slowed down because of more page faults
even though the less used pages of other process are available in memory. The only
problem with global replacement is that process cannot control its own page fault resulting
in starvation for low priority process.
Prepaging
In the pure demand paging technique, a page is brought to main memory only when
there is a page fault. Hence, the number of page faults is very high when a process
begins. Prepaging attempts to prevent the high level of initial page faults and is
advantageous when a process is swapped out and restarted again. In this situation, the
list of pages in working set of that process is maintained. The entire working set is
fetched again before restarting process rather than fetching one page at a time. The
advantage of prepaging depends on how many brought back pages are reused. If the
number of reused pages is small then it is better to go for the page fault technique. The
main function of prepaging is to reduce the page fault rate of reloaded processes and
hence generally improve CPU efficiency.
Self-Instructional
Material 111
Storage Management Page Size
The page size is another important design issue for a designer. While deciding the page
size, the Page Map Table (PMT) is used for translating the address. There is a trade off
NOTES between the page size and the size of PMT. The smaller the page size, the more will be
the number of pages. Thus, the size of virtual address, leading to a bigger PMT. This
allows PMT to map all the spaces of the virtual memory. For example, if a processor has
a 42-bit virtual memory address and a page size of 512 bytes (29 bytes), then there are
221 possible page table entries. If the page size is increased to 4 Kbytes (212 bytes), then
the PTT requires ‘only’ 220 or 1 M page table entries. These large page tables will
normally not be full, since the number of entries is limited to the amount of physical
memories available. One way these large, sparse PTT’s are managed is by mapping the
PTT itself into virtual memory.
Each active process has its own PMT. Hence, in a small page size, a large
amount of main memory will be wasted in storing big PMT. Thus, one may desire a big
page size. But this will result in an increase in internal fragmentation, as the bigger
the page size, the more will be the internal fragmentation and hence more memory
wastage.
Another concern is time spent in I/O overhead for seeking the page in case of
page fault. Consider the transfer of a single block from hard disk of 512 bytes. It takes
28.4 seconds to read a single page of 1K size but it takes 56.4 minutes to read the same
amount in two pages of 512 bytes each. This is due to the fact that in reading two
consequent pages, the latency time in transfer rate is lesser as compared to reading half
sized pages located at different locations on disk. Thus, to minimize the I/O time a larger
page size is required.
However, the smaller the page size, the better will be the implementation of
reference of locality. A smaller page size provides a better resolution, allowing us to
isolate the memory that is actually needed.

3.7 SUMMARY
Check Your Progress  Memory management refers to move processes back and forth between main
memory and disk during paging and swapping. The prime objective of memory
16. What is the
function and aim of
management is to divide the main memory for accommodating multiple processes.
page replacement  The binding of instructions and data to actual memory location can occur at three
algorithm?
different stages, namely compile time, load time and execution time.
17. Why is a clock
implemented in  The absolute code can be generated if the exact location of the process in the
LRU page memory can be observed at compile time. This type of binding is termed as
replacement
compile time binding.
algorithm?
18. What is thrashing?  A process is loaded into a single partition. To accommodate every process in the
19. What are upper partition, the partition size is selected based on the largest process size.
bound and lower
 An operating system keeps track of memory segments that are free and occupied.
bound threshold?
The operating system allocates memory to the process when process is to be
20. What is the use of
page map table used executed and de-allocates the memory when the process terminates.
the size?  Compaction technique is used to solve the external fragmentation problem. In this
technique, the non-contiguous memory holes are combined together that is all the
used memory is moved towards one end of the memory and the unused memory
Self-Instructional is moved towards the other end.
112 Material
 Dynamic loading refers to the process of copying the loadable image into memory, Storage Management
connecting it with any other programs already loaded and updating addresses as
needed.
 Dynamic linking refers to the process of combining a set of programs including
library routines to create a loadable image. NOTES
 The function overlay helps a process to be allocated even if it has a size larger
than the amount of memory allocated to it.
 The two types of memory allocation techniques are contiguous allocation and
non-contiguous allocation. In the contiguous allocation technique, each process
occupies a continuous memory location. Non-contiguous physical addresses are
allocated to a process to solve the problem of external fragmentation and to some
extent internal fragmentation.
 The physical memory is divided into fixed size memory blocks known as frames.
 The logical memory is divided into fixed size memory location called pages. The
size of the frame is equal to the size of the page.
 The address generated by the CPU is divided into two parts—the page number
and the page offset.
 If the processor executes thousands of instruction per second then for each
instruction the page table is consulted.
 Translation Lookaside Buffer (TLB) is a hardware cache within the processor’s
bus interface unit which stores recently used copies of page table entries. The
main function of TLB is to speed up conversion from virtual address to physical
address.
 The memory management technique that supports the users’ view of memory is
known as segmentation. Segmentation is different from paging. In paging, the
logical memory is different from the users’ view of memory in segmentation; the
logical memory is same as the users’ view of memory.
 In the MULTiplexed Information and Computing System (MULTICS), the problem
of external fragmentation is solved by using segmentation with paging. The lengthy
search times is reduced by paging the segments.
 Virtual memory is a technique that allows the execution of processes that may
not be completely loaded in the memory. It enables to execute a program or
software with a size larger than the physical memory available. Virtual memory is
commonly implemented by demand paging or demand segmentation.
 The function of page algorithm is to find a page that is not in use or will not be
used in the near future and swap it with the page required. The aim of any page
replacement algorithm is to ensure minimum page fault.
 The first and simplest algorithm is the First In, First Out (FIFO) algorithm. This
algorithm suggests that the oldest page should be removed.
 Least Recently Used (LRU) page replacement algorithm is based on the principle
of reference of locality, which states that if a page is used in the recent past, there
are good chances that it will be used in the near future.
 A stack in the form of a doubly linked list is used for storing the page number.
Whenever a page is referred, it is moved to top of the stack and page number
which is at the tail of stack is replaced as this is the least recently used.
Self-Instructional
Material 113
Storage Management  Thrashing is a situation where processor is busy in handling the page faults, i.e., it
swaps page in and swaps page out. Thrashing happens when a hard drive has to
move its heads over the swap area many times due to the high number of page
faults.
NOTES  The thresholds upper bound and lower bound are the system parameters and
depend on the amount of physical memories available.
 The Page Map Table (PMT) is used for translating the address to decide the
page size. The smaller the page size, the more will be the number of pages.
 The smaller the page size, the better will be the implementation of reference of
locality. A smaller page size provides a better resolution, allowing isolating the
memory that is actually needed.

3.8 KEY TERMS


 Symbolic name: It refers to the name with which a user identifies the components.
 Physical name: It refers to an actual physical address of entity, such as address
of file or data on disk or memory. It can be fixed once it enters or variable
relocatable address.
 External fragmentation: It refers to the division of free storage into small pieces
over a period of time, due to an inefficient memory allocation algorithm, resulting
in the lack of sufficient storage for another program.
 Compaction: It refers to the combination of memory available at different places
into a single large memory.
 Dynamic linking: This technique is used to load system library functions,
subroutine libraries, etc.
 Overlay area: This area signals the overlay handler which swaps out the old
program segment and swaps in the next program segment with the help of device
drivers, interrupt handlers and exception handlers.
 Segmentation: It refers to the memory management technique which supports
the user’s view of memory.
 Virtual memory: It is a technique that allows the execution of processes that
may not be completely loaded in the memory. It enables to execute a program or
software with a size larger than the physical memory available. Virtual memory is
commonly implemented by demand paging or demand segmentation.
 Fixed replacement schemes: It refers to page replacement algorithms in which
the number of pages allocated to a process is fixed.
 Variable replacement schemes: It refers to page replacement algorithms in
which the number of pages available for a process varies during the whole life
cycle of the process.
 Thrashing: It is a situation where processor is busy in handling the page faults,
i.e., it swaps page in and swaps page out.
 Equal allocation: It refers to a technique in which pages are divided equally to
all processes.

Self-Instructional
114 Material
 Global replacement: It allows a process to select a replacement frame from Storage Management
the set of all frames even if a frame is currently allocated to some other process.

3.9 ANSWERS TO ‘CHECK YOUR PROGRESS’


NOTES
1. Memory management refers to moving of processes back and forth between
main memory and disk during paging and swapping process.
2. If data binding is done at the compiler level then this process is called early
binding.
3. Compaction is a technique that is used to solve the external fragmentation problem.
4. Dynamic linking refers to the process of combining a set of programs including
library routines to create a loadable image.
5. Overlay function helps a process to be allocated even if it has a size larger than
the amount of memory allocated to it.
6. The two types of memory allocation techniques are known as contiguous allocation
and non-contiguous allocation.
7. The logical memory is divided into fixed size memory location called pages.
8. The prime function of TLB is to speed up conversion from virtual address to
physical address.
9. The memory management technique that supports the users’ view of memory is
known as segmentation.
10. The syntax used for logical address in the segmentation is the tuple with segment
name and offset and the syntax used for it is <Segment-name, offset>.
11. The role of segment table is to store the mapping of two-dimensional address to
one-dimensional address.
12. The MULTICS system is used to solve the problem of external fragmentation
using segmentation with paging. The lengthy search times is reduced by paging
the segments.
13. The basic principle behind the virtual memory technique is to store those sections
of program instructions and data that are not currently used in hard disk.
14. Demand paging increases the degree of multiprogramming which allows a process
to run even it exceed the physical space allocated for it.
15. A trap is generated by the operating system.
16. The function of page algorithm is to find a page that is not in use or will not be
used in the near future and swap it with the page required. The aim of page
algorithm is to ensure minimum page fault.
17. A clock is implemented in LRU page replacement to determine the page to be
replaced.
18. Thrashing is a situation where processor is busy in handling the page faults, i.e., it
swaps page in and swaps page out.
19. The thresholds upper bound and lower bound are the system parameters and
depend on the amount of physical memories available.
20. The page map table is used for translating the address while deciding the page
size. Self-Instructional
Material 115
Storage Management
3.10 QUESTIONS AND EXERCISES

Short-Answer Questions
NOTES
1. Write the names which are used in address binding.
2. Why loader is needed at load time?
3. What is the function of free hole in dynamic storage allocation?
4. What is prepaging?
5. What are translation lookaside buffers?
6. Define segmentation.
7. Write one function of virtual memory.
8. Why is page table modified?
9. Name the classes of replacement schemes.
10. Define least recently used page replacement algorithm.
11. What is working set Window?
12. What are known as system parameters in page fault frequency scheme?
13. Differentiate between global and local replacement.
Long-Answer Questions
1. Define memory management. What is the role of contiguous allocation of memory
in memory management?
2. Differentiate dynamic linking and loading techniques with the help of examples.
3. Explain the management of overlay with the help of diagram.
4. Illustrate address translation scheme with the help of paging process.
5. Write a short note on hardware support for paging.
6. Explain the process of mapping the logical address to the physical address with
the help of diagram.
7. Define protection. Explain the role of valid-invalid bit in deciding and protecting
the segmentation techniques.
8. At which level sharing process is done? Explain this process with the help of an
example.
9. Write a short note on segmentation with paging.
10. Illustrate internal operation of memory management unit with the help of example.
11. What are the advantages and disadvantages of demand paging?
12. Discuss the causes of thrashing.
13. Explain page fault frequency scheme with the help of diagram.
14. Explain the role of page size which is decided in paging system while designing
the page.

Self-Instructional
116 Material
Storage Management
3.11 FURTHER READING
Silberschatz, Abraham, Peter Galvin and Greg Gagne. Operating System Concepts,
John Wiley & Sons, 2004. NOTES
Tanenbaum, Andrew S. Modern Operating Systems, Prentice Hall, 2001.
Mano, M. Morris. Computer System Architecture. New Jersey: Prentice Hall Inc.,
1993.
Peterson, J.L., Abraham Silberschatz and Peter B. Galvin. Operating System Concepts.
New York: Addison Wesley, 1994.
Louise I. Shelly 2020 Dark Commerce

3.12 LEARNING OUTCOMES


 Understand the concept of memory management
 Address binding, contiguous allocation, overlay, dynamic linking and loading
 Paging, paging process and hardware support for paging
 Segmentation and paging with segmentation
 Virtual memory and demand paging
 The various page replacement algorithms
 The concept of thrashing and allocation of frame

Self-Instructional
Material 117
File System Interface

UNIT 4 FILE SYSTEM INTERFACE


Structure NOTES
4.0 Introduction
4.1 Unit Objectives
4.2 Concept of a File
4.2.1 File System Structure and Implementation
4.3 File Systems Organization
4.3.1 Techniques of File Organization
4.3.2 File Attributes
4.3.3 Directory Structures
4.3.4 Operations on Directory
4.3.5 File Protection
4.3.6 Secondary Storage Management
4.4 Protection Concepts
4.5 Security Problem
4.5.1 User Authentication
4.5.2 Program Threats
4.5.3 System Threats
4.6 Summary
4.7 Key Terms
4.8 Answers to ‘Check Your Progress’
4.9 Questions and Exercises
4.10 Further Reading
4.11 Learning Outcomes

4.0 INTRODUCTION
In this unit, you will learn about the concept of file system interface. Files may be
created and deleted. A logical file system stores metadata information. This includes
the file system structure excluding the actual contents of the file. You will also
learn the concept of file system organization, such as techniques of file organization,
piles, sequential files, indexed sequential file direct access, file attributes, directory
structures as well as acyclic graph directory. A file system normally associates a
directory structure to organize or keep track of files in the computer system. A
directory contains information about files, for example location, ownership and
other attributes. In secondary storage management, you will learn the concept of
file allocation methods, such as contiguous allocation, linked allocation, indexed
allocation and free storage management. Protection is a mechanism that is used to
control the access to system resources. Each process has an associated protection
domain which specifies all resources that are accessed by a process domain that
consists of objects and operation for those objects. A user is given the ability to
execute an operation. This ability is called access right. You will also learn about
the security problems in the file system interface. Security is of two types: internal
and external. Security measures are taken to protect the system from unauthorized
access. The user must install antivirus software on the system to protect it against
malwares or malicious software because it attempts to damage the resources of the
target system.
Self-Instructional
Material 119
File System Interface
4.1 UNIT OBJECTIVES
After going through this unit, you will be able to:
NOTES  Understand the concept of a file
 Know about the implementation as well as structure of the file system
 Describe the organization of the file system
 Explain the various protection concepts of the file system
 Define the security problems in the file system interface
 Explain the basics of user authentication, program threats and system threats

4.2 CONCEPT OF A FILE


From a user’s point of view, a file is simply a collection of similar records. It is
referenced by a unique name. In the view of an Operating System (OS) designer or
a system programmer, it is an abstraction mechanism on storage devices. Information
may be classified and represented in files on storage devices. Files may be created
and deleted. A secured file system must provide some access control mechanism to
protect the files, i.e., file access like read, write and execute by different users must
be controlled by the owner of the files. Files of an owner can be placed in folders
called directories. A directory is also a file used for recording the name and attributes
of files. We can also place other directories within a directory.
Naming Files
File systems provide some naming techniques to provide names for each of the
files. The number of characters that can be used for creating names of files varies
from system to system. Early file systems permitted only limited number of characters
(1 to 8 characters) for naming. However, recent file systems permit long names for
files. Many file system provide two or more part names with the parts separated by
a period, for example sort.c. The part following the period (dot) is called file
extension. File extension sometimes indicates the type or class of data stored inside.
Issues in Naming Files
Techniques used by the OS for naming the files are called name spaces. There are
two name spaces, namely flat name space and hierarchical name space. An operating
system may provide any one of them for naming files. In flat name space, there will
not be multiple directories for classifying and organizing files. So, all the names
must be different. Two files cannot have the same name.
In hierarchical name space, the files are organized in nested directories, i.e.,
there will be a root directory and within the root there will be many subdirectories
and each subdirectory can have again subdirectories within it to many levels. So,
files can have same names as long as they belong to different directories. So, a file
or directory can have a local name relative to the present working directory and a
full name or absolute name relative to the root directory.
Processes or users can now reference a file using its full name or a relative
name that is based on the working directory. UNIX denotes root directory by /
Self-Instructional (front slash) and Windows denotes it by \ (backslash). Suppose prog1.c is a file in
120 Material
subdirectory cp of directory named programs in root. We can write the full name or File System Interface
absolute name of the file as /programs/cp/prog1.c in UNIX and\programs\cp\prog1.c
in Windows. If cp is the working directory, we can refer the file by the local name
progr1.c. If programs is the working directory, we can refer it by cp\prog1.c or cp/
prog1.c. NOTES
Types of Files
Most general purpose operating systems support several types of files. UNIX and
Windows support regular files and directories. UNIX also supports block special
files and character special files. Regular files are used to store users’ information
which the normal users can manipulate. Directories are system files used for
providing a classified view of the files based on the information content and other
attributes like the owner of the files. Character special files represent serial Input/
Output (I/O) devices. Well known serial I/O devices are terminals (keyboard, mouse
and Cathode Ray Tube (CRT), printers and network. An operating system does I/O
to these devices just by writing to or reading from character special file abstractions
of these devices.
Disk storage devices are modelled as a block special file where information
is accessed as blocks.
Magic number
Text size
Data size
BSS size
Symbol table size
Entry point
Reserved
Flags

Text

Data

Relocation bits

Symbol table

Fig. 4.1 An Executable File Format

Regular files are the American Standard Code for Information Interchange (ASCII)
text files or binary files. Text files can be displayed or printed and can be edited
with a text editor. Most programs use text files for I/O. Executable files are examples
of binary files. They are stored in some format so that the operating system can read
it properly and execute them. A binary executable file format of UNIX is shown in
Figure 4.1. The first eight entries are the headers describing the file and the layout
of data inside. The magic number indicates the file format. Text contains the program
code, data is the global and static storage used for variables. Relocations bits are
Self-Instructional
Material 121
File System Interface used to adjust the absolute addresses when the program is moved from one region
to the other in memory. Symbol table contains the various attributes of names and
variables used in the program.

NOTES 4.2.1 File System Structure and Implementation


Files store data. A file system facilitates how files are stored so that they can be
retrieved easily. File system implementation makes use of disk structures as well as
memory structures.
A file system includes the following:
 Definitions of file attributes.
 Definitions of operations.
 Definitions of directory structures.
 Definitions of algorithms and data structures to map the logical file system
onto the physical file system.
A file system is generally divided into several layers where each layer uses
the services of the lower layers and creates new services for the higher layers (refer
Figure 4.2).
Application programs

Logical file system

File organization module

Basic file system

I/O control

Devices

Fig. 4.2 File System Structure

The lowest layer I/O control transfers data between the main memory and the
disk system. The I/O control layer uses device drivers that send specific bit patterns
Check Your Progress to the I/O controller memory. The I/O controller decodes the bit patterns and decides
1. Define the term what action must be taken on which device location.
directory. This layer knows how a logical block address can be translated into a physical
2. What does file block address. It uses file allocation methods to find the location of the file.
name extension
indicate? A logical file system stores metadata information. This includes the file system
3. How are root structure excluding the actual contents of the file. This layer also manages the
directories indicated directory structure. A file control block is a part of this layer.
by UNIX and
Windows?
4. What is the use of a 4.3 FILE SYSTEMS ORGANIZATION
file system?

The file system is an important part of any operating system because it stores the
data under various applications. Also, it keeps record in a systematic and logical
Self-Instructional
122 Material
manner so that the data can be retrieved, viewed and opened easily. We know that a File System Interface
file is a collection of records and is considered as key element in a file management
system. The records are systematically organized in the file because it affects system
performances. The word ‘organization’ refers to the logical and systematic
arrangement of the files in the disk which is based on the specific ordering. Hence, NOTES
the logical data organization is done using simple techniques based on the relevance
to data management from the lower level, i.e., database point of view of an OS.

4.3.1 Techniques of File Organization


The major techniques of file organization are discussed below:
Piles
In this, information is written to the file as per the order of arrival. Each record
consists of one burst of data. Records may have different fields or similar fields in
different order. Thus, each field should be self describing, including field name and
value. The length of each field may be indicated by delimiters or by values in subfield
or by default values. As there is no order or structure in the placing of records they
are accessed only by exhaustive search.
Sequential Files
In sequential files, the records are placed in the order of arrival. Physical contiguous
blocks are used to store the record sorted in the order of entry to the file. The order
cannot be changed or the length of the record cannot be altered or the record cannot
be deleted. We can read or write or update content of the records sequentially. New
records are appended to the end of the file. A sequential access file model is shown
in Figure 4.3.
Beginning
of file Current position
of file pointer

Rewind Read or write


End
of file

Fig. 4.3 Sequential Access File

Indexed Sequential Files


Indexed sequential organization can improve the speed of file access considerably.
In this, the data are organized into two files: one is an index file and the other is
called relative file, the file containing the actual records. The index file contains a
small number of index records each with two fields. The first field is the key that
stands for a group of contiguous records in the sequential access record file (relative
file) and the second field is the pointer (offset) to the first record in each group of
records in the relative file. An illustration of organization of an indexed sequential
file is shown in Figure 4.4. The key value of each index could be the value of the
key field of the first record in each group with sorted index fields as shown in
Figure 4.4. There will be as many index records in the index file as the number of
groups of records in the record file.
Self-Instructional
Material 123
File System Interface To search for a record, the key of the record is first searched in the index file.
This is done by comparing the search key with the index keys sequentially until an
index key that is greater than the search key (assume keys are sorted in ascending
order) is found. Choose the previous record as the index record of the group of
NOTES records that we are looking for. The pointer field of this record will point to the first
record of the group. Now, sequentially search the record from the group. If the
record is not available in the group then the search will find the first record in the
next group to terminate the search indicating the absence of the record looked for.
To see how much speed is achieved by employing an index file, we will
consider 10,000 records arranged as 100 groups with 100 records in each. So, the
index file will have 100 index records. Now, with direct sequential search with no
index a linear search requires on the average 5000 key comparisons. With index file
based search, to sequentially search the index file requires on an average 50
comparisons and then to search within a record group of relative file requires another
50 comparisons, i.e., a total of 100 comparisons. This means, a significant reduction
of number of comparison from 5000 to 100 or 50 to 1.
Further speed may be achieved by adding more indexes. We can add second
level index and third level index and so on to bring down the search time further.
However, as the levels of index increases, the storage requirements also increases.
Finally, at some level of index the benefit index search may offset due to the increased
cost of additional storage space.

Logical record
Index field number Name Place of birth Age Address
Adarsh
Asha

Rehan UP 34 India
Rahul Roma Chennai 25 India
Rehan Ruki Mumbai 22 India

Relative file where the


Record index file record is placed

Fig. 4.4 Indexed Sequential File

Inverted List or Index File


To make the search faster and to enable search on many attributes of data record, an
organization called index file or inverted list is employed. In an inverted list, indexes
on more than one attribute of records are used to access the data faster. Every key
type will have index. The records need not be stored in any sequence in the data
file. All index fields are updated for the location of the record. For example, to
enable fast search on products and product types, from the product file of a company,
we can maintain an index for all products and another index for all product types.
Inverted list or index file technique may be used to implement content based
query search system.
Self-Instructional
124 Material
Direct or Hashed Access File System Interface

Direct access or hashed access organization may be used to access the record much
faster than indexed sequential or inverted list organization. In this organization,
there is an index file like that of the indexed sequential organization. An index to NOTES
the record in the index file is generated by applying a suitable hash algorithm on the
search key. This hash indexed record of the indexed file maintains the location of
the record on the disk block so that the record can be easily retrieved on generating
the hash on the search key. So, if the entire hash index file can be stored in a single
block of disk then any record can be accessed with two disk block access operations.
Hashed access organization provides excellent performance for search retrieval.

4.3.2 File Attributes


Each file has a set of properties or characteristics called attributes. They are given
values at the time of creation. Some of the attribute values may change with the
usage of the file. Different operating systems may use slightly different sets of
attributes for their files. However, many attributes are common for all systems. The
following are some of the important attributes of a file:
 Name: This is recorded in user readable format.
 Identifier: This is the tag number to identify file inside file system.
 Type: Various types of files are supported in some systems.
 Location: This attribute maintains location of file (file block numbers) on
the device where it is stored.
 Size: Current file size of the file.
 Flags: Bits to indicate file properties like hidden, system file, read only,
directory, etc.
 Protection: Protection attributes control the access of file, such as who all
can access the files and what operations they can do.
 Time and Date: Maintain the time and date of creation and last modification.
 User Identification: This is required for the usage monitoring and protection
and security of resources.
The set of file attributes provides the operating system and application software
more information about the file and how it is intended to be used. Each file is
created and placed in a folder known as the directory as desired by the owner of the
file. There will be one entry in the directory for each file and the file attributes are
stored in that entry.
File Operations
As mentioned earlier, files are used to store information for later use. So, users need
to do various operations on the files to accomplish their task. The file system provides
suitable interfaces to users for doing these operations. Most common operations on
files are: Create, Delete, Open, Close, Read, Write, Append, Seek, Get Attributes,
Set Attributes and Rename. These are actually the interfaces to file system for users.
These are described briefly in the following:
 Create: Creates a new file with a given name.
 Delete: Removes the given file from the directory system.
Self-Instructional
Material 125
File System Interface  Open: Opens an existing file for designated operation like reading or writing.
 Close: A file is closed when no more access to it is needed. Close operation
saves the contents of file (memory image of the disk block ) on to the disk.

NOTES  Read: Reads the specified size of data usually from the current file pointer
position.
 Write: Writes the specified size of data usually from the current position of
file pointer.
 Append: Adds data at the end of file.
 Seek: Repositions the file pointer to the specified position.
 Get Attributes: Returns attributes of files.
 Set Attributes: Sets user settable attributes.
 Rename: Changes the name of file/directory.
4.3.3 Directory Structures
A file system normally associates a directory structure to organize or keep track of
files in the computer system. A directory contains information about files like
location, ownership and other attributes. A directory is also like a file except that it
is used for storing attributes of files and owned by and managed by the operating
system. A user cannot directly access directories to read/write attributes. However,
some of the attributes can be accessed indirectly through system calls.
The structure of directories may be different for different file systems. To
provide an efficient directory structure is an important task of the file system designer.
This has significance also on the user interface provided by the file system. The
directory structure can be organized in various ways like single level, two level,
hierarchical or tree structured and acyclic graph directory structure. The tree structure
is the most used structure in file systems. Important directory structures are discussed
as follows:
Single Level Structure

Directory

UG PG MCA OS IP CP EMAIL Projects

Files

Fig. 4.5 Single Level Directory

The simplest design is the single directory structure shown in Figure 4.5. All
the files of the system have to be in this single directory. All the files must have
different names. This is very inconvenient, especially when there are many users in
the system. Normally a user prefers to use names that reflect the content of the files.
If different users name the file with this strategy, it is very likely that they arrive at
the same name for their files. With single level directory, it is difficult for a user to
protect his files from other users of the system. Even with single user systems,
keeping track of a large number of files is difficult. This structure is used only in
small, single user systems with a few files to handle.
Self-Instructional
126 Material
Two Level Structure File System Interface

Root/Master
file directory user1 user2 user3 user4 user5 user6

NOTES

User file
OS CP IP MCA AI CP UG sales book emplo
directories

Fig. 4.6 Two Level Directory Structure

An improvement to the single level directory is to have one directory per user
shown in Figure 4.6. Files of each user can be put in a different directory so that
problems with the use of same name can be eliminated. It is easy to provide
security for each user’s files. However, it is very difficult to organize the different
categories of files of a single user in one directory. Sharing files of other users is
also difficult.
Tree Structures

Root directory
Users Programs Bin

user1 user2 W M CC java L

OS CP IP MCA AI CP UG A B C
C C# CPP

AI CP CC AA CP DS

Fig. 4.7 Tree Structured Directory

Shown in Figure 4.7 is a tree structured directory which permits subdirectories


at many deeper levels. So, a user can arrange his files according to types in many
directories and subdirectories in a hassle free manner. Tree directories are efficient
for search and grouping files.
Now, the problem is about how to handle the deletion of a directory. Normally,
a directory can be deleted only if it is empty. It is difficult to delete a directory that
contains several files, and possibly subdirectories. One has to delete all files and
subdirectories. This is a laborious task when there are nested subdirectories at many
levels. However, in newer systems like Windows Explorer, deletion of directories
are done in one command without the concern for files and subdirectories contained
in.
Self-Instructional
Material 127
File System Interface Acyclic Graph Directory
Another useful structure is the acyclic graph shown in Figure 4.8 which permits
sharing of directories and files. This is an extension of tree structured directory. The
NOTES same physical file can be present in more than one directory with different names
called links. The drawback is that it is very difficult to delete files. A file can be
physically removed only when all the references (links) to the file are deleted.

Users Programs Bin


Root directory

user1 user2 W M CC java

OS CP IP MCA AI CP UG
C C# CPP

OS CP CC

Fig. 4.8 Acyclic Graph Directory

4.3.4 Operations on Directory


A file system does all these operations. Users are given interfaces (access to the
functions for doing these operations) to the code of the file system that does these
operations. Following are the major operations done on directories:
Create: An empty directory is created. It contains no user files but includes
files with name .(dot) and ..(dot dot) which are put by the file system. They are
actually used by the system to traverse the directory structure.
Delete: The given directory is deleted. Only empty directory can be normally
deleted by this operation.
Opendir: Opens the directory for reading.
Closedir: To close the directory.
Readdir: To read the directory for listing files.
Rename: To change the name of the directory.
Link: Creates a link to an existing file. This allows a file to appear in more
than one directory.
Unlink: A directory entry is removed. The corresponding file is removed if
there is no other link for the file in other directories.

Self-Instructional
128 Material
Table 4.1 Difference between Tree Structure and Acyclic Graph File System Interface

Acyclic Graph Tree Structure


In data structure, acyclic graph follows A tree structure has directed path and has
no nonempty directed path so it reduces one root node. Its performance is faster
the performance time. than acyclic graph. NOTES
Acyclic graphs refer to reference graphs It does not use reference graph to collect
that use garbage collection by using garbage collection.
simple reference counting.
These graphs support functional data Tree structure also supports data structure
structure which allows cyclic structure but by using a set of nodes.
process.
Acyclic graphs are considered as It has subtree whose node is the root of a
‘worker of no node overlapping’. subtree. Node does not overlap in this
mechanism.
They use hard link property, such as Tree structure, for example, tree class
duplicate directory entries to implement uses link list property.
shared files and directories.
The following figure shows that acyclic The following figure shows the tree
graph is considered as the class structure. The construction of tree is
hierarchy: basically classified on the basic three
processes, such as root, parent and child.
In the following figure A, B, C and D are
The criteria of splitting of nodes depend
the four classes that allow acyclic flow
on the declaration of terminal node or the
of data structure. The arrow sign depicts
assignment of each terminal node to a
clearly that control goes from D either to
class.
B or C. It cannot directly interact with A.
So, interaction among classes is only
possible if they would be declared Variable
virtually by defining ‘virtual’ keyword to X1

maintain class hierarchy.


Variable Split 1
Variable
D X2 X3

Split 2 Split 3
B C
Variable
X4
Terminal Node Terminal Node Terminal Node
1 2 3
A
Split 4
Acyclic Graph
Terminal Node Terminal Node
4 5

Tree Structure

4.3.5 File Protection


The file system should provide tools for allowing file sharing among users. The
owner of the files must have the right to control the set of operations that can be
done on files and who all can do such operations. The following are some types of
access rights or operations that can be granted to the users of the system:
 Read: The user can read a file for any purpose including copying and
execution.
 Write or Update: The user can modify, delete and add data.
 Execute: The user can load a file to memory and execute but cannot copy.
 Append: The user can add data to a file at the end but cannot modify or delete
any content.
 Delete: The user can delete a file from the file system.
 List Directory: The user can view a list of the directory.
Self-Instructional
Material 129
File System Interface The users of the system are grouped to grant access privileges in a controlled
way. The early UNIX supported three categories of users of the system—owner,
group and public (everyone)—and three types of accesses—read (R), write (W)
and execute (X). Nine bits of storage are used to record the access permissions in
NOTES the attribute set of the file for the three categories of users. A ‘1’ value indicates
permission of the right and ‘0’ value indicates absence of permission. The technique
of recording is as given below:
Owner access: RWX
Group access: RWX
Public access: RWX
Total nine bits as: RWX RWX RWX
For the owner to have read, write and execute rights, the pattern RWX= 111
is used.
For the group to have read and write permission (no permission to execute),
the pattern RWX= 110 is used.
To give ‘execute only’ permission for everyone, the pattern RWX= 001 is
used.
So, the value of the nine access permission bits will be written as 111 110
01. The first three for owner’s rights, the second three bits for group rights and the
third three bits for public rights to the file.
4.3.6 Secondary Storage Management
A file consists of a collection of storage blocks on the secondary storage. A schematic
representation of file system blocks in secondary storage is shown in Figure 4.9. A
block may consist of one or more sectors on the storage device. The file management
system of the OS must allocate blocks of storage for files. It must also keep track of
the available space on the disk. So, file allocation problem involves many issues
like the following:
 What should be the size of the storage space or the number of blocks allocated?
 When should the space be allocated—statically, at the beginning itself or
dynamically, according to the need as the file grows?
 Should the blocks allocated be contiguous or not?
 What data structure will be used to keep track of available space so that the
allocation is faster?
The storage space allocation techniques and the free space management
techniques discussed in the next subsections address these issues in details.

0 1 2 3 4 5
6 7 8 9 10 11
12 13 14 15 16 17
18 19 20 21 22 23

24 25 26 27 28 29

30 31 32 33 34 35

36 37 38 39 40 41

Fig. 4.9 Storage Blocks on File System


Self-Instructional
130 Material
File Allocation Methods File System Interface

Allocating secondary storage space is a major task that a file system must do. The
space must be allocated in such a way that the files can be accessed faster and space
can be utilized without much loss due to fragmentation problems. There are various NOTES
techniques or strategies used by different systems for allocation of storage space.
Contiguous allocation, indexed allocation and linked allocation are the major
techniques. A file system normally provides only one of these techniques for storage
allocation to files. A few systems provide more than one strategy for storage space
allocation. All these methods of allocation have their merits and demerits as
mentioned in the following descriptions of these methods.
Contiguous Allocation
In this technique of storage allocation, files are given block numbers that are
contiguous on the storage device. On the disk, the addresses of disk block start from
0 and increase linearly and then end at (DiskSize -1) as shown in Figure 4.10. For
example, the size of the storage device shown in Figure 4.10 is 42 file system blocks.
In Figure 4.10, the storage blocks allocated for three files F1, F2 and F3 are shown
as shaded area. Three contiguous blocks starting from block 7 are allocated to file
F1, 4 contiguous blocks starting from block 12 are allocated to file F2 and 7
contiguous blocks starting from block 26 are allocated to file F3. These addresses
are recorded in the directory entries of these files as shown in the right part of
Figure 4.10. In this allocation, as long as the blocks allocated to a file belong to the
same cylinder, no read/write head movement is required to access the next block of
a file from the current block. If storage is allocated to multiple adjacent cylinders,
only one (one track) head movement is needed to move from the last block of
current cylinder to the first block of next cylinder. That means, contiguous allocation
requires only minimum head seek time. Track skewing may be employed to minimize
the performance degradation due to the extra cylinder seek required in some cases.

Directory entries
Starting block Num.
File name number Blocks

F1 7 3

F2 12 4

F3 26 7

Fig. 4.10 Contiguous Blocks allocated to Three Files

Advantages
Fast access of file is possible. Any record can be accessed in one disk read as the
block number of the record may be computed easily and that block alone can be
brought to the main memory for access.
Self-Instructional
Material 131
File System Interface Disadvantages
Even though the access is fast with contiguous allocation, following are number of
disadvantages of this technique.
NOTES  Difficult to search space for creating a new file: As we create and delete
files on the disk, the free space on the disk will be scattered, and it is very
difficult to look for spaces required for creating new files. A file for example,
may require five contiguous blocks for copying an existing file to a new file.
The operating system has to search in the available contiguous free blocks
for these five blocks. We can use algorithms, such as best fit, first fit and
worst fit and their variants for searching free memory holes of the right size
from a set of available holes. First fit is usually faster and worst fit produces
less fragmentation problem. Best fit leaves larger holes for later use but
fragmentation problem is severe with this technique.
 External fragmentation problem is severe: As we allocate and make free
storage spaces many times due to creation and deletion of files, a state may
be reached in which all the free holes on the disk may be so small that it
cannot be allocated to meet a request for a given size. However, the sum of
the total free block holes is larger than the requested size of free blocks. That
is, the holes are distributed so that a contiguous space of required size is not
available. This state of storage allocation is called external fragmentation
problem.
 The amount of storage required for the file must be known in advance:
This is another severe problem with contiguous allocation. In most of the
cases, it is difficult to predict the total storage requirement of a file. So, when
the file size grows exceeding the currently allocated size, a new contiguous
free area of appropriate size must be looked for, and all data must be copied
from the previously allocated contiguous area to the new area. This requires
increased overheads for searching new free holes and copying the entire
existing data of the file to the new area.
Linked Allocation
In linked allocation, the space for the file can be allocated in non-contiguous area,
thus eliminating the severe external fragmentation problem present in the contiguous
allocation. The blocks of a file are distributed anywhere in the storage space as
shown in Figure 4.11, where the scenario of blocks allocated to three files in linked
allocation is depicted. The blocks of a file are linked by placing pointers at the end
of each block except for the last where a null pointer is placed to indicate that it is
the last block of a file. For example, File F1 is allocated blocks 15 (start block), 22
and 11. Block 15 carries at the end of it the address 22 (the address of the next
block) and block 22 carries the address 11, the next and last block of this file. A null
pointer (may be –1) is placed at the end of block 11 to mark the last block of this
file. Similarly, file F is allocated blocks 12, 25, 30 and 36 whereas file F3 is allocated
blocks 8, 14, 19, 26, 27, 29 and 34. The address of the first block of each file is
entered in the directory entry while creating the file. An empty file (a file with no
data) may be created by adding a null value instead of the block address in the
directory entry. When data is to be added, a new block is requested dynamically and
if it is the first data block, its address is paced in the directory entry, otherwise, its
address is placed in the present last block of the file to link it to the existing linked
Self-Instructional
132 Material
list of blocks. A null value is entered to the last location of the new block allocated. File System Interface
So, allocation is done block by block as the need arises to allow growth of files
easily.

NOTES
File name Start block
F1
F3
F2 F1 15
F3 F1

F3 F1 F2 12

F3 8
F2
F3 F3 F3

F2
F3
F2 Non-contiguous blocks of a file are
linked through pointers

Fig. 4.11 Linked Allocation of Blocks to Three Files F1, F2, and F3

Advantages
Following are the advantages of linked allocation technique:
 There is no external fragmentation problems as the blocks are permitted to
be distributed anywhere in the storage space.
 Finding free space for adding new data may be done easily.
 There is no need to declare file size in advance. File can grow dynamically
without the overheads of searching free contiguous blocks and copying of
blocks.
Disadvantages
Following are the disadvantages of linked allocation technique:
 Difficult to support direct access: To read the data in the fifth block of the
file, for example all the previous four blocks must be read to get the address
of the fifth block. This allocation technique is suitable only for sequential
access.
 Low reliability: As the data and the pointer to another block are stored in a
block, loss of a pointer due to disk hardware failure or due to other bugs may
lead to the loss of almost all data of the file. This may also lead to accessing
blocks allocated to other files or blocks that are in the free space.
Indexed Allocation
Indexed allocation technique eliminates almost all the drawbacks of contiguous
and linked allocation techniques. In this approach, each file has an index block
where the addresses of all blocks of the file are placed. So, the pointers are not
distributed to blocks but concentrated in a single block. However, the blocks can be
distributed anywhere in the storage space as in the case of linked allocation
eliminating the external fragmentation problem. The address of first data block of
Self-Instructional
Material 133
File System Interface the file is placed in the first entry or the address of the ith data block is placed in the
ith entry of the index block. So, accessing any data block requires two disk read:
one for the index block and the other for the data block. The address of the disk
block will be read from the index block to directly access the desired data block
NOTES making it suitable for direct access. The file can grow dynamically; there is no need
to declare the size of the file in advance. When all, except for the last entry of the
index block is filled, a new index block will be allocated and this will be linked to
the last entry of the previous index block.
The index block address is entered in the directory entry at the time of creating
the file. Even an empty file must have one block as the index block. For example,
index block 32 contains an array of data block. It indexes files to access the actual
data block that contains data (refer Figure 4.12). The need of an additional block of
storage for the index block is the disadvantage of indexed allocation.
Index block 6 Index block 32
13 20
18 19
2 25
24
F1 34
37
29
Index block 22 F3
10
21
35
9

F2

Fig. 4.12 Indexed Allocation of Blocks

Free Storage Space Management


Storage space has to be maintained and managed properly to improve the
performance of storage space allocation algorithms. As files are created and deleted,
the total storage space will be divided into many free areas known as holes between
allocated areas. So, it is necessary to keep track of the storage areas that are free and
areas that are allocated to files. The operating system maintains a list of holes (free
list of blocks) for this purpose. When a set of free blocks is needed for creating a file
the operating system searches it in the free block list and, if available, it is allocated
to the process that requested it. The OS then updates the free block list. For storage
space and search efficiency of the free list, the following techniques are available to
implement free list:
Bit Vector
In the bit vector implementation of free list, a long string of binary number called
bit vector, whose length is equal to the number of blocks in the storage device, is
used to represent free blocks and allocated blocks. That is, one bit is used to represent
the status (allocated or free) of each disk block. A value 1 is used to indicate allocation
of the block to some file and a 0 is used to indicate free status of the block. As an
example, suppose blocks 3, 6, 7, 10,11,13, 14, 15, 16,17,18, 22, 23, 24, 25, 30,31,32,
40,43,44 are free in a 50 block storage device (block numbers are from 0 to 49). The
bit vector representation for this allocation is declared as follows:
Self-Instructional
134 Material
Bit vector: 1110110011 0010000001 1100001111 0001111111 0110011111 File System Interface

Advantage: If the bit-vector is in the main memory, it is easy and efficient to search
in the bit vector, particularly for finding a set of contiguous free blocks.
Disadvantage: The bit vector should be in the main memory for efficient search. NOTES
Linked List
In this linked list approach, the free blocks are all linked together one after the other
as depicted in Figure 4.13. The head pointer will be pointing to the first free block in
the list. This is particularly suitable for linked and indexed allocation as the free block
may be easily found from the head of the linked list. In the example free list considered
earlier, Block 3 is the first Block, a pointer to Block 6 is placed in Block 3 and then a
pointer to Block 7 is placed in Block 6 and then a pointer to Block 10 and so on. The
technique is not suitable for allocation of contiguous blocks.

Head of list
3 Freed disk blocks
3 6 7 10 44
6 7 10 11

3, 6, 7, 10, 11, ..., 44 are free disk blocks


Fig. 4.13 Linked List of Free Disk Blocks

Grouping
This is an efficient variant of linked list approach. In this scheme as shown in Figure
4.14, the first free block is used to store the addresses of first n–1 free blocks, where
n is the number of addresses that can be placed in a free block. At the nth location,
store the address of another free block that contains the addresses of another n free
blocks, the last one will be again the block for holding the addresses of other free
blocks. In this way, the list can be grown further to accommodate all free block
addresses. The values shown are for the example free list considered earlier. The
advantage is that the allocation of a large number of free locks may be done easily
from the first disk block itself.

Block 3 Block 18 Block 44


6 22
7 23
10 24
11 25
13 30
14 31
15 32
16 40
17 43
18 44

Fig. 4.14 Grouping Free Blocks


Self-Instructional
Material 135
File System Interface Counting
This technique keeps track of all free holes in the storage space. A linked list with
each node containing the starting block number of the hole and size (number of
NOTES contiguous free blocks) of the hole is maintained. Figure 4.15 depicts the
representation of the counting scheme for the example free list. It is easy to search
contiguous blocks in such linked lists.

Head of list

3 1 6 2 10 2 13 6

22 4 30 3 40 1 43 2

Fig. 4.15 Counting

4.4 PROTECTION CONCEPTS


In a multiprogramming environment, the resources like processors, memory
segments, I/O devices, software programs and files data must be shared among
users.
Any amount of protection is considered less. Isolation connotes that entities
operate independently from each other in the physical sense. Share all or nothing
means that an object is either totally private or totally public. The share via access
limitation connotes that different entities have different levels of access to an object
as a gift from the owner. The role of OS is to act as a guard between entities and
objects for enforcing correct access. The function of the share via dynamic
capabilities is to enable the former to allow rights to be varied dynamically.
Limit on the use of an object connotes that (i) access to the object is controlled
and (ii) the manner of its use may change across entities.
In this section we will concentrate on the technical ways used by the various
operating systems to protect resources like files and other things.
Protection is a mechanism that is used to control the access to system resources.
It allows which users are permitted to access what resources.
Check Your Progress The goals of the protection are as follows:
5. What is the  Increase reliability,
meaning of the term  Prevent mischievous, intentional violation of access restriction,
organization?
 Enforce stated policies,
6. What is the use of
the physical  Provide a way to distinguish between authorized and unauthorized usage.
contiguous blocks? Consider a system as a collection of objects each with a unique name.
7. Name one major  Operations of an object depend on the type of object.
task that the file
system must do.
 Each process executes within a protection domain which specifies what
rights the process has to which objects.
Self-Instructional
136 Material
 The ability to invoke a given operation on an object is termed as access File System Interface
right.
 A domain is a collection of pairs, i.e., objects and access rights.
 Policy determines which pairs are assigned to which domains.
 Mechanism is the ability that determines how to do something. Policies NOTES
are decisions that determine what to do.
A car can run 100 miles per hour. It is the ability of the car hence, it is a
mechanism. The speed limit of the car is 55 miles per hour. This is a decision hence
it is a policy.
A policy defines what is to be done, while a mechanism defines how it is to
be done. For example, the timer constructed to ensure protection of the CPU is a
mechanism, while the decision regarding how long the timer is to be set for a
particular user is a matter of policy decision.
Mechanism and policy must be separated so as to provide flexibility to a
system. In case of a well defined interface between mechanism and policy, any
change in policy would affect only a few parameters. If the interface between these
two is complex or ill-defined, it could involve drastic changes in the system.
Once the policy is decided, it would give the programmer the option to use
his/her own implementation. It should be noted here that it is possible to change the
underlying implementation for a more efficient one without any hassle if both the
mechanism and policy are well defined. Specifically, if the policy and mechanism
are separated, it would provide the flexibility in a number of ways. Firstly, the same
mechanism can be used for implementing different policies. Thus, to change a policy,
it is not necessary to develop a new mechanism only a change in the parameters for
that mechanism from a library of mechanisms is required. Secondly, it becomes
possible to change the mechanism so as to increase its efficiency or move it to a
new platform, without making any change in the overall policy.
 Domain of Protection: A system is considered as the collection of processes
and resources. The resources can be considered as objects. Processes request
the objects like the CPU, memory, printer, disks and other hardware resources.
Processes can also request the software objects, for example files, programs,
semaphores and monitors. Each object, whether software or hardware objects,
has a unique name that is used to differentiate it from other objects. Each
object is accessed by well defined operations. Execute operation is possible
on the CPU object, read and write operation on the memory object, create,
open, read, write, close, delete, execute operations are possible on file objects.
Each process is given permission to access only those resource objects, which
it requires to complete its task; this is called as need to know principle. The
process must be authorized to use the requested resource objects.
 Domain Structure: Each process has an associated protection domain which
specifies all resources that are accessed by a process domain that consists of
objects and operation for those objects. A user is given the ability to execute
an operation. This ability is called access right. A domain is a collection of
ordered pair (<object name, access rights>), for example, D is a domain with
< file a, (read, write)>. Here ‘a’ is a file object, which has read/write access
rights. We can define domains that share access rights with one another. The
process and its domain can have static or dynamic association. In static
association, the domains associated for a process is fixed. In dynamic
Self-Instructional
Material 137
File System Interface association, a process can be associated with a domain dynamically, i.e., a
process can switch among multiple domains.

4.5 SECURITY PROBLEM


NOTES
Every system consists of resources like files or data. To protect the resources against
the unauthorized access, we must provide some security measures. Users who try to
access the system resources without proper permissions are called intruders.
Security is of two types—internal and external. If all the users access the
resources they are intended to use, then the system is said to be secure. Total Security
cannot be achieved.
Security violations can be intentional or accidental. Accidental security
violations are easier to protect than the intentional security violations. Malicious
access, another name for intentional security violation, is of several forms, such as
follows:
 Reading of data without proper authorizations.
 Modification of data without proper authorizations.
 Destruction of data without proper authorizations.
To protect the system from unauthorized access to the data, we must take
some security measures. The security measures can be applied at the following four
levels:
 Physical: The site where one or more systems reside must be physically
secured. This is done by providing physical barriers like walls and
screening the users. The site must be free from fire, floods and any such
damages.
 Human: When users are allowed to access the systems they must be
thoroughly screened and their actions must be logged. Systems must be
protected from users who try to breach the security restrictions supported
by the authorized users.
 Network: The Internet (network link) is shared by many systems. When
one system sends data to the other, then it should be protected from
interception from other systems.
 Operating System: The operating system must protect itself from
accidental or intentional security breaches.
The assets that must be secured are hardware, software, data and
communication.
Hardware is primarily vulnerable to interruptions, which may occur either
due to theft or vandalism. For preventing these attacks, physical security measures
are applied.
Only hardware is not vulnerable to interruptions; software is also vulnerable
to interruption, as its deletion is easy. In order to limit the damage due to deletion,
backups are used. Modification or fabrication through alteration, for example by
viruses is a big problem, as its quick detection is difficult. Software is also vulnerable
to interception occurring due to unauthorized copying. This problem is yet to be
resolved.
Data is vulnerable to interruptions in many ways. An interruption may result
due to destruction and unauthorized reading of data files. More detrimentally, it can
Self-Instructional
138 Material
occur through unauthorized analysis and aggregation of data. Modification and File System Interface
fabrication also cause interruptions with very damaging consequences.
Communication is susceptible to all sorts of threats. Threats or attacks are of
two types: passive and active. Passive attacks take the form of eavesdropping and
fall into two categories: reading the contents of a message or more subtly and NOTES
analysing patterns of traffic to infer the nature of even secure messages. It is difficult
to detect a passive attack so prevention is emphasized. Active attacks occur when a
data stream is modified or a false data stream is created. One entity may masquerade
as another (presumably one with more or different privileges) may be by capturing
and replaying an authentication sequence. Replay is a similar attack usually on
data. There may be modifications in the contents of a message often to actuate
incorrect behaviour in other users. Service attacks are denied to restrict the normal
use of communication facilities. Unlike passive attacks, it is difficult to entirely
prevent active attacks; so detection and damage control are emphasized.
The following are the security requirements:
Confidentiality: Maintaining the privacy of data is an important concept in
security. The information maintained by a system is accessible only by the
authorized users or the processes that represent those users. Interception occurs
when an unauthorized user gains access to a resource. Examples include illegal
file copying and the execution of programs.
Integrity: Integrity of a system is maintained if the system’s resources are
modified only by authorized users. Modification of resource occurs when an
unauthorized user not only gains access to a resource but also changes or
modifies a resource such as file or running process.
Availability: The system resources must be accessible only at required times
by authorized users. Interruption occurs when an unauthorized user reduces
the availability of a resource.
Authenticity: The system must verify the identity of a user who is accessing
the resources.
Fabrication occurs when an unauthorized user inserts counterfeit data in
between the valid data.
Malicious software attempts at causing damage to or consuming the resources
of, a target system. It may operate independently. A Trap Door refers to a secret
entry point into a program left by the program developers. A Logic Bomb refers to
a code embedded in a program that explodes when certain conditions are met, for
example a certain date or the presence of certain files or users. Logic Bombs also
often originate with the developers of the software. A Trojan Horse refers to a useful
(or apparently useful) program which contains the hidden code for performing some
unwanted or harmful function. A virus refers to a program that can infect other
programs by modifications as well as causing local damage. Such modifications
include a copy of the virus which can then get transmitted further to other programs.
A worm refers to an independent program that spreads via network connections
typically using either e-mail, remote execution or remote login to deliver or execute
a copy of itself to or on another system as well as causing local damage. A zombie
refers to an independent program that secretly takes over a system and uses that
system for launching attacks on other systems, thereby concealing the original
instigator. Such attacks often involve further replication of the Zombie itself. Zombies
are often used in the Denial of Service (DoS) attacks. The last three of these involve
replication. Self-Instructional
Material 139
File System Interface The two security threats, intruders and viruses are most common for which
we need to provide security measures.
Intruders
NOTES Intruders are of the following three types:
 A masquerader who is an unauthorized person (usually an outsider) who tries
to penetrates a system to exploit legitimate users’ accounts.
 A misfeasor who is a legitimate user (usually an insider) who tries to access
system resources to which he/she is not privileged or who abuses or tries to
abuse such privileges.
 A clandestine is a user (insider or outsider) who seizes control of a system to
evade auditing controls.
Intruders usually try to gain access to a system resource or try to increase
their privileges to which they are not entitled; they do this often by obtaining the
password for a legitimate account. There are many methods for obtaining passwords.
They are as follows:
 Trying with default passwords.
 Extensively testing short passwords.
 Trying words from a dictionary or from a list of common passwords.
 Collecting personal information about users.
 Using a Trojan Horse.
 Eavesdropping on communication lines.
The usual methods for protecting passwords are through one way encryption
or by limiting access to password files. However, passwords are inherently
vulnerable.
4.5.1 User Authentication
A person or information is authenticated on the computer by using various techniques,
such as user name or e-mail ID and password.
Password
User name and password provides authentication. If user logs on the system unit or
application, user name and password will be asked for checking authentication.
Following screen shows the two prime fields, User Name: and Password: are
provided to system administration for checking the authenticity. Once authentication
is verified for users, they can access to the desired system.

Self-Instructional
140 Material
If the two requirements are not matched then users are not allowed to access the File System Interface
system. Smart card authentication is taken as a prime example in the era of online
transaction. A smart card resembles a credit card in size and shape but inside, it is
completely different. The inside of a smart card contains an embedded
microprocessor. The microprocessor is under a gold contact pad on one side of the NOTES
card. Smart cards are much more popular in Europe than in the United States. The
smart cards are based on X.509 Public Key Infrastructure (PKI) and digital signatures
and also contain biometric information as well as printed information and a photo.
X.509 is an International Telecommunication Union (ITU), Telecommunication
Standardization Sector (ITU-T) standard for PKI in cryptography. A X.509 version
3.0 digital certificate has three main variables. These variables are taken as the
certificate, the certificate signature algorithm and the certificate signature. The
certificate is described by attributes, such as version, algorithm ID, serial number,
issuer, subject, validity, subject public key information, extensions and several other
optional ones like subject and issuer unique identifier. The subject public key info
attribute is further detailed by the public key algorithm and subject public key while
validity attribute comes has further options for an upper and lower date limit which
eventually decides the life of the certificate. Such smart cards are designed to meet
a range of appropriate security specifications. An X.509 certificate which is issued
by the card issuing organization contains the user’s public key. This certificate can
be read from the card. The user’s private key is used to digitally sign information
and also be used to decrypt information intended for the user. The private key cannot
be extracted from the card it is private to the user. The smart card provides a
mechanism to securely authenticate the user who holds it.
4.5.2 Program Threats
Often one user writes a program to be used by another user. In this case, misuse of
programs can occur and lead to unexpected behavior. The two most common methods
by which such behavior can occur are known as Trojan Horses and Trap Doors
which are known as viruses. It is believed that program ‘Elk Cloner’ was the first
computer virus created by Rich Skrenta. Computer virus refers an executable code
that is recursively attached to various other computer programs to replicate itself
without the awareness of a system user. These computer viruses can damage the
system of a computer. Virus attempts for self replication in the system unit. It can
spread in files, disks or Internet and recreate automatically as mushroom without
getting permission to new host. New viruses are created by hackers and malicious
programmers. In the Internet era, 87 per cent of viruses are spread across network
in which many PCs are connected. Boot sector virus, multi-partite virus, companion
virus, macro and link virus are considered as types of computer viruses. Every virus
first occupies in the main memory to effect badly on CPU processing time. Viruses
are frequently transmitted through e-mail attachments, peer to peer downloads,
phishing and instant messages. The phishing process leads to a fraudulent process
which access the user’s credentials. An e-mail attachment carries and spread virus
fast in an address book or a random combination of address book. If these viruses
are not controlled quickly then the servers can disrupt the e-mail services for all
systems. Any awkward behavior of computer system cannot be directly related to
computer virus, because OS and programs work differently and not according to
the system. The sign of virus sometimes can be seen as unusual screen displays or
messages. A virus slows the operation of computer. The computer drive is accessed
Self-Instructional
Material 141
File System Interface unexpectedly if virus infected programs reside there. The virus infected files change
the length and size of *.com or *.exe files. The content of file and date or time is
changed from the directory listing if the file is infected with virus. Some viruses
hide the details of a file if they work in Random Access Memory (RAM) memory.
NOTES The location of system resources are also changed in virus infected file. According
to their location, viruses can be of two types known as non-resident virus and resident
virus. The non-resident virus looks for other sources to infect and transfer control to
the host program, whereas the resident virus looks new host if the infected files are
accessed by other programs. Following are considered as prime program threats:
 Trojan Horse: This virus basically attacks on secure and trusted operating
system and make user think about it a beneficial and secure application. It
starts attempt if a user wants to legitimate the system and want to get read or
write permission in a file. If a file is shared by another user a Trojan Horse
program is created that motivates data destruction. This infection is mainly
spread through email attachments and in chatting process via Skype and Yahoo
messenger. Suppose one user sends an attachment as saxophone.wav file to
other user which is infected with Trojan Horse then this file collects sound
samples that are basically virus files and in this way it is spread across network.
It is different from other destructive virus because this virus does not reproduce
the malicious code. It also steals passwords of authorized user and sends
email as authorized user instead it is hacker’s false name. It does not reproduce
the infection due to leaking capacity. It was originated from pro-hacker
website. It requires Windows to work because remote accessing part can infect
the other system unit. Once PC is infected by this program threat the system
unit tries to work with User Datagram Protocol (UDP) port 54321 Back Orifice
2000 and UDP port 57341 NetRaider 0.0 that works as default ports used by
some known Trojan Horses. In Australia, about 72 per cent Internet Service
Provider (ISP) were infected with Back Orifice. The major malfunctions
created by Trojan Horse are starting queries and pings to servers, rebooting
system automatically, displaying system information, logging keystrokes,
editing registry file to control the server, etc. The latest dangerous Trojan
Horse is known as TR/Dldr.FraudLoad.51200 discovered in the year of 2009
representing the download subtyping which is having file size 51.200 bytes.
 Trap Doors: When a programmer leaves a hole in the software only that user
is capable of gaining access to it. Basically, Trap Doors is a unique program
where the programmer might illegally or legally write the code to avoid normal
security procedures for specific user.
There are problems to detect because they are in the source code where
software systems can contain millions of lines of code. For example,
Win32.Kriz.3862 virus in 1999 executed itself on Christmas Day and causes serious
damage by overwriting massive amounts of data on the hard disk and rewriting the
Basic Input Output System (BIOS). In 2000, Deutsche Morgan Grenfell, securities
trader who had initially been hired as a programmer, was charged with inserting
Logic Bombs. Protection is required from trap doors virus thorough commitment to
quality assurance, strict separation of programming duties and strict security policies,
such as user authentication and authorization after deployment. Trap Doors can
provide access to a system for unauthorized procedures, whereas Logic Bombs
execute malicious code at certain time.
Self-Instructional
142 Material
4.5.3 System Threats File System Interface

Most operating systems provide a means for processing to offspring other processes.
With an environment like that, it becomes easy for operating system resources and
user file to be misused. Worms and viruses are the most common methods for NOTES
achieving misuse. Following are considered as prime system threats:
Worms
Worms are also computer viruses that put malfunctions across network. If user
downloads the file which is actually worm into his system, it spreads until other
computers connected with that system unit gets effected. This virus is dangerous
for those businesses set up on large network. To know the working and spreading of
viruses on PC or even on Internet, you must know the lifecycle of computer viruses.
The lifecycle of computer virus is as follows:
 Coding: In this phase, the virus program is coded and developed.
 Releasing: Once the code is ready, it is spread to the system and network.
 Spreading: It is out forwarded through a simple e-mail.
 Quarantining: In this phase, the virus gets quarantined. This phase often
happens when it validates the signature of the virus and develops an antivirus
update.
Virus
System threat especially virus attempts on boot sector to modify the interrupt vectors
and system files. For example, virus activity frequently calls I/O operations if system
unit is infected. A virus is detected by searching the pattern of viruses, for example
running any code by examining the records and files. Viruses spread from machine
to machine and across network in a number of ways. The viruses are always trying
to trigger and execute the malicious programs that intently spread the computer
system. For example, a macro virus is booted with infected disk and spread the
viruses to boot sector. Then, it started to share the network drive or other media that
exchanges infected files across Internet by downloading files and attachments from
Internet. The transmission of viruses is possible by following ways:
 If system unit is booted from infected files.
 If programs are executed with an infected programs.
 If the virus infiltration includes common routes, floppy disks and e-mail
attachments.
 If pirated software and shareware are used in the system files.
Viruses are so malicious and smart even users are not able to realize whether
their system unit is infected with viruses or not. The property of viruses is that they
hide themselves among regular system files or frequently attachments and
camouflage as they are standard files. The following steps are preferably taken if
system gets infected with viruses:
 The golden rule must be followed preventing from data destruction that
helps users to avoid unnecessary stress.
 The Internet facility and Local Area Network (LAN) utilities must be
disconnected for the time being.

Self-Instructional
Material 143
File System Interface  Two operating systems must be installed within system unit if system is
not booted properly. If the system does not recognize the hard drive it
means it is infected with virus. It is better to boot from Windows rescue
disk. The partition table of scandisk must be recovered using scandisk for
NOTES standard Windows program.
 Back up of all important and critical data must be taken as regular interval
in external devices, such as Compact Disk (CD), Universal Serial Bus
(USB), floppy disks or even flash memory, etc.
 Antivirus software must be installed in the system and it is needed to run
after weekend or month end. The good antivirus disinfects infected objects,
quarantine infected objects and able to delete Trojans and worms.
 The latest updates must be taken for removing the antivirus databases.
The infected computer is not included to download the updates.
 Scans and disinfects the mails of client’s databases that ensure the malicious
programs are not reactivated if messages are sent from one to other across
network.
Firewall security features must be installed in the system that prevents from
malicious and foreign programs. The corrupted applications and files must be
cleaned and deleted. User needs to try to reinstall the required applications in the
system and should be sure that the corresponding software is not pirated.

4.6 SUMMARY
 An Operating System (OS) designer or a system programmer is an abstraction
mechanism on storage devices.
 Information may be classified and represented in files on storage devices.
Files may be created and deleted.
Check Your Progress  A secured file system must provide some access control mechanism to protect
8. What do you the files, i.e., file access like read, write and execute by different users must
understand by be controlled by the owner of the files. A directory is also a file used for
protection in an recording the name and attributes of files.
operating system?
9. How is a policy
 The number of characters that can be used for creating names of files varies
different from a from system to system.
mechanism?
 In flat name space, there will not be multiple directories for classifying and
10. What is the role of a
process in a
organizing files. All the names must be different and two files cannot have
dynamic the same name.
association?
 In hierarchical name space, the files are organized in nested directories, i.e.,
11. What are the two
types of security?
there will be a root directory and within the root there will be many
subdirectories and each subdirectory can have again subdirectories within it
12. What does
malicious software to many levels.
do?
 Directories are system files used for providing a classified view of the files
13. Who is a
based on the information content and other attributes like the owner of the
clandestine?
files.
14. How is a virus
detected and how it  Disk storage devices are modelled as a block special file where information
spreads? is accessed as blocks.

Self-Instructional
144 Material
 Regular files are the American Standard Code for Information Interchange File System Interface
(ASCII) text files or binary files. Text files can be displayed or printed and
can be edited with a text editor.
 A logical file system stores metadata information. This includes the file system
structure excluding the actual contents of the file. NOTES
 The file system stores the data under various applications and keeps record in
a systematic and logical manner so that the data can be retrieved, viewed and
opened easily. The records are systematically organized in the file because it
affects system performances.
 The word ‘organization’ refers to the logical and systematic arrangement of
the files in the disk which is based on the specific ordering.
 In piles, information is written to the file as per the order of arrival.
 In sequential files, the records are placed in the order of arrival. Physical
contiguous blocks are used to store the record sorted in the order of entry to
the file. The order cannot be changed or the length of the record cannot be
altered or the record cannot be deleted.
 Direct access or hashed access organization is used to access the record much
faster than indexed sequential or inverted list organization.
 Each file has a set of properties or characteristics called attributes. They are
given values at the time of creation.
 The file system provides suitable interfaces to users for doing common
operations on files, such as Create, Delete, Open, Close, Read, Write, Append,
Seek, Get Attributes, Set Attributes and Rename.
 A file system has a directory structure to organize or keep track of files in the
computer system. A directory contains information about files like location,
ownership and other attributes. The structure of directories may be different
for different file systems. The directory structure can be organized in various
ways like single level, two level, hierarchical or tree structured and acyclic
graph directory structure.
 A file consists of a collection of storage blocks on the secondary storage. A
block may consist of one or more sectors on the storage device.
 Storage space has to be maintained and managed properly to improve the
performance of storage space allocation algorithms. As files are created and
deleted, the total storage space will be divided into many free areas known as
holes between allocated areas.
 The role of OS is to act as a guard between entities and objects for enforcing
correct access. Each process executes within a protection domain which
specifies what rights the process has to which objects.
 A user is given the ability to execute an operation. This ability is called access
right.
 Security is of two types—internal and external. If all the users access the
resources they are intended to use, then the system is said to be secure.
 Threats or attacks are of two types: passive and active. Passive attacks take
the form of eavesdropping and fall into two categories: reading the contents
of a message or more subtly and analysing patterns of traffic to infer the
Self-Instructional
Material 145
File System Interface nature of even secure messages. Active attacks occur when a data stream is
modified or a false data stream is created.
 Malicious software attempts at causing damage to or consuming the resources
of, a target system. It may operate independently.
NOTES
 A virus refers to a program that can infect other programs by modifications
as well as causing local damage. Such modifications include a copy of the
virus which can then get transmitted further to other programs.
 A worm refers to an independent program that spreads via network connections
typically using either e-mail, remote execution or remote login to deliver or
execute a copy of itself to or on another system as well as causing local
damage.
 A person or information is authenticated on the computer by using various
techniques, such as user name or e-mail ID and password.
 Firewall security features must be installed in the system that prevents from
malicious and foreign programs. The corrupted applications and files must
be cleaned and deleted.

4.7 KEY TERMS


 Access right: It is the ability of the user to execute an operation.
 File: It is an abstraction mechanism on storage devices.
 Block special file: It is a file wherein information is accessed as blocks.
 File system: It stores the data under various applications and keeps record in
a systematic and logical manner so that the data can be retrieved, viewed and
opened easily.
 Attributes: These are a set of properties or characteristics of every file.
 Directory: It is a system file used for providing a classified view of the files
based on the information content and other attributes like the owner of the
files.
 Counting: This technique keeps track of all free holes in the storage space.
 Masquerader: It is an unauthorized person who tries to penetrate a system
to exploit legitimate users’ accounts.
 Trojan Horse: It refers to a type of viruses which basically attack on secure
and trusted operating system and make user think about it a beneficial and
secure application.
 Quarantining: It is a phase in which virus gets quarantined when it validates
the signature of the virus and develops an antivirus update.

4.8 ANSWERS TO ‘CHECK YOUR PROGRESS’


1. A directory is a file used for recording the name and attributes of files.
2. File extension indicates the type or class of data stored inside.
3. UNIX denotes root directory by / (front slash) and Windows denotes it by \
(backslash).
Self-Instructional
146 Material
4. A file system facilitates how files are stored so that they can be retrieved File System Interface
easily.
5. The word ‘organization’ refers to the logical and systematic arrangement of
the files in the disk, which is based on the specific ordering.
NOTES
6. Physical contiguous blocks are used to store the record sorted in the order of
entry to the file.
7. Allocating secondary storage space is a major task that a file system must do.
8. Protection is a mechanism that is used to control the access to system resources.
9. A policy defines what is to be done, while a mechanism defines how it is to
be done.
10. In dynamic association, a process can be associated with a domain
dynamically, i.e., a process can switch among multiple domains.
11. The two types of securities are internal and external security.
12. Malicious software attempts at causing damage to or consuming the resources
of a target system.
13. A clandestine is a type of intruders, who basically is a user (insider or outsider)
that seizes control of a system to evade auditing controls.
14. A virus is detected by searching the pattern of viruses, for example running
any code by examining the records and files. Viruses spread from machine to
machine and across network in a number of ways.

4.9 QUESTIONS AND EXERCISES

Short-Answer Qustions
1. Name the various types of files.
2. What are regular files?
3. Mention the major techniques of file organization.
4. What is the use of the acyclic graph?
5. What are the methods of file allocation in a file system?
6. Name the techniques for implementing free list.
7. What are the various goals of protection?
8. Name the various forms of the malicious access.
9. What is an intruder? Mention its types.
10. How is a user or information authenticated?
11. How is a virus detected?
Long-Answer Questions
1. Describe the structure of the file system.
2. Briefly describe any three major techniques of file organization.
3. Explain the functions and features of an indexed sequential file.
4. Describe the various attributes of a file with the help of examples.
Self-Instructional
Material 147
File System Interface 5. Explain the different interfaces to file system.
6. Describe the functions of the tree structured directory with the help of an
example.

NOTES 7. Briefly distinguish between acyclic graph and the tree structure using suitable
diagrams.
8. Describe the functions of the storage blocks in the file system.
9. Explain the technique of counting as a method of implementing free list.
10. Explain security measures that are applied at the four levels of the file system.
11. What are the security requirements of the file system? Explain.
12. Explain the functions, spread and removal of virus from a computer system.

4.10 FURTHER READING


Silberschatz, Abraham, Peter Galvin and Greg Gagne. Operating System Concepts,
John Wiley & Sons, 2004.
Tanenbaum, Andrew S. Modern Operating Systems, Prentice Hall, 2001.
Mano, M. Morris. Computer System Architecture. New Jersey: Prentice Hall Inc.,
1993.
Peterson, J.L., Abraham Silberschatz and Peter B. Galvin. Operating System
Concepts. New York: Addison Wesley, 1994.
Louise I. Shelly 2020 Dark Commerce

4.11 LEARNING OUTCOMES

 Understand the concept of a file


 Know about the implementation as well as structure of the file system
 The organization of the file system
 The various protection concepts of the file system
 The security problems in the file system interface

Self-Instructional
148 Material
Device Management

UNIT 5 DEVICE MANAGEMENT


Structure NOTES
5.0 Introduction
5.1 Unit Objectives
5.2 Input/Output Devices
5.2.1 Input Devices
5.2.2 Output Devices
5.2.3 Storage Devices
5.2.4 Optical Drives
5.3 Dedicated and Shared Devices
5.3.1 Virtual Devices
5.4 Disk Management and Scheduling
5.4.1 Disk Structure
5.4.2 Disk Scheduling
5.5 SPOOLing
5.6 I/O Systems and Device Drivers
5.7 Summary
5.8 Key Terms
5.9 Answers to ‘Check Your Progress’
5.10 Questions and Exercises
5.11 Further Reading
5.12 Learning Outcomes

5.0 INTRODUCTION
In this unit, you will study about device management. Computers have an input/
output subsystem which provides an efficient mode of communication between the
central system and the outside world. The I/O devices refers to input devices, such
as keyboard, point and draw devices, such as mouse, touch pads, light pens, trackball,
joystick, etc., and various types of output devices, such as multimedia projectors,
printers, etc., which collectively provide a means of communication between the
computer and the outside world are known as peripheral devices. This is because
they surround the CPU and the memory of a computer system. You will also study
about various external as well as internal I/O devices, such as keyboard, mouse,
scanner, printer, monitor, universal serial bus, projectors, etc. A multimedia projector
is an output device which is used to project information from the computer onto a
large screen so that it can be viewed by a large group of people.
You will also learn about the dedicated and shared devices as well as virtual
device, such as Android Virtual Device which use virtual memory with communicate
with each other. You will be introduced to various disk scheduling algorithms, such
as first come first serve, shortest seek time first, SCAN Scheduling, Circular SCAN
scheduling, LOOK scheduling which decides the concept of disk management and
scheduling define disk structure and disk scheduling. The unification of files and
devices are arranged in I/O system. In this mechanism, the device driver works as
the file interface that keeps the coding to translate to the device driver interface.
You will also learn about SPOOLing as well as systems and device drivers.
SPOOLing is a way of processing data serially. Print jobs are spooled to the printer
because they must be printed in the right order. During a SPOOLing operation only
one job is performed at a time and other jobs wait in a queue to be processed.
Self-Instructional
Material 149
Device Management
5.1 UNIT OBJECTIVES
After going through this unit, you will be able to:
NOTES  Understand the various I/O devices
 Describe the functioning of dedicated and shared devices
 Discuss about disk management as well as scheduling
 Know the application of virtual devices
 Explain SPOOLing and the various device drivers

5.2 INPUT/OUTPUT DEVICES


The computer system is a dumb and a useless machine if it is not capable of
communicating with the outside world. It is very important for a computer system
to have the ability to communicate with the outside world, i.e., receive and send
data and information.
Computers have an Input/Output (I/O) subsystem referred to as I/O subsystem
which provides an efficient mode of communication between the central system
and the outside world. Programs and data must be entered into the computer memory
for processing, and results obtained from computations must be displayed or recorded
for the user’s benefit. This can be explained with a very common scenario where
the average marks of a student need to be calculated based on the marks obtained in
various subjects. The marks would typically be available in the form of a document
containing the student’s name, roll number and marks scored in each subject. This
data must first be stored in the computer’s memory after converting it into machine
readable form. The data will then be processed (average marks calculated) and sent
from the memory to the output unit which will present the data in a form that can be
read by users.
The I/O devices that provide a means of communication between the computer
and the outside world are known as peripheral devices. This is because they surround
the CPU and the memory of a computer system. While input devices are used to
enter data from the outside world into the primary storage, output devices are used
to provide the processed results from primary storage to users.
5.2.1 Input Devices
Input devices are used to transfer user data and instructions to the computer. The most
commonly used input devices can be classified into the following five categories:
 Keyboard devices (general and special purpose, key to tape, key to disk, key
to diskette).
 Point and draw devices (touch screen, touch pads, light pen, trackball,
joystick).
 Scanning devices (mouse, optical mark recognition, magnetic ink character
recognition, optical bar code reader, digitizer, electronic card reader).
 Voice recognition devices.
 Vision input devices (webcam, video camera).
Self-Instructional
150 Material
Keyboard Devices Device Management

Keyboard devices allow input into the computer system by pressing a set of keys
mounted on a board, connected to the computer system. Keyboard devices are
typically classified as general purpose keyboards and special purpose keyboards. NOTES
General Purpose Keyboard
The most familiar means of entering information into a computer is through a
typewriter like keyboard that allows a person to enter alphanumeric information
directly.
The most popular keyboard used today is the 101 key with a traditional
QWERTY layout, with an alphanumeric keypad, 12 function keys, a variety of special
function keys, numeric keypad, and dedicated cursor control keys. It is so called because
the arrangement of its alphanumeric keys in the upper left row (refer Figure 5.1).
 Alphanumeric Keypad: This contains keys for the English alphabets, 0
to 9 numbers, special characters like * + – / [ ], etc.
Function Keys Numeric Keypad

Shift Key Space Bar Enter Key


QWERTY Keyboard Cursor Movement Keys

Fig. 5.1 QWERTY Keyboard Layout

 12 Function Keys: These are keys labelled F1, F2 ... F12 and are a set of user
programmable function keys. The actual function assigned to a function key
differs from one software package to another. These keys are also called soft
keys since their functionality can be defined by the software.
 Special Function Keys: Special functions are assigned to each of these keys.
The enter key, for example is used to send the keyed in data into the memory.
Other special keys include:
 Shift (used to enter capital letters or special characters defined above the
number keys).
 Spacebar (used to enter a space at the cursor location).
 Ctrl (used in conjunction with other keys to provide added functionality
on the keyboard).
 Alt (like CTRL, used to expand the functionality of the keyboard).
 Tab (used to move the cursor to the next tab position defined).
 Backspace (used to move the cursor a position to the left and also delete
the character in that position).
 Caps Lock (to toggle between the capital letter lock feature – when ‘on’,
it locks the keypad for capital letters input).
 Num Lock (to toggle the number lock feature – when ‘on’, it inputs numbers
when you press the numbers on the numeric keypad).
 Insert (used to toggle between the insert and overwrite mode during data
entry when ‘on’, entered text is inserted at the cursor location).
Self-Instructional
Material 151
Device Management  Delete (used to delete the character at the cursor location).
 Home (used to move the cursor to the beginning of the work area which
could be the line, screen or document depending on the software being
used).
NOTES  End (used to move the cursor to the end of the work area).
 Page Up (used to display the previous page of the document being currently
viewed on screen).
 Page Down (used to view the next page of the document being currently
viewed on screen).
 Escape (usually used to negate the current command).
 Print Screen (used to print what is being currently displayed on the screen).
 Numeric Keypad: This consists of keys with numbers (0 to 9) and
mathematical operators (+ – * /) defined on them. It is usually located on the
right side of the keyboard and supports quick entry of numerical data.
 Cursor Control Keys: They are defined by the arrow keys used to move the
cursor in the direction indicated by the arrow (top, down, left, right).
Another popular key arrangement, called Dvorak system, was designed for
easy learning and use. It was designed with the most common consonants in one
part and all the vowels on the other part of the middle row of the keyboard. This key
arrangement made the users use alternate keystrokes back and forth between both
the hands. This keyboard was never been commonly used.
Special Purpose Keyboard
These are standalone data entry systems used for computers deployed for specific
applications. These typically have special purpose keyboards to enable faster data
entry. A very typical example of such keyboards can be seen at the Automatic Teller
Machines (ATMs) where the keyboard is required for limited functionality (support
for some financial transactions) by the customers. Point Of Sale (POS) terminals at
fast food joints and Air/Railway reservation counters are some other examples of
special purpose keyboards. These keyboards are specifically designed for special
types of applications only.
Key to Tape, Key to Disk, Key to Diskette
These are individual standalone workstations used for data entry only. These
processor-based workstations normally have a keyboard and a small monitor. The
function of the processor is to check the accuracy of the data when it is being entered.
The screen displays data as it is being entered. These facilities are very useful
and desirable during mass data entry and are therefore becoming very popular in
data processing centres.
Point and Draw Devices
The keyboard facilitates input of data in text form only. While working with display-
based packages, we usually point to a display area and select an option from the
screen [fundamentals of Graphical User Interface (GUI) applications]. For such
cases, the sheer user friendliness of input devices that can rapidly point to a particular
option displayed on screen and support its selection resulted in the advent of various
point and draw devices.
Self-Instructional
152 Material
Mouse Device Management

A mouse is a small input device used to move the cursor on a computer screen to give
instructions to the computer and to run programs and applications (refer Figure 5.2).
It can be used to select menu commands, move icons, size windows, start programs, NOTES
close windows, etc. Initially, the mouse was a widely used input device for the Apple
computer and was a regular device of the Apple Macintosh. Nowadays, the mouse is
the most important device in the functioning of a GUI of almost all computer systems.

Fig. 5.2 Mouse

You can click a mouse button, i.e., press and release the left mouse button to
select an item. You can right click, i.e., press and release the right mouse button to
display a list of commands. You can double click, i.e., quickly press the left mouse
button twice without any time gap between the press of the buttons to open a program
or a document. You can also drag and drop, i.e., place the cursor over an item on the
screen and than press and hold down the left mouse button. Holding down the
button, move the cursor to where you want to place the item and then release the
button.
Touch Screen
A touch screen is probably one of the simplest and most intuitive of all input devices
(refer Figure 5.3). It uses optical sensors in or near the computer screen that can
detect the touch of a finger on the screen. Once the user touches a particular screen
position sensors communicate the position to the computer. This is then interpreted
by the computer to understand the user’s choice for input. The most common usage
of touch screens is in information kiosks where users can receive information at the
touch of a screen. These devices are becoming increasingly popular today.

Fig. 5.3 Touch Screen

Touch Pads
A touch pad is a touch sensitive input device which takes user input to control the
onscreen pointer and perform other functions similar to that of a mouse (refer Figure 5.4).
Instead of having an external peripheral device, such as a mouse, the touch pad
enables the user to interact with the device through the use of a single or multiple
fingers being dragged across relative positions on a sensitive pad. They are mostly
found in notebooks and laptops where convenience, portability and space are the
prime design concerns. Touch pads are pressure and touch sensitive. They use finger
Self-Instructional
Material 153
Device Management drag and tapping combinations to perform multiple control operations. A user, for
example, can also perform the scroll function of a mouse by sliding a finger in
between certain points usually the extreme top and bottom corners on the right side
of the pad. Their user interface is much more convenient to use and puts less strain
NOTES on wrist and hand which is the most common side effect of using computers with
mouse over a long period of time. The functionality of a touch pad is not limited by
the manufacturer’s user interface. They can be user programmed to recognize a
combination of finger and tap moments to perform new actions as an input device.
Touch pads have shown steady growth in market demand and user acceptability
over all phases of their development cycles. Their growth is further expected to
continue in the same way as the demand for touch sensitive portable devices with
more functionality and better appearance is on the rise.

Fig. 5.4 Touch Pad

Light Pen
The light pen is a small input device used to select and display objects on a screen.
It functions with a light sensor and has a lens on the tip of a pen shaped device. The
light receptor is activated by pointing the light pen towards the display screen and it
then locates the position of the pen with the help of a scanning beam application to
directly draw on screen (refer Figure 5.5).

Fig. 5.5 Light Pen

Trackball
The trackball is a pointing device that is much like an inverted mouse. It consists of
a ball inset in a small external box or adjacent to and in the same unit as the keyboard
of some portable computers (refer Figure 5.6).

Fig. 5.6 Trackball

It is more convenient and requires much less space than the mouse since here
the whole device is not moved (as in the case of a mouse). Trackball comes in
various shapes but supports the same functionality. Typical shapes used are a ball, a
square and a button (typically seen in laptops).
Self-Instructional
154 Material
Joystick Device Management

The joystick is a vertical stick that moves the graphic cursor in the direction the
stick is moved. It consists of a spherical ball which moves within a socket and has
a stick mounted on it. The user moves the ball with the help of the stick that can be NOTES
moved left or right, forward or backward, to move and position the cursor in the
desired location (refer Figure 5.7). Joysticks typically have a button on top that is
used to select the option pointed by the cursor.

Fig. 5.7 A Joystick

Video games, training simulators and control panels of robots are some
common uses of a joystick.
Scanning Devices
Scanning devices are input devices used for direct data entry from the source
document into the computer system. With the help of the scanner you can capture
your images and documents and convert it into digital formats for easy storage on
your computer. The scanner comprises of two major components, the first component
lights up the page in order to capture the optical image and the second component
converts that captured image into a digital format for viewing and storing it on your
computer system.

Fig. 5.8 Hand Held Scanner

There are two types of scanners, contact and laser. Both illuminate the image
first to calculate the reflected light and determine the value of the captured image.
Hand held contact scanners make contact as they are brushed over the printed matter
to be read (refer Figure 5.8). Laser based scanners are more versatile and can read
data passed near the scanning area.

Fig. 5.9 Flat Bed Scanner


Self-Instructional
Material 155
Device Management Hand held scanners are used where the information to be scanned or the
volume of documents to be scanned is very low. They are much cheaper as compared
to the flat bed scanner (refer Figure 5.9). Capturing information using scanners
reduces the possibility of human error typically seen during large data entry. The
NOTES reduction in human intervention improves the accuracy of data and provides for
timeliness of the information processed.
Source data automation is the recent development for data input technologies.
Source data automation does not require any manual data entry rather it captures
the data as a derivative of the routine business activity.
Optical Mark Recognition
The Optical Mark Recognition (OMR) devices can scan marks from a computer
readable paper. Such devices are used by universities and institutes to mark test
sheets where the candidate selects and marks the correct answer from multiple
choices given on a special sheet of paper (refer Figure 5.10). These marksheets are
not required to be evaluated manually as they are fed in the OMR and the data is
then transferred to the computer system for further evaluation.

Answer Sheet
1. a b c d

2. a b c d

3. a b c d

4. a b c d

Page 1 of 4

Fig. 5.10 Sheet Read by an OMR Device

The actual technique used by an OMR device once again involves focussing
a light on the page being scanned thereby detecting the reflected light pattern for
the marks. Pencil marks made by the user reflect the light determining which
responses are marked.
Magnetic Ink Character Recognition
An Magnetic Ink Character Recognition (MICR) device is like an optical mark
recognition device and is used only in the banking industry (refer Figure 5.11).
MICR devices scan cheque numbers directly from the cheque leaflets and then
automatically feed them in the computer systems for further use doing the job quickly,
accurately and efficiently.

Magnetic Ink Characters

Fig. 5.11 A Bank Cheque using MICR Technology


Self-Instructional
156 Material
Banks using MICR technology print cheque books on special types of paper. Device Management
The necessary details of the bank (like the bank’s identification code, relevant account
number and cheque number) are pre-printed on the cheques using an ink that contains
iron oxide particles that can be magnetized.
MICR readers are used to read and sort cheques and deposits. An MICR NOTES
reader sorter reads the data on the cheques and sorts the cheques for distribution to
other banks and customers or for further processing.
Optical Bar Code Reader
Data coded in the form of small vertical lines forms the basis of bar coding.
Alphanumeric data is represented using adjacent vertical lines called bar codes.
These are of varying widths and the spacing between them are used to uniquely
identify books, merchandise in stores, postal packages, etc. Figure 5.12(a) shows a
bar code used on a book for its unique identification.

Fig. 5.12(a) Bar Code Example Fig. 5.12(b) Bar 2code Reader

An bar code reader uses laser beam technology. The laser beam is moved
across the pattern of bars in a bar code. These bars reflect the beam in different
ways. The reflected beam is then sensed by a light sensitive detector which then
converts the light patterns into electrical pulses, thereby transmitting them to logic
circuits for further conversion to alphanumeric value (refer Figure 5.12(b)). Bar
code devices are available as hand-held devices.
Digitizer
Digitizers are used to convert drawings or pictures and maps into a digital format
for storage into the computer. A digitizer consists of a digitizing or graphics tablet
which is a pressure sensitive tablet, and a pen with the same X and Y coordinates as
on the screen. Some digitizing tablets also use a crosshair device instead of a pen.
The movement of the pen or crosshair is reproduced simultaneously on the display
screen (refer Figure 5.13). When the pen is moved on the tablet, the cursor on the
computer screen moves simultaneously to the corresponding position on the screen
(X and Y coordinates). This allows the user to draw sketches directly or input existing
sketched drawings easily. Digitizers are commonly used by architects and engineers
as a tool for Computer Aided Designing (CAD).

Fig. 5.13 Digitizing Tablet


Self-Instructional
Material 157
Device Management Electronic Card Reader
Card readers are devices that also allow direct data input into a computer system.
The electronic card reader is connected to a computer system and reads the data
encoded on an electronic card and transfers it to the computer system for further
NOTES processing. Electronic cards are plastic cards with data encoded on them and meant
for a specific application (refer Figure 5.14). Typical examples of electronic cards
are the plastic cards issued by banks to their customers for use in ATMs. Electronic
cards are also used by many organizations for controlling access of various types of
employees to physically secured areas.

Fig. 5.14 Access Card Security System

Depending on the manner in which the data is encoded, electronic cards may
be either magnetic strip cards or smart cards. Magnetic strip cards have a magnetic
strip on the back of the card. Data stored on magnetic strips cannot be read with the
naked eye, a useful way to maintain confidential data. Smart cards, going a stage
further, have a built-in microprocessor chip where data can be permanently stored.
They also possess some processing capability making them suitable for a variety of
applications. To gain access, for example, an employee inserts a card or badge in
the reader. This device reads and checks the authorization code before permitting
the individual to enter a secured area. Since smart cards can hold more information
as compared to magnetic strip cards, they are gaining popularity.
Voice Recognition Devices
One of the most exciting areas of research involves the recognizing of an individual
human voice as the basis of input to the computer system. Eliminating the keying in
of data, basic commands can very easily be given, facilitating quick operation. Voice
recognition devices consist of a microphone attached to the computer system. A
user speaks into the microphone to input data. The spoken words are then converted
into electrical signals (this is in the analog form). A digital to analog converter then
converts the analog form to digital form (0s and 1s) that can be interpreted by the
computer. The digitized version is then matched with the existing pre-created
dictionary to perform the necessary action. Voice recognition devices have limited
usage today because they have several problems. Not only do they require the ability
to recognize who is speaking but also what is being said (the message). This difficulty
arises primarily because people speak with different accents and different tones and
pitches. The computer requires a large vocabulary to be able to interpret what is
being said. Today’s voice recognition systems are therefore successful in a limited
domain. They are limited to accepting words and tasks within a limited scope of
operation and can handle only small quantities of data.
Most speech recognition systems are speaker dependent, i.e., they respond to
the unique speech of a particular individual, a feature not necessarily inconvenient
but limiting generalized applications. It therefore requires creating a database of
words for each person using the system.
Self-Instructional
158 Material
Vision Input Devices Device Management

Vision input devices allow data input in the form of images. It usually consists of a
digital camera which focuses on the object whose picture is to be taken. The camera
creates the image of the object in digital format which can then be stored within the NOTES
computer.
As the speech recognition system digitizes the voice input, this system similarly
compares the digitized images to be interpreted to the pre-recorded digitized images
of the database of your computer system. Once it finds the right match it sends it for
further processing or pre-defined action.
Video input or capture is the recording and storing of full motion video
recordings on your computer system’s storage device. High end video accelerator
and capture cards are required to capture and view good quality video recordings
on your computer. File compression of the recorded video file is very important for
file storage, since the video files captured are of high quality and may take up one
gigabyte of disk space. The most popular standard used for compression is the Motion
Pictures Expert Group (MPEG). Webcams and video cameras are most commonly
used to input visual data.
Web Camera
A web camera is a video capturing device attached to the computer system, mostly
using a USB port used for video conferencing, video security, as a control input
device and also in gaming (refer Figure 5.15).

Fig. 5.15 A Web Camera

5.2.2 Output Devices


An output device is an electromechanical device that accepts data from the computer
and translates it into a form that can be understood by the outside world. The
processed data, stored in the memory of the computer, is sent to an output unit
which then transforms the internal representation of data into a form that can be
read by the users.
Normally, the output is produced on a display unit like a computer monitor or
can be printed through a printer on paper. At times speech outputs and mechanical
outputs are also used for some specific applications.
Output produced on display units or speech output that cannot be touched is
referred to as softcopy output while output produced on paper or material that can
be touched is known as hardcopy output. A wide range of output devices are available
today and can be broadly classified into the following four types:
 Display devices (monitors, multimedia projectors)
 Speakers
 Printers (dot matrix, inkjet, laser)
 Plotters (flatbed, drum)
Self-Instructional
Material 159
Device Management Display Devices
It is almost impossible to even think of using a computer system without a display
device. A display device is the most essential peripheral of a computer system.
NOTES Initially, alphanumeric display terminals were used that formed a 7×5 or 9×7 array
of dots to display text characters only. As a result of the increasing demand and use
of graphics and GUIs, graphic display units were introduced. These graphic display
units are based on series of dots known as pixels used to display images. Every
single dot displayed on the screen can be addressed uniquely and directly.
Display Screen Technologies
Owing to the fact that each dot can be addressed as a separate unit, it provides
greater flexibility for drawing pictures. Display screen technology may be of the
following categories:
Cathode Ray Tube: The CRT consist of an electron gun with an electron
beam controlled with electromagnetic fields and a phosphate coated glass display
screen structured into a grid of small dots known as pixels. The image is created
with the electron beam produced by the electron gun which is thrown on the phosphor
coat displayed by the electromagnetic field.
Liquid Crystal Display: Liquid Crystal Display (LCD) was first introduced
in the 1970s in digital clocks and watches, and is now widely being used in computer
display units. The Cathode Ray Tube (CRT) was replaced with the LCD making it
slimmer and more compact. But, the image quality and the image colour capability
got comparatively poorer.
The main advantage of LCD is its low energy consumption. It finds its most
common usage in portable devices where size and energy consumption are of main
importance.
Projection Display: Projection display technology is characterized by
replacing the personal size screen with large screens upon which the images are
projected. It is attached to the computer system and the magnified display of the
computer system is projected on a large screen.
Monitors: Monitors use a CRT to display information (refer Figure 5.16). It
resembles a television screen and is similar to it in other respects.

Fig. 5.16 CRT Monitor

The monitor is typically associated with a keyboard for manual input of


characters. The screen displays information as it is keyed in enabling a visual check
of the input before it is transferred to the computer. It is also used to display the
output from the computer and hence serves as both an input and an output device.
This is the most commonly used (I/O) device today and is also known as a
soft copy terminal. A printing device is usually required to provide a hard copy of
the output.
Self-Instructional
160 Material
Multimedia Projectors Device Management

A multimedia projector is an output device which is used to project information


from the computer onto a large screen so that it can be viewed by a large group of
people. Prior to this, the standard mode of making presentations was to make NOTES
transparencies and project them using an overhead projector. This was a tedious
and time consuming activity since for every change in the subject matter a new
transparency had to be prepared. And of course, since electronic cut, copy and paste
was not possible this, meant additional work.
A multimedia projector can directly be plugged into a computer system and
the information projected on a large screen thereby making it possible to present
information to a large audience. The presenter can also use a pointer to emphasize
specific areas of interest in the presentation.
LCD flat screens connected to the computer systems for projecting the LCD
image using an overhead multimedia projector are widely used today.
Owing to its convenience and applicability, multimedia projectors are
increasingly becoming popular in seminars, presentations and classrooms.
Speakers
Used to produce music or speech from programs, a speaker port (a port is a connector
in your computer wherein you can connect an external device) allows connection of
a speaker to a computer (refer Figure 5.17). Speakers can be built into the computer
or can be attached separately.

Fig. 5.17 A Speaker

Printers
Printers are used for creating paper output. There is a huge range of commercially
available printers today (estimated to be 1500 different types). These printers can
be classified into the following three categories based on:
Printing Technology
Printers can be classified as impact or non-impact printers, based on the technology
they use for producing output. Impact printers work on the mechanism similar to a
manual typewriter where the printer head strikes on the paper and leaves the
impression through an inked ribbon. Dot matrix printers and character printers fall
under this category. Non-impact printers use chemicals, inks, toners, heat or electric
signals to print on the paper and they do not physically touch the paper while printing.
Self-Instructional
Material 161
Device Management Printing Speed
This refers to the number of characters printed in a unit of time. Based on speed,
these may be classified as character printer (prints one character at a time), line
NOTES printers (prints one line at a time), and page printers (print the entire page at a time).
Printer speeds are therefore measured in terms of characters per second (cps) for a
character printer, lines per minute (lpm) for a line printer, and pages per minute
(ppm) for a page printer.
Printing Quality
It is determined by the resolution of printing and is characterized by the number of
dots that can be printed per linear inch, horizontally or vertically. It is measured in
terms of dots per inch or dpi. Printers can be classified as near letter quality or
NLQ, letter quality or LQ, near typeset quality or NTQ and typeset quality or TQ,
based on their printing quality. NLQ printers have resolutions of about 300 dpi, LQ
of about 600 dpi, NTQ of about 1200 dpi and TQ of about 2000 dpi. NLQ and LQ
printers are used for ordinary printing in day to day activities while NTQ and TQ
printers are used to produce top quality printing typically required in the publishing
industry.
Types of Printers
Dot Matrix: Dot matrix printers are the most widely used impact printers in personal
computing. These printers use a print head consisting of a series of small metal pins
that strike on a paper through an inked ribbon leaving an impression on the paper
through the ink transferred [refer Figure 18(a)]. Characters thus produced are in a
matrix format. The shape of each character, i.e., the dot pattern, is obtained from
information held electronically [refer Figure 5.18(b)].

Fig. 5.18(a) Dot Matrix Printer Fig. 5.18(b) Characters formed using Dots

The speed, versatility and ruggedness, combined with low cost, tend to make
such printers particularly attractive in the personal computer market. Typical printing
speeds in case of dot matrix printers range between 40–1000 characters per second
(cps). In spite of all theses features in dot matrix printer technology, the low print
quality gives it a major disadvantage.
Inkjet: Inkjet printers are based on the use of a series of nozzles for propelling
droplets of printing ink directly on almost any size of paper. They, therefore, fall
under the category of non-impact printers. The print head of an inkjet printer consists
of a number of tiny nozzles that can be selectively heated up in a few microseconds
by an Integrated Circuit (IC) register (refer Figure 5.19). When this happens, the
ink near it vaporizes and is ejected through the nozzle to make a dot on the paper
placed in front of the print head. The character is printed by selectively heating the
appropriate set of nozzles as the print head moves horizontally.
Self-Instructional
162 Material
Device Management

NOTES

Fig. 5.19 Inkjet Printer

Laser: Laser printers work on the same printing technology as photocopiers using
static electricity and heat to print with a high quality powder substance known as
toner (refer Figure 5.20).

Fig. 5.20 Laser Printer

Laser printers are capable of converting computer output into print, page by
page. Since characters are formed by very tiny ink particles they can produce very
high quality images (text and graphics). They generally offer a wide variety of
character fonts, and are silent and fast in use. Laser printers are faster in printing
speed than other printers. Laser printers can print from 10 pages to 100 pages per
minute, depending upon the model. Laser is high quality, high speed, high volume
and non-impact technology that works on almost any kind of paper. Even though
this technology is more expensive than inkjet printers it is preferred because of its
unmatched features, such as high quality, high-speed printing and noiseless and
easy to use operations.
Plotters
Plotters are used to make line illustrations on paper. They are capable of producing
charts, drawings, graphics, maps and so on. A plotter is much like a printer but is
designed to print graphs instead of alphanumeric characters. Based on the technology
used, there are mainly two type of plotters: pen plotters or electrostatic plotters. Pen
plotters, also known as flatbed plotters, draw images with multicolored pens attached
to a mechanical arm. Electrostatic plotters, also known as drum plotters, work on
the same technology as laser printers.
Flatbed plotters and drum are the most commonly used plotters.
Flatbed Plotters
Flatbed plotters have a flat base like a drawing board on which the paper is laid [as
shown in Figure 5.21(a)]. One or more arms, each of them carrying an ink pen,
moves across the paper to draw. The arm movement is controlled by a microprocessor
(chip). The arm can move in two directions, one parallel to the plotter and the other
perpendicular to it (called the x and y directions). With this kind of movement, it
can move very precisely to any point on the paper placed below.
Self-Instructional
Material 163
Device Management The computer sends the commands to the plotter which are translated into x
and y movements. The arm moves in very small steps to produce continuous and
smooth graphics.
The size of the plot in a flatbed plotter is limited only by the size of the
NOTES plotter’s bed.
The advantage of flatbed plotters is that the user can easily control the graphics.
He can manually pick up the arm anytime during the production of graphics and
place it on any position on the paper to alter the position of graphics to his choice.
The disadvantage here is that flatbed plotters occupy a large amount of space.
Drum Plotters
Drum plotters move the paper with the help of a drum revolver during printing
[refer Figure 5.21(b)]. The arm carrying a pen moves only in one direction,
perpendicular to the direction of the motion of the paper. It means that while printing,
the plotter pens print on one axis of the paper and the cylindrical drum moves the
paper on the other axis. With this printing technology, the plotter has an advantage
to print on unlimited length of paper but on a limited width. Drum plotters are
compact and lightweight compared to flatbed plotters. This is one of the advantages
of such plotters.
The disadvantage of drum plotters, however, is that the user cannot freely
control the graphics when they are being created. Plotters are more expensive when
compared to printers. Typical application areas for plotters include Computer Aided
Engineering (CAE) applications, such as Computer Aided Design (CAD), Computer
Aided Manufacturing (CAM) and architectural drawing and map drawing.

Fig. 5.21(a) Top View of a Flatbed Plotter Fig. 5.21(b) Drum Plotter

5.2.3 Storage Devices


A disk drive is a peripheral device used to store and collect information. It can be
removable or fixed, high capacity or low capacity, fast or slow speed and magnetic
or optical.
Structurally, a drive is the object inside which a disk is either permanently or
temporarily stored. While a disk contains the media on which the data is stored, a
drive contains the machinery and circuitry required for implementing read/write
operations on the disk.
The disk looks literally like a flat circular plate. The computer writes
information to the disk, where it is stored in the same form as it is stored on a
cassette tape. Disks as such are just magnetically coated rolls or circular disks which
Self-Instructional
164 Material
are divided into sectors and tracks. The data is accordingly stored and numbered Device Management
with respect to the track and sector number on the disk; only the structure of the
medium is different. Examples of removable disk drives are Digital Versatile/Video
Disc (DVD), Compact Disk Read Only Memory (CD ROM), floppy disk drive, etc.
A hard disk is an example of a non-removable disk drive. NOTES
The method of accessing data could be sequential (magnetic tape drives) or
random, such as Hard Disk Drive (HDD), DVD where the read/write head can
directly go to any location on the disk.
Drives can be classified into two major groups—magnetic and optical. Here
is a brief overview of various types of magnetic and optical drive.
Magnetic Drives
These are magnetized storage media on which digital or analog information is
recorded as electromagnetic signals over tracks and sectors predesigned on the media.
They are a non-volatile source for storing data because they can store information
for a long time and do not require electricity or any other element to retain the
information stored in them.
Hard Disk Drive
This is a crucial hardware component of a personal computer, without which modern
day computers cannot function. Although the RAM is a place of primary storage, it
is ephemeral, i.e., its life is dependant on the power source RAM is active only as
long as the computer is turned on. A hard disk drive, though technically a secondary
form of storage, is the primary form of permanent storage since the data stored on
the hard disk is not dependant on the computer being switched on or off. The features
of HDDs that have made them an irreplaceable component in our computers are
their high capacity for storing data and the high speeds at which they can access it
at relatively lower cost. They come in various interfaces and specifications, such as
Integrated Device Electronics (IDE), Enhanced IDE (EIDE), Small Computer
System Interface (SCSI), (SATA) and SATA II.
Floppy Disks
These are portable media consisting of a magnetically coated disk kept inside a
protective covering. They are low capacity and cheap to manufacture but highly
prone to dust and scratching. Due to these limitations, they are no longer considered
a standard component of a personal computer system. Their size varies from 360K
to 2.88MB.
Zip Drives
These are similar to disk drives but with thicker magnetic disks and a larger number
of heads in the drive to read/write. The zip drive was introduced mainly to overcome
the limitations of the floppy drive and replace it with a higher capacity and faster
medium. They are better than floppy disks but still slow in performance and with a
high cost to storage ratio. The disk size ranges from 100MB to 750MB. Zip drives
were popular for several years until the introduction of CD ROMs and CD writers,
which have now come to be widely accepted due to their cost, convenience and
speed.
Tape Drives and Tape Drums
Tape drives represented the sequential access method of storage and retrieval.
Sequential access, as opposed to the now prevalent random access, means that data
Self-Instructional
Material 165
Device Management can be stored and retrieved only in a sequential manner as defined by the order in
which the data was stored on the tape drive. For instance, in case of cassette tape
drives (used in tape recorders and players) which are an example of sequential
access based storage if you want to play song number 4 you can do so only after you
NOTES have either played or fast forwarded song numbers 1 to 3 (there is no way to directly
go to song number 4 without going through songs 1 to 3). Tape drives were widely
used in the 1980s and 1990s as backup devices but due to their slow speed and
sequential read/write access and they have now become virtually obsolete.

5.2.4 Optical Drives


An optical drive is a type of storage medium that stores the content in digital form
which is written and read by a low intensity laser. The laser reads data from the
reflective surface of an optical disc by measuring surface changes in height and
depth. All types of optical media are divided into tracks and sectors that contain a
series of tiny indentations in which data is stored.
CD ROM
This is an optical medium of data storage. The current maximum capacity of a
Compact Disk Read Only Memory (CD ROM) is 900Mb (Megabits) with a
maximum read/write access speed of 52X, which means 10,350 rotations per minute
(rpm) and transfer rate of 7.62 Mbps (megabits per second). The data is written
with the help of a red infrared laser beam from an optical lens and the same laser of
lower intensity is used to read data from the CD ROM.
HD DVD
A high density, mostly single sided, double layered optical disc which can hold up
to 15Gb (Gigabyte) on a single layer and 30Gb on a dual layer disc. The read/write
speed on an HD DVD varies between 36 Mbps and 72 Mbps. These were primarily
designed for the storage of high definition videos and large volumes of data. The
basic look and feel of an HD DVD drive and disk is the same as that of a CD ROM
and DVD except that it uses a laser of different wavelength and the microscopic
structure of storage on a disk is different.
Blu Ray
Another high density optical storage media format is gaining popularity these days.
It is mainly used for high definition video and storing data. The storage capacity of
a dual layer Blu ray Disc is 50 GB, almost equal to storing data in six double dual
layer DVD or more than 10 single layer DVD.
Check Your Progress
1. Why are input 5.3 DEDICATED AND SHARED DEVICES
device used?
2. How are keyboard The device allocation mechanism follows either on dedicated or shared devices.
devices classified?
Virtual technique is used to transform a dedicated device into the shared device.
3. What is a light pen?
The dedicated devices use shared allocation of memory. Shared devices use memory
4. Define bar codes.
management. Virtual memory addresses are translated into physical memory
5. What are the most
commonly used addresses through the use of a look up table called a page table. In addition to
mediums for mapping the entire process into virtual memory, a subset of pages is also mapped
inputting visual into physical memory. Certain devices require either manual actions or time
data?
consuming I/O operations which are to be performed prior to use by a job. Such
type of shared devices are used in job scheduling routines of processor management.
Self-Instructional
166 Material
A shared device is logically created and having a separate area for processing the Device Management
data. The devices, such as card readers, magnetic tapes and printers can be used in
serial way which states that single job is processed at a time. Dedicated device,
such as printer only starts job if the particular device is available and hence it is
considered as a dedicated device. But it complicates the multiprogramming and NOTES
priority scheduling. If a system has two printers, a simple dedicated device allocation
in turn results the process of multiprogramming in a limited way. For example, in
spooling process all job output is intended to be kept in the memory on a direct
access device, such as drum or disk until all the issued jobs are completed. The
main problem occurs with the use of shared devices that it is handled by the operating
systems. The validity of I/O jobs are checked by the operating system and for this,
assigned channel and control unit are allocated. They cannot be allocated again as
soon as the I/O jobs are completed. The dedicated and shared devices directly
associated with memory management. USB, pen drives, etc., are considered as shared
devices and external hard disk device is considered as dedicated device in network
era. All these devices are used frequently by the users to share information and data
from one system to other system.
Universal Serial Bus Device
Universal Serial Bus (USB) is considered as high speed serial bus and prime tool
for shared devices. Its data transfer rate is higher than that of a serial port. It supports
interfaces, such as monitors, keyboard, mouse, speaker, microphones, scanner, printer
and modems. It allows interfacing several devices to a single port in a daisy chain
printer. USB provides power lines along with data lines. USB cable contains a set
of four wires collectively in which two of them are used to supply electrical power
to peripherals which eliminates bulky power supply. And, the other two wires are
used to send data and commands. USB uses three types of data transfer and they are
isochronous or real time, interrupt driver and bulk data transfer. USB is a set of
connectivity which is developed by Intel. It is easily connected with other peripherals
to the system unit. The configuration process takes place after plugging in the
Integrated Development Environment (IDE) cables to the socket. USB is to be
considered as most successful interconnection device in the computer world. It can
easily migrate to the mobile gadgets and other consumer electronics too. It avoids
special types of interface cards and easily movable to the laptop. An USB was
released in the year of 1995. It is operated at the speed of 480 Mbps and hence
considered as prime portable and shared device.

Fig. 5.22 Twin Universal Serial Bus Device

Figure 5.22 shows the prime shared device known as twin universal serial bus device.
Basically, it is a matched pair of USB devices that can be used to share information
between two computers securely. It is plugged into two Personal Computers (PCs)
and they are able to share data between each other over the Internet. If one is removed
Self-Instructional
Material 167
Device Management then the connection is broken and the data sharing process stops. The various types
of portable devices, such as handhelds, digital cameras and mobiles are connected
to the system unit. For example, the images and pictures, music files, multimedia
files are transferred from digital camera to a printer with the help of USB or wireless
NOTES USB. The wired technology is enabled to the mobile lifestyle. It connects the power
telephonic conversation and videoconferencing technique. In USB, four wire cables
are interfaced. Two of the wires are set for differential mode. The function of this
mode is to transmit and receive the information and data. The rest two wires are set
for power supply. The source of power comes from the host. Hub is self powered.
Two different connectors are used with USB cable in which one end connector is
attached for upstream communication whereas other end connector is used for
downstream communication. The USB cable length is available in 5 meters long.
External Hard Disk Device
An External Hard Disk (EHD) device is considered as shared and portable device.
It is required for computer system if hard disk is not sufficient to store all the important
data. First you need to learn the quick installation of this peripheral. For configuration
you need to connect the mini connector of USB cable to the back of the drive. Then,
connect the standard USB ports on your computer. The line labeled with symbol
provides auxiliary power. It is needed only if you computer does not provide the
sufficient USB power through other line. For PC users the drive icon should appear
in ‘My Computer’ or ‘Window’s Explorer’.

Fig. 5.23 External Hard Disk Drive Device

Figure 5.23 shows a dedicated device known as external hard disk device. This
device is a hardware storage device which essentially needed by everyone who
works on PC’s. This device is dedicated and portable device. It is much faster modes
of dedicated data storage devices compared to other removal media, such as Compact
Disk (CD) and Digital Versatile Disc (DVD). Thus, moving in and out of data from
this device is very fast. Its cost is also reasonable keeping in consideration the
features it provides. This device of various prices is available in the market depending
on storage, power consumed and quality of the product. Therefore, the best option
is to choose the best external hard drive with reasonable price keeping in
consideration the budget. Many compatibility problems arise while buying an
external hard drive. The external hard drive workable with your system should be
purchased. Always make sure that the product is compatible with your computer.
This dedicated device is used for backup and for those PC which needs relatively
less storage should buy low storage capacity external hard drives. So, this device
Self-Instructional
168 Material
fulfills the requirement of the user keeping in consideration for budget. For Mac Device Management
user, you would need to reformat the external hard disk device. The external and
portable hard disk supports to take the safe periodic system backup and frequent
data backups and also considered that the critical data is always protected in this
drive. The frequency of backup depends on the importance of data. To protect the NOTES
data, you need to simply drag and drop copies of the critical files onto the drive.
Any data storage device can fail so you always keep at least two copies on different
disks for all types of documents and data, such as images, video clips, texts, etc.
The two types of messages are scrutinized if hard disk drive is configured with the
PC during the time of troubleshooting process. These messages are displayed on
the screen of PC. You must try the following suggestions if the drive does not appear
in ‘My Computer’. The following steps are required in troubleshooting process of
external hard disk drive device:
 Try restarting your PC.
 Make sure you are using the USB cable that comes with the drive.
 Make sure both lines of the USB cable are connected to the PC.
 Try changing the connections to different USB ports.
If PC will not start up when the portable drive is connected, the Basic Input Output
System (BIOS) on the computer probably have a conflict and hindrance with large
capacity removable drives. To work around this problem you need to power off the
drive during start up the computer. Power on the drive after the computer finishes
starting up. To use disk management, you need to use the Disk Utility option to
reformat the drive. For this, you need to select Application  Utilities  Disk
Utility. The disk utility basically works with disks and volumes. The term ‘disk’
refers to the hard drive itself in which a ‘volume’ is a formatted section of a disk.
Each disk has a minimum of one volume. You can use ‘Disk Utility’ to create a
single volume or multiple volumes on a disk.
Pen or Thumb Drive Device
The thumb drive or pen drive device is also a prime shared device. With the help of
this drive you can share various documents, multimedia presentations, pictures,
Moving Picture Experts Group (MPEG), Media Audio Player 3 (MP3) files by using
this hot Plug and Play (PnP), high speed USB 2.0 flash drive. This drive is made of
rugged aluminum casing. Sharing and transferring files have never been so easy
process with data reliability and security at the premium. For transferring or backing
up the files you need to simply plug in your USB flash disk. With capacities up to
1GB you can share with your important files, music, images wherever you go from
one place to other place and hence considered as portable device.

Fig. 5.24 512MB Thumb Drive Device


Self-Instructional
Material 169
Device Management Figure 5.24 shows the frequently used shared device known as thumb or pen drive
device. A thumb drive is portable and shared memory storage device. It is re-writeable
and holds its memory without a power supply unlike RAM. Thumb drives can be fit
into any USB port on a computer. They follow ‘hot swap’ process in which a user
NOTES can plug the drive into a computer and will not have to restart it to access the thumb
drive. This device is small about the size of a human thumb hence their got its name
as ‘thumb drive’ and are very stable for shared devices. Most of the thumb drives
come equipped with software that installed a Win98 driver on the computer enabling
the user to connect a thumb drive. Installing the small software takes sixty seconds.
Thumb drives also pose security threats since they are easily concealed. Users could
copy proprietary information to them or upload hacking software from them and all
undetected by the system administrator. The thumb drive is available in storage
sizes of up to 16GB.
5.3.1 Virtual Devices
Virtual devices are also referred to as a virtual peripheral and works as a physical
hardware device. They are virtually attached with the CPU believing that a device
exists but actually it is not possible. For example, fax software can act as a virtual
printer. When print is selected, the document is sent to a fax/modem which then
sends information to another fax/modem or fax machine instead of a printer printing
the file. Virtual devices use virtual memory for processing the data. Virtual memory
system came into existence in the very early age of computer programs development.
In many Microsoft Windows operating systems, the Virtual Device Driver (VDD)
is the program which is in charge of handling software interrupts come from the
operating system. The device driver which is not virtual will handle hardware
interrupts and not software interrupts and makes virtual device drivers different.
Each hardware device for the computer will have a virtual device driver including
serial and parallel ports, the hard disk drive controller, keyboards, mouse, etc. These
devices play an important part in the way that your system can be operated
successfully. It is a good idea to keep your virtual device drivers updated on a
regular basis as well, to ensure there are no bugs in the way it works. If you have a
newer operating system, you may be able to upgrade all the device drivers on your
system virtual as well as other types simply by going to the Windows Device Manager
(WDM). If you have an operating system that does not allow device driver upgrades,
you can download and install a commercial device driver upgrade tool. There are
plenty of these software programs available online and a simple search will help
you find the ones you require. These tools will scan your system for all the device
drivers which are installed then compare this list to the database of updates to find
matches. The programs are so complex and big and sometimes not able to fit in the
available memory. It is better to divide the programs into pieces. These pieces are
known as overlays. The overlays can be swapped dynamically in and out of the
memory by OS. VMS was first devised by Fotheringham in 1961. This system was
developed because the program, data and stack might together exceed from the
amount of available physical memory. Virtual Memory (VM) systems use physical
Dynamic Random Access Memory (DRAM) as a cache for the disk in the system
unit. The VM address space exceeds physical memory size. The Virtual Memory
System (VMS) simplifies the memory management because multiple processes reside
in main memory. Each process has its own address space. This system provides
protection because one process can not intervene with other process because both
processes operate in different address spaces.
Self-Instructional
170 Material
Device Management

Virtual Physical
Processor Disk
Memory Memory

Memory OS (Virtual NOTES


Management Memory Manager)

Fig. 5.25 Virtual Memory System

Figure 5.25 shows how virtual memory system is organized collectively in the disk,
processor, physical memory, virtual memory, Memory Management Unit (MMU)
and operating system that manages virtual memory. In the VMS, the page table
plays an important role to manage the memory. The disk keeps all the system files
and the programs to run successfully the OS.
Some of the devices normally have to be dedicated, for example card readers
and can be converted into shared devices with the help of techniques, such as
SPOOLing. A SPOOLing program can read and copy all card input onto a disk at
high speed. . If a process tries to read a card the SPOOLing program intercepts the
request and then converts into a dedicated device to a shared device. This whole
process can be done with the help of virtual card reader. This is applicable to a large
number of peripheral devices, such as teletypes, printers and also with slow I/O
devices. Some of the devices, such as disks, drums and other types of Direct Access
Storage Devices (DASD) can be shred concurrently by several processes. These
processes are read from a single disk at essentially the same time. The management
of shared device can become complicated if efficiency of run time performance is
desired. For example, if two processes simultaneously request a Read operation
from Disk A then it must be determined which request should be handled first. This
process is fulfilled by virtual devices. Virtual device is a platform for Web services
composition that provides the user with a new way to experience the content on the
web. Virtual devices application combines data from multiple sources into a single
integrated tool to create a new Web service and hence applicable for multimedia
applications. Various Web services can be interconnected to process Web content
from different sources thus generating a different view of the data. A set of virtual
software devices are wired together with virtual equipments which resembles an
audio rack in the multimedia applications, for example Really Simple Syndication
(RSS) Aggregators, Google Search, Twitter, Speech Engine, ITunes, PayPal and so
on. Microsoft Windows operating systems supports the virtual device driver is the
program which is in charge of handling software interrupts which come from the
operating system. Device drivers which are not virtual can handle the hardware
interrupts and not software interrupts and this is reason which makes virtual device
drivers different. Each hardware device for the computer will have a virtual device
driver and this includes serial and parallel ports along with the hard disk drive
controller, keyboards, mouse and others. This is done partially by software, such as
I/O schedulaer and traffic controller or completely by hardware with very
sophisticated channels and control units. The virtual devices use policy for
establishing which requests are to be satisfied. This mechanism is based either on
priority list or the objective of achieving improved system output, for example by
choosing whichever request is very nearest to the current position of the read head
of the disk. Virtual device drivers are needed by your computer when a hardware
Self-Instructional
Material 171
Device Management device has settings which can be changed so that the current settings can be
maintained. These drivers play an important part in the way that the system and
devices operate and perform. It is a good idea to keep your virtual device drivers
updated on a regular basis as well to ensure there are no bugs or viruses works with
NOTES the system unit. If you have a newer operating system, you may be able to upgrade
all the device drivers on your system, virtual as well as other types simply by going
to the Windows Device Manager (WDM). Virtual devices use virtual memory. VMS
came into existence in the very early age of computer programs development. The
programs are so complex and big and sometimes not able to fit in the specified
memory. The better option is to be chosen to divide the programs into subprograms.
These subprograms are known as overlays. The overlays are swapped dynamically
in the memory processed by OS. VMS was first devised by Fotheringham in 1961.
This system was developed because stack, data and programs together exceed from
required physical memory. Virtual memory use cache in physical DRAM in the
system unit. The VM address space exceeds physical memory size. The VM system
simplifies the complete memory management which resides in the main memory.
The involved process has own address space. This system provides protection because
one process can not intervene with other process because both processes operate in
different address spaces. Let us take an example of Android Virtual Device (AVD).
You can create as many AVDs as you need based on the types of devices you want
to model and the Android platforms and external libraries you want to run your
application on. In addition to the options in an AVD configuration you can also
specify emulator command line options by using the emulator console to change
behaviors or characteristics at run time. An AVD is a device configuration for the
emulator that allows you to real world devices. For this, you first need to create an
AVD. Virtual devices can be created in Android Software Development Kit (SDK)
and AVD manager tab as shown in screen below.

You can test these virtual devices and see how nicely the phones are emulated
as shown in the following screen. This is very useful once you begin writing
applications.

Self-Instructional
172 Material
Device Management

NOTES

The Android SDK includes a mobile device emulator, i.e., a virtual mobile
device that runs on your computer. The emulator lets you prototype, develop and
test Android applications without using a physical device. The Android emulator
supports all of the hardware and software features of a typical mobile device except
that it cannot receive or place actual phone calls. It provides a variety of navigation
and control [CTRL] keys which you can be pressed using your mouse or keyboard
to generate events for your application. It also provides a screen in which your
application is displayed together with any other Android applications running. AVDs
let you specify the Android platform that you want to run on the emulator, as well as
the hardware options and emulator skin files that you want to use. Once your
application is running on the emulator, it can use the services of the Android platform
to invoke other applications, access the network, play audio and video, store and
retrieve data, notify the user and render graphical transitions and themes.

The main function of emulator is to provide a variety of debug capabilities,


such as a console from which you can log kernel output, simulate application
interrupts, such as arriving Short Message Service (SMS) messages or phone calls
with the help of data channel as shown in screen above. Virtual devices use Bluetooth
and Wi-Fi services in data communication process. The Bluetooth technology has
been designed to connect both mobile devices and peripherals that currently require
a wire. The services of Bluetooth are provided by wireless in which no setup is
needed. The transfer speed of data rate is 1.0 Mbps. It holds radio frequency chips,
which are plugged into the devices. It maintains 2.45 GHz frequency. It uses a
technique called spread spectrum frequency hopping. The Bluetooth and wireless
Self-Instructional
Material 173
Device Management networking are closely related to Wi-Fi connectivity through radio waves. The Wi-
Fi stands for wireless fidelity. It is used for wireless devices. The Wi-Fi Alliance
represents the wireless standard protocol and basically non-profit organization. This
supports interoperability features for wireless devices. It connects the networking
NOTES system without cables. But for this, Wi-Fi and regular ISP services are needed. The
manufacturers of Wi-Fi Alliance build the various devices for 802.11 standards.
Approximately 205 companies are joined to the Wi-Fi Alliance and almost 900
products have been certified to the interoperable system. These companies give
assurance that the Wi-Fi devices are connected by physical layer in reference models.
Wi-Fi Protected Access (WPA) Solution added recently to the Wi-Fi standard. The
physical and access control layer implement the extra enhanced features, such as
Internet security. The Wi-Fi can be grown by leaps and bounds because it is connected
via spectrum. It uses unlicensed 24 GHz and 5 GHz bands. It provides data throughput
for most uses. The prime equipment is required for Wi-Fi connection is Wi-Fi PC
card. It is common way to connect the computer to the Internet without wires. This
card is technically known as Personal Computer Memory Card International
Association (PCMCIA). But the basic difference between Bluetooth and Wi-Fi is
that Bluetooth replaces cables at the primary stage whereas Wi-Fi is completely
considered to be wireless technology. In these days, Bluetooth community uses Wi-
Fi protocol.

5.4 DISK MANAGEMENT AND SCHEDULING


Disks are used to store bulk data as secondary storage for modern computers. A
hard disk has a device controller which translates numerical addresses into head
movements. The device controller gets the instructions for execution from the
operating system.
A Small Computer System Interface (SCSI) drive is the most popular drive
used for large personal computers and workstations. An SCSI is of four types—
SCSI 1, SCSI 2, fast SCSI 2 and SCSI 3. An SCSI drive is coupled with a bus and
identifies an SCSI address. Each SCSI controller can address up to seven units.
Each track is usually divided into sectors; a sector is a fixed size region which
is present along the track. When writing to a disk, data is written in units of a whole
number of sectors. On a disk, the number of sectors per track is not constant, nor is
the number of tracks. If a sector is damaged, it must be patched up by some repair
program. Usually, data in that sector is lost. Disks must be checked for damages.
When a disk is formatted, the damaged sectors are not used for storing data. The
SCSI drive keeps a defect list that consists of all bad sectors. A new disk contains a
list of sectors and is updated as more defects occur. Formatting is a process by
which the sectors of a disk are created along the tracks; each sector is labelled with
an address, so that the disk controller can find the correct sector.
On simple disks, formatting is done manually. On complex, disks such as
SCSI drives, a low level formatting on the disk is done by the manufacturer. High
level formatting is not necessary when a file system is able to manage the hardware
sectors.
Data consistency is checked by writing data to the disk and reading back the
data. An error occurs if there is any disagreement. Some device controllers detect
bad sectors and move data to a good sector if there is an error. Another way of
Self-Instructional
174 Material
checking data consistency is to calculate a number for each sector in which the Device Management
number is calculated on the basis of what data is present in the sector. The calculated
number is stored in the sector. When data is read back, the number is recalculated
and if there is disagreement, then an error is generated. This is called Cyclic
Redundancy Check (CRC) or error correcting code. NOTES
The disk drive rotates at the speed 60 to 200 rotations per second. Transfer
rate is the rate at which data flows between a drive and a computer. Positioning
time (random-access time) is the time for moving the disk arm to the desired cylinder
and is also called seek time. The time for the desired sector to rotate under the disk
head is called rotational latency. Head crash results from the disk head making
contact with the disk surface. Host controller in computer uses bus to talk to disk
controller built into the drive or storage array.
5.4.1 Disk Structure
A disk is the permanent storage media. It is divided into a number of cylinders in
which each cylinder is divided into a number of tracks; each track is divided into a
number of sectors and each sector has several blocks, as shown in Figure 5.26.
Addressing of disk drive is done as large one-dimensional arrays of logical blocks.
A logical block is the smallest unit of transfer. The size of a logical block is generally
512 bytes. The one-dimensional array of logical blocks is mapped into the sectors
of the disk sequentially. Sector 0 is the first sector of the first track on the outermost
cylinder. Mapping proceeds in order through that track, then the rest of the tracks in
that cylinder, and then through the rest of the cylinders from the outermost to the
innermost.
To access the disk faster, each track is usually divided into sectors; a sector is
a fixed size region which is present along the track. When writing to a disk, data is
written in units of a whole number of sectors. Because the heads of the disk move
simultaneously on all the surfaces of the disks, we can increase read/write efficiency
by allocating blocks related to one file in parallel across all surfaces.
The physical properties of a disk are number of tracks, sectors per track,
speed of revolution and the number of heads (refer Figure 5.26). An operating system
must access all the different types of disks without any difficulty. On a disk, neither
the number of sectors per track is constant nor is the number of tracks.

Fig. 5.26 Physical Properties of a Disk

5.4.2 Disk Scheduling


The operating system is responsible for the efficient use of the disk drives which
means having fast access time and a high bandwidth for the disks. The disk header
Self-Instructional
Material 175
Device Management moves only in the forward or backward direction. The access time has the following
three major components:
 Seek time is the time required for the disk to move the heads to the cylinder
containing the desired sector.
NOTES  Rotational latency is the time required for the disk to rotate the desired sector.
 Transfer time is the time taken to transfer the data present in the blocks in
a sector.
The transfer time is so fast that it can be negligible. The rotation latency is
normally 7200 rpm, i.e., 120 rotations per second. Even this value is negligible.
The efficiency of the operating system is directly dependent on the seek time. The
objective of the operating system is to minimize seek time.
Disk bandwidth is the total number of bytes transferred, divided by the total
time between the first request for service and the completion of the last transfer.
Disk access time for any request must be as fast as possible. Scheduling is
done to improve the average disk access time. The speed of access depends on seek
time. Each disk drive has a queue of pending requests. A request can be the input
request (write request) or output (read request). A disk address consists of disk
number, cylinder number, surface number, sector number and the number of blocks
to transfer.
Data in the blocks is transferred into the main memory address. Block numbers
indicate the amount of information to be transferred, i.e., the byte count.
Disk Scheduling Algorithms
Servicing of disk I/O requests can be done by using disk scheduling algorithms.
We illustrate disk scheduling algorithms with an example.
Consider a disk with 200 tracks from 0 to 199. Let the request queue be as
follows:
98, 183, 37, 122, 14, 124, 65, 67
And, let the head point to 53 track.
In the above example, the disk has 200 tracks. Request queue has 98 as its
first request. Here, the disk must be moved from 53 track to 98 track as the disk
header is positioned at 53 track initially.
FCFS Scheduling
First Come, First Serve (FCFS) scheduling is the simplest form of disk scheduling.
It is a fair algorithm and may not provide the best possible service.
For the ordered disk queue with requests on tracks is shown in the screen
below.
98; 183; 37; 122; 14; 124; 65; 67
Read/write head initially at track 53
From 53 track the header moves to 98 track
From 98 track the header moves to 183 track
From 183 track the header moves to 37 track
From 37 track the header moves to 122 track
Self-Instructional
176 Material
From 122 track the header moves to 14 track Device Management

From 14 track the header moves to 124 track


From 124 track the header moves to 65 track
From 65 track the header moves to 67 track NOTES

Total head movement = 640 tracks


And there is a wild swing from 122 to 14 and back to 124. Wild swings occur
because the requests do not always come from the same process and they are inter
leaved with requests from other processes.
SSTF Scheduling
Shortest Seek Time First (SSTF) scheduling selects the request with the minimum
seek time from the current head position. SSTF scheduling is a form of Shortest-
Job-First (SJF) scheduling and it may cause starvation of some requests. This
algorithm services all requests close to the current head position before moving the
head far away, i.e., moves the head to the closest track in the service queue.
A service queue can be serviced as shown in screen below.
53; 65; 67; 37; 14; 98; 122; 124; 183

Self-Instructional
Material 177
Device Management 53; 65; 67; 37; 14; 98; 122; 124; 183
From 53 track the header moves to 65 track
From 65 track the header moves to 67 track
NOTES From 67 track the header moves to 37 track
From 37 track the header moves to 14 track
From 14 track the header moves to 98 track
From 98 track the header moves to 122 track
From 122 track the header moves to 124 track
From 124 track the header moves to 183 track
Total head movement = 263 tracks.
SCAN Scheduling
The disk arm starts at the one end of the disk and moves toward the other end
servicing requests until it gets to the other end of the disk where the head movement
is reversed and servicing continues.
This is also termed as elevator algorithm due to its similarity with building
elevators. The head constantly scans the disk from one end to the other. For example,
the read/write head begins at one end of the disk and proceeds towards the other
end servicing all requests as it reaches each track. At the other end, the direction of
head movement is reversed and servicing continues. For example, assume a head
moving towards 0 in a queue 53; 37; 14; 0; 65; 67; 98; 122; 124; 183 as shown in
screen below.

Total head movement = 236 track.


When head reverses, we have only a few requests. Heaviest density of requests
is at the other end.

Self-Instructional
178 Material
C SCAN Scheduling Device Management

Circular SCAN (C SCAN) refers to a variation of SCAN scheduling. It moves the


head from one end to the other. When it reaches the other end, it immediately come
back to the first end without servicing any requests on the way. NOTES

LOOK Scheduling
LOOK scheduling moves the head only till the last request in that direction. No
more requests in the current direction reverses the head movement. Before you
move in that direction, you need to look for a request.
Placing directories halfway between the inner and outer tracks of a disk reduce
the head movement.
SSTF is common and has a natural appeal.
SCAN and C-SCAN perform better for systems that place a heavy load on
the disk.
Performance depends on the numbers and types of requests.
Requests for disk service can be influenced by the file allocation method.
A disk scheduling algorithm should be written as a separate module of the
operating system, allowing it to be replaced with a different algorithm, if necessary.
Either SSTF or LOOK is a reasonable choice for the default algorithm.
When a user wants to open a file, an operating system needs to locate the file
in the directory structure. The operating system searches the directory structure
frequently. If the directory structure is present in the first track and the file data is
present on the last track then the head must be moved from the first track to the last
track. This decreases the performance. To improve the performance, the directory
structure is cached for faster access. The disk scheduling algorithms are complex to
implement hence, they are written in separate module of the operating system.

Self-Instructional
Material 179
Device Management Table 5.1 summarizes the various types of tools and devices used in multimedia
system.
Table 5.1 Devices used in Intelligent Multimedia System

NOTES Devices Functions


This device (speaker) is used in multimedia
system and virtual reality applications. It accepts
80Hz-20KHz input sensitivity.

This device (CD/CD R/CD RW) is also used in


multimedia system and virtual reality
applications.

This audio CD Player PCD-901 device plays with


CD R/CD/DC RW device.

This headphones device keeps input power 50mw


frequency response and its 20Hz-20KHz capacity
uses 98dB/mw at 1 KHz.

Video VCD player device is used to play the


audio and video files.

The wireless speaker is used to maintain the


system frequency response for 35Hz-20kHz
degree of distortion.

The multimedia speaker W-400D consists of 4.1


channel audio super-woofer output with low
noise power audio, for example 560W and is
used in multimedia system and virtual reality
applications.
This device is a type of USB portable panel
speakers and for this, no power is needed. Its size
is 150mm (W) ×120mm (H). W represents width
and H represents height of the device
respectively.
This PC camera CMOS sensor device is basically
used for image resolution. This device uses
352×288 file format and 15 frames per second
(fps) catch speed for Audio Video Interleaved
(AVI) images. This device is used to process the
multiple video files at a time.

5.5 SPOOLING
Simultaneous Peripheral Operation OnLine (SPOOLing) is a way of processing
data serially. Print jobs are spooled to the printer because they must be printed in
the right order. During a spooling operation only one job is performed at a time and
other jobs wait in a queue to be processed. Spooling is considered as a form of batch
processing. One difficulty with simple batch systems is that the computer still needs
to read the deck of cards before it can begin to execute the job. This means that the
Self-Instructional
180 Material
CPU is idle during these relatively slow operations. Since it is faster to read from a Device Management
magnetic tape than from a deck of cards it became common for computer centers to
have one or more less powerful computers in addition to their main computer. Since,
the I/O operation could proceed while the CPU is used on a user program then little
degradation in performance is noticed. Since, the computer performs I/O operations NOTES
parallel it is possible to have the computer read a deck of cards to a tape, drum or
disk and to write out to a tape printer while it has been computing. This process is
called SPOOLing. I/O software is implemented with the operating system which
requires a small portion in main memory. This software is consisted of libraries
linked together with user programs but other system programs run outside the kernel.
System calls are made by various library procedures including I/O system calls. For
example, a function is written in ‘C’ language as follows:
count = write (fd, buffer, nbytes);
The write() function will be linked with the program and contained in the form
of binary program implemented in memory at run time. All I/O software is also not
consisted of library procedures. Then, the spooling system is preferred. SPOOLing
process is used with dedicated I/O devices which are assembled through
multiprogramming system, for example for printing a file or document a process is
opened in which no other process could print. Printer is considered as typical spooled
device. For this, a special process known as daemon is created. A special directory
is also created to contain the process. This directory is known as spooling directory.
To print a file a process first generates the entire file to be printed and puts it in the
spooling directory. The SPOOLing process is not only used for printers but also
used for transferring the file over a network using network daemon. Sending file
across network users put the file in a network SPOOLing directory. Then, the network
daemon takes it out and transmits the data to the destination. Spooled file is especially
transmitted in the Internet electronic mail system. Data SPOOLing process allows
you to specify the storage daemon to initially write your data to disk and then
subsequently to tape. This serves several important purposes.
 It takes a long time for data to come in from the file daemon during an
incremental backup. If it is directly written to tape then the tape will start and
stop as it is often called causing tape wear.
 While the spooled data is being written to the tape the de-spooling process is
used. This means you can spool multiple simultaneous jobs to disk.
 Writing to a tape can be considered as slow process. By first spooling process
you can often reduce the time in which the file daemon run on a system.
Thus, it reduces the downtime and intervenes with users. If your spool device
is not large enough to hold all the data from then the file daemon is used to
backup the files and information.
Interactive interfaces are used for interactive use for exploration. The programming
interfaces interact with various applications in detail supports inter application
programming by using (COM), scripting and Common Object Request Broker
Architecture (CORBA). In the phase of system interface design the various types of
system calls work together with the same functionality as well as working with
spooling process. The interface is designed between the operating system and its
running application programs, collectively called a set of system calls. For example,
a function is written in ‘C’ language as call to read() function can be written in
‘C’ as follows:
count=read(file,buffer,mbytes);
Self-Instructional
Material 181
Device Management If the system call is not worked out because of disk error or keeping invalid
parameters, the error number is written ‘errno’. The errno is a keyword
and count is to be set to -1, if error comes. The process management is dealt with
the system call and FORK is used to create a new process. It creates duplicate copy
NOTES of original process that includes registers and file descriptors. The FORK call returns
an integer value. It is used by shell. The command is typed at command prompt and
the FORK at shell forks off a new process. A good quintessential of system calls for
signaling is DEL key. This key sends a signal to delete the texts, files, folders or
objects whereas the KILL system also allows a process to signal another process
by using kill program.
Spooling batch systems are the simplest form of the multiprogramming systems.
One advantage of spooling batch systems is to deliver output from jobs rather than
only after all jobs in the current cycle is finished. The line printer spooling utility is
software that manages the print spooling system. SPOOLing is a technique that
temporarily stores data until it is ready to be processed by your printer. For line
printer SPOOLing, a file or group of files to be printed is stored in a queue until a
printer becomes available as shown in Figure 5.27. When the printer is available
the next file in the queue is printed.

Printer 1

Printer 2
Queue 1

Print
requests

Queue 2

Print
requests

Check Your Progress


6. How is the validity
of I/O jobs
checked? Fig. 5.27 Print SPOOLing
7. Name some of the
interfaces supported Figure 5.27 shows the process of print spooling in which print requests have been
by the USB. sent to the Printer 1 and Printer 2. Two queues namely Queue 1 and Queue 2 wait
8. How is formatting for the printing jobs and take down the documents to the desired printer. Network
carried out on
complex disks? print servers allow several users to use the same printer. In a network, printers are
9. How is the attached to remote systems known as print servers. The remote systems are used
consistency of the with print servers. The workstations accessing the print servers are called print
data rectified? clients as shown in Figure 5.28.
10. What is disk
bandwidth?

Self-Instructional
182 Material
Device Management

Print NOTES
servers
Print
server
systems

Print
clients

Fig. 5.28 Print Clients, Print Server Systems and Print Servers

Print servers must be configured on the print server system before remote clients
can configure them successfully across the network.

5.6 I/O SYSTEMS AND DEVICE DRIVERS


In the Input/Output (I/O) organization, the I/O system decides how to work with
device driver, disk head scheduling, unification of files and devices. The following
mechanisms are implemented in the I/O system with reference to widely and
popularly used operating systems in the network era. The I/O system is denoted by
a sequence of bytes. This is accessed sequentially or randomly. The various levels
of structure do not put impact on the structure of I/O. For example, the text files
conventions lined with American Standard Code for Information Interchange (ASCII)
characters are separated by newline character known as line-feed character. The
kernel of OS does not know the convention. Therefore, the I/O stream of data bytes
is simplified by a common data form that makes the tool-based approach in I/O
system. An I/O stream from one program can be fed to almost all other programs as
input. For example, UNIX OS prefers to use descriptors to open and socket the
system calls. Basically, the descriptors are small unsigned integers. The standard
input is taken for file descriptor 0, standard output is 1 and standard error is taken as
2. The arguments of open system call are file and permission mode for specifying
whether the file is going to be opened for reading or writing. The system call is used
to create new and empty file. The close system call is used to deallocate the descriptor.
The I/O devices are accessed by files.
Device Drivers
A device driver interface is designed to make a link between design issues and
techniques. Table 5.2 shows the four prime functions written in ‘C’ language used
in the device driver:
Self-Instructional
Material 183
Device Management Table 5.2 Various Interfaces of a Device Driver and their Functions

Device Driver Interfaces Function


Open(int deviceNumber) The controllers open the device and control more
NOTES than one device.
Close(int deviceNumber) The controllers close the device after processing.
Read(int deviceNumber, The controllers read the device number and
int deviceAddress, void address of the device.
* memoryAddress, int
length)
Write(int deviceNumber, The controllers read the device number and
int deviceAddress, void address of the device and then act accordingly to
* memoryAddress, int determine the design technique.
length)

The main use of device numbers is to name which device to use among those
controlled by a single controller, but they are often used to convey other information,
such as:
 The device number 0 rewinds after one successful completion whereas the
device number 8 does not rewind.
 The device number 0 works on normal-sized paper whereas device number 8
works on legal sized paper
 The device number 0 basically writes at high density, whereas device number
1 and device number 2 write on medium and low density respectively.
The two types of device drivers are: block or disk device drivers and character
device drivers. The block or disk device driver disks have fixed size and addressable
blocks, so no length is required. They are always in one block. The character device
drivers, on the other hand, deliver a stream of data with no addresses. In fact, no
device address is used in the character device drivers, which need a ‘device control’
command to handle detailed points, such as which paper tray is to be used. The
device control commands control the following functions:
 Determining the type of paper tray to use in a printer
 Rewinding a tape
 Turning an echo on a terminal
 Ringing the bell on a terminal
 Working as character and block interfaces

Self-Instructional
184 Material
Device Management

NOTES

Fig. 5.29 Device Drivers

The device drivers perform double buffering, disk head scheduling that
controls batching and aging as solutions to starvation and disk models (refer Figure
5.29). Generalized device drivers, disk partitions, RAM disks, Pseudo-tty and disk
caching interact with each other to decide the I/O system architecture (refer Figure
5.30). Devices controllers connect to the bus and represent the devices. Device
drivers talk to device controllers and through them to the devices. Device drivers
present a common interface to the rest of the OS.

Pseudo-tty Program using


device driver a “terminal”

Pseudo-tty Program pretending


control to be a terminal
device driver

Fig. 5.30 Pseudo-tty Device Driver


Self-Instructional
Material 185
Device Management The following functions of device drivers create useful effects in the I/O system:
 They make partition of physical disk into various logical units. These units
are called partitions.
NOTES  They work on single logical unit that is a combination of various physical
disks.
 They enhance RAM as a super fast disk.
 They can read address space in a disk.
 They basically work to a program and not to a terminal.
Figure 5.31 shows the flowchart of partitioning a disk.

Fig. 5.31 Partitioning a Disk

Disk Head Scheduling


The disk head scheduling mechanism is also an important task that helps in taking
many useful decisions. For example, if we have two or more pending disk requests,
this mechanism helps in deciding which one should go first. The disk head scheduling
works on various mechanism, such as FCFS, SSTF, etc. The SSTF solves the
starvation problem by using the two techniques known as batching and aging.
Elevator algorithm is required for disk head scheduling. The elevator algorithm
starts at cylinder 0 with direction ‘up’. The required steps are as follows:

Self-Instructional
186 Material
Step 1: Let current cylinder be N. Device Management

Step 2: The second step is required to select the closest request for cylinder
‘N’ for up direction otherwise select the else option that is less higher for
cylinder ‘N’ for low direction.
NOTES
Step 3: The switch direction can be used if no request direction is determined.
Step 4: The Step 2 is repeated at this step.
The disk scheduling is necessary because FCFS scheduling has major
drawbacks, such as it seeks randomly distributed locations if there are heavy load
traps on the running OS. But disk scheduling algorithm minimizes the seek times
with high latency. The modern OS performs rotational optimization via throughput
that performs a number of requests per unit of time and mean response time that
spends average time or the required services and variance in response time that
measures the predictability of response time. Maximization of throughput and high
bandwidth are the overall goals of I/O systems.
Unification of Files and Devices
The unification of files and devices are arranged in I/O system. In this mechanism,
the device driver works as the file interface that keeps the coding to translate to the
device driver interface. The file commands can be used in device objects to unify
the I/O system.

5.7 SUMMARY
 Computers have an Input/Output (I/O) subsystem referred to as I/O subsystem
which provides an efficient mode of communication between the central
system and the outside world.
 The I/O devices that provide a means of communication between the computer
and the outside world are known as peripheral devices. This is because they
surround the Central Processing Unit (CPU) and the memory of a computer
system.
 Input devices are used to transfer user data and instructions to the computer.
The most commonly used input devices can be classified as Keyboard devices
(general and special purpose, key to tape, key to disk, key to diskette), Point
Check Your Progress
and draw devices (touch screen, touch pads, light pen, trackball, joystick),
Scanning devices (mouse, optical mark recognition, magnetic ink character 11. What is the
disadvantage with a
recognition, optical bar code reader, digitizer, electronic card reader), Voice simple batch
recognition devices and Vision input devices (webcam, video camera). system?

 The most popular keyboard used today is the 101 key with a traditional 12. What is a
SPOOLing
QWERTY layout, with an alphanumeric keypad, 12 function keys, a variety directory?
of special function keys, numeric keypad, and dedicated cursor control keys. 13. Why is a device
 A mouse is a small input device used to move the cursor on a computer driver designed?
screen to give instructions to the computer and to run programs and 14. What are the
mechanisms on
applications. which the disk head
 A touch pad is a touch sensitive input device which takes user input to control scheduling can
the onscreen pointer and perform other functions similar to that of a mouse. function?

Self-Instructional
Material 187
Device Management  The light pen is a small input device used to select and display objects on a
screen. It functions with a light sensor and has a lens on the tip of a pen
shaped device.
 Scanning devices are input devices used for direct data entry from the source
NOTES document into the computer system. There are two types of scanners, contact
and laser.
 Hand held scanners are used where the information to be scanned or the
volume of documents to be scanned is very low.
 The Optical Mark Recognition (OMR) devices can scan marks from a
computer readable paper. The Magnetic Ink Character Recognition (MICR)
device is like an optical mark recognition device and is used only in the
banking industry.
 Data coded in the form of small vertical lines forms the basis of bar coding.
Alphanumeric data is represented using adjacent vertical lines called bar codes.
 Digitizers are used to convert drawings or pictures and maps into a digital
format for storage into the computer.
 An output device is an electromechanical device that accepts data from the
computer and translates it into a form that can be understood by the outside
world.
 A display device is the most essential peripheral of a computer system. Liquid
Crystal Display (LCD) was first introduced in the 1970s in digital clocks and
watches, and is now widely being used in computer display units. The Cathode
Ray Tube (CRT) was replaced with the Liquid Crystal Display (LCD) making
it slimmer and more compact.
 Projection display technology is characterized by replacing the personal size
screen with large screens upon which the images are projected. It is attached
to the computer system and the magnified display of the computer system is
projected on a large screen.
 Printers are used for creating paper output. Printers can be classified as impact
or non-impact printers, based on the technology they use for producing output.
 Plotters are used to make line illustrations on paper. They are capable of
producing charts, drawings, graphics, maps and so on. A plotter is much like
a printer but is designed to print graphs instead of alphanumeric characters.
 A disk drive is a peripheral device used to store and collect information. It
can be removable or fixed, high capacity or low capacity, fast or slow speed
and magnetic or optical.
 The data is stored and numbered with respect to the track and sector number
on the disk; only the structure of the medium is different. The various types
of removable disk drives are Digital Versatile/Video Disc (DVD), Compact
Disk Read Only Memory (CD ROM), floppy disk drive, etc. A hard disk is an
example of a non-removable disk drive.
 The dedicated devices use shared allocation of memory. Shared devices use
memory management. A shared device is logically created and having a
separate area for processing the data.

Self-Instructional
188 Material
 An External Hard Disk (EHD) device is considered as shared and portable Device Management
device. It is required for computer system if hard disk is not sufficient to store
all the important data.
 Virtual devices are referred to as a virtual peripheral and works as a physical
hardware device. They are virtually attached with the CPU believing that a NOTES
device exists but actually it is not possible.
 Virtual Memory (VM) systems use physical Dynamic Random Access
Memory (DRAM) as a cache for the disk in the system unit. The VM address
space exceeds physical memory size. The virtual memory system simplifies
the memory management because multiple processes reside in main memory.
 Disks are used to store bulk data as secondary storage for modern computers.
A hard disk has a device controller which translates numerical addresses into
head movements. The device controller gets the instructions for execution
from the operating system.
 Disk bandwidth is the total number of bytes transferred, divided by the total
time between the first request for service and the completion of the last transfer.
 Circular SCAN (C SCAN) refers to a variation of SCAN scheduling. It moves
the head from one end to the other.
 Simultaneous Peripheral Operation OnLine (SPOOLing) is a way of
processing data serially. Print jobs are spooled to the printer because they
must be printed in the right order. During a spooling operation only one job is
performed at a time and other jobs wait in a queue to be processed. Spooling
is considered as a form of batch processing.
 In the Input/Output (I/O) organization, the I/O system decides how to work
with device driver, disk head scheduling, unification of files and devices.
The I/O system is denoted by a sequence of bytes.
 A device driver interface is designed to make a link between design issues
and techniques.
 The disk head scheduling works on various mechanism, such as First Come,
First Served (FCFS), Shortest Seek Time First (SSTF), etc. The SSTF solves
the starvation problem by using the two techniques known as batching and
aging.

5.8 KEY TERMS


 Cyclic redundancy Check: It is the process of generating an error due to a
disagreement during the recalculation of the numbers at the time when the
data is read back.
 Rotational latency: It is the time for the desired sector to rotate under the
disk head.
 SPOOLing: It is a way of serially processing the data.
 Hardcopy output: It is the output produced on paper or material that can be
touched.
 Print clients: These are the workstations that access the print servers.

Self-Instructional
Material 189
Device Management  Bar codes: It is the adjacent vertical lines which are used for representing
alphanumeric data.
 Page table: It is a look-up table using which virtual memory addresses are
translated into physical memory addresses.
NOTES
 Partitions: These are the logical units made by partitioning of physical disk
by I/O systems.
 Virtual devices: They are also referred to as a virtual peripheral and works
as a physical hardware device.
 Circular SCAN: It refers to a variation of SCAN scheduling which moves
the disk head from one end to the other. When it reaches the other end, it
immediately come back to the first end without servicing any requests on the
way.
 Line printer SPOOLing: It refers to utility software which manages the
print SPOOLing system.

5.9 ANSWERS TO ‘CHECK YOUR PROGRESS’


1. Input devices are used to transfer user data and instructions to the computer.
2. Keyboard devices are typically classified as general purpose keyboards and
special purpose keyboards.
3. The light pen is a small input device used to select and display objects on a
screen.
4. Data coded in the form of small vertical lines forms the basis of bar coding.
Alphanumeric data is represented using adjacent vertical lines called bar codes.
5. Webcams and video cameras are most commonly used medium for inputting
visual data.
6. The validity of I/O jobs are checked by the operating system and for this,
assigned channel and control unit are allocated.
7. USB supports interfaces, such as monitors, keyboard, mouse, speaker,
microphones, scanner, printer and modems.
8. On complex disks like SCSI drives, a low-level formatting on the disk is
done by the manufacturer.
9. Data consistency is checked by writing data to the disk and reading back the
data.
10. Disk bandwidth is the total number of bytes transferred, divided by the total
time between the first request for service and the completion of the last transfer.
11. Disadvantage with simple batch systems is that the computer still needs to
read the deck of cards before it can begin to execute the job.
12. Printer is considered as typical SPOOLed device. For this, a special process
known as daemon is created. A special directory is also created to contain the
process. This directory is known as SPOOLing directory.
13. A device driver interface is designed to make a link between design issues
and techniques.
14. The disk head scheduling works on various mechanism, such as FCFS, SSTF,
etc.
Self-Instructional
190 Material
Device Management
5.10 QUESTIONS AND EXERCISES
Short-Answer Questions
1. Give the classification of input devices.
2. What is the function of hand-held scanners? NOTES
3. What is the advantage of flatbed plotters?
4. What is the use of the external hard disk device?
5. Mention the steps for troubleshooting.
6. What are the components of access time?
7. What is the advantage of SPOOLing batch system?
8. What are the functions of device control commands?
9. How are files and devices unified in an I/O system?
Long-Answer Questions
1. Explain the various special function keys.
2. Write short notes on:
(i) Touch lads
(ii) Scanning devices
(iii) Printing devices
3. Describe the history and functioning of USB.
4. What is disk scheduling? Explain its various types. What role does disk access
time plays in disk scheduling?
5. What is virtual memory system? How can a system be interface with virtual
memory?
6. Explain the functions various devices used in intelligent multimedia system.
7. Briefly explain the purpose of data SPOOLing.
8. Explain the different interfaces of a device driver along with its functions.
9. Explain the various steps required in the device driver for performing various
algorithms.

5.11 FURTHER READING


Silberschatz, Abraham, Peter Galvin and Greg Gagne. Operating System Concepts.
John Wiley & Sons, 2004.
Mano, M. Morris. Computer System Architecture. New Jersey: Prentice Hall Inc.,
1993.
Louise I. Shelly 2020 Dark Commerce

5.12 LEARNING OUTCOMES


 Understand the various I/O devices
 The functioning of dedicated and shared devices
 Learn about disk management as well as scheduling
 Know the application of virtual devices
 SPOOLing and the various device drivers

Self-Instructional
Material 191

You might also like