You are on page 1of 163

WACHEMO UNIVERSITY

COLLEGE OF ENGINEERING AND TECHNOLOGY


SCHOOL OF COMPUTING AND INFORMATICS
DEPARTMENT OF INFORMATION TECHNOLOGY

OPERATING SYSTEMS COURSE MODULE


COURSE CODE: ITEC2022

PREPARED BY

1. Redwan Aman (MSc in Information Technology)


2. Esubalew Ashebir (MSc in Computer Networking)

January, 2022
WCU, Hossena, Ethiopia
Table of Content
List of Figures .............................................................................................................................................. IV
List of Tables ............................................................................................................................................... IV
Preface ........................................................................................................................................................ VII
Course Description..................................................................................................................................... VIII
Course Objective........................................................................................................................................ VIII
Chapter one ................................................................................................................................................... 1
1. History and Overview ........................................................................................................................... 1
1.1 Computer system components ............................................................................................................ 1
1.2 View of operating system with components ....................................................................................... 2
1.3 Operating System Services ................................................................................................................. 4
1.4. Types and structure of operating system............................................................................................ 5
1.4.1. Types of operating systems ......................................................................................................... 5
1.4.2 Operating system structures ......................................................................................................... 5
1.5 Device Management in Operating System.......................................................................................... 8
1.6. Security Management in Operating System....................................................................................... 9
1.7. What is Memory Management Unit in operating system?................................................................. 9
1.8 Interruption in operating system ....................................................................................................... 12
1.9 Concurrency and its importance ....................................................................................................... 12
1.10 The purpose and role of OS in computer engineering .................................................................... 13
2. Design Principles .................................................................................................................................... 15
2.1 Functionality of a typical operating system ...................................................................................... 15
2.2 Mechanisms to support client-server models and hand-held devices ............................................... 15
2.3. Design issues (efficiency, robustness, flexibility, portability, security, compatibility) ................... 18
2.4. Influences of security, networking, multimedia, windows .............................................................. 21
2.5 OS Structuring methods (monolithic, layered, modular, micro-kernel models) ............................... 24
2.5.1 Simple Structure......................................................................................................................... 24
2.5.2 Monolithic Approach ................................................................................................................. 24
2.5.3 Layered Approach ...................................................................................................................... 25
2.5.4 Microkernels .............................................................................................................................. 26
2.6 Abstractions, processes, and resources ............................................................................................. 29
2.7 Application program interfaces (APIs) specific to operating systems .............................................. 32
2.5 User mode and kernel mode.............................................................................................................. 33

I
2.6 Interrupts methods and implementations .......................................................................................... 35
Chapter Three.............................................................................................................................................. 39
3. Concurrency ........................................................................................................................................... 39
3.1. Process States and state diagrams .................................................................................................... 39
3.2 Structures (ready list, process control blocks, and so forth) ............................................................. 43
3.3 Dispatching and context switching ................................................................................................... 45
3.4 The role of interrupts ........................................................................................................................ 47
3.5 Concurrent execution: advantages and disadvantages ...................................................................... 48
3.6 The mutual exclusion problem and some solutions .......................................................................... 50
3.7 Deadlock: causes, conditions, prevention ................................................................................... 51
3.8 Models and mechanisms (semaphores, monitors, condition variables, rendezvous) ........................ 53
3.9. Producer-consumer problems and synchronization ......................................................................... 53
3.9.1 The Producer-Consumer Problem .............................................................................................. 53
3.9.2 Synchronization........................................................................................................................ 57
3.10. Multiprocessor issues (spin-locks, reentrancy) .............................................................................. 57
Chapter Four ............................................................................................................................................... 59
Scheduling and dispatch ............................................................................................................................. 59
4.1. Preemptive and non-preemptive scheduling .................................................................................... 59
4.2. Schedulers and policies .................................................................................................................... 62
4.3. Processes and threads ....................................................................................................................... 64
4.4 SCHEDULING ................................................................................................................................. 68
4.4.1 INTRODUCTION TO SCHEDULING ..................................................................................... 68
WHEN TO SCHEDULE ............................................................................................................................ 74
4.5 Scheduling Algorithm ....................................................................................................................... 78
4.5.1 FIRST-COME FIRST-SERVED ............................................................................................... 79
4.5.2 SHORTEST JOB FIRST ........................................................................................................... 81
4.5.3 SHORTEST REMAINING TIME NEXT ................................................................................. 83
4.6.4 ROUND-ROBIN SCHEDULING ............................................................................................. 84
4.5.5 PRIORITY SCHEDULING ....................................................................................................... 86
Chapter Five ................................................................................................................................................ 89
5. Memory Management ......................................................................................................................... 89
5.1. Review of physical memory and memory ....................................................................................... 89
5.2 Management hardware ...................................................................................................................... 90

II
5.3 Overlays, swapping, and partitions ................................................................................................... 90
5.4 Paging and segmentation .................................................................................................................. 93
5.5 Placement and Replacement policies ................................................................................................ 95
5.6 Working sets and thrashing ............................................................................................................... 96
5.7. Caching ............................................................................................................................................ 98
Chapter Six................................................................................................................................................ 100
6. Device Management ............................................................................................................................. 100
6.1 Characteristics of serial and parallel devices .................................................................................. 100
6.2 Buffering strategies ......................................................................................................................... 102
6.3 Direct memory access ..................................................................................................................... 105
6.4 Recovery from failures ................................................................................................................... 107
Chapter Seven ........................................................................................................................................... 110
7. Security and protection ......................................................................................................................... 111
7.1. Overview of system security .......................................................................................................... 111
7.2 Policy/mechanism separation.......................................................................................................... 113
7.3. Security methods and devices ........................................................................................................ 114
7.4 Protection, access, and authentication............................................................................................. 119
7.5. Models of protection ...................................................................................................................... 120
7.6. Memory protection......................................................................................................................... 121
7.7. Encryption ...................................................................................................................................... 121
7.8. Recovery Management .................................................................................................................. 121
Chapter Eight ............................................................................................................................................ 122
8. File systems........................................................................................................................................... 123
8.1 Files: data, metadata, operations, organization, buffering, sequential, non sequential ................... 123
8.2 Directories: contents and structure .................................................................................................. 124
8.3 File systems: partitioning, mount/unmount, and virtual file systems ............................................. 128
8.4 Standard implementation techniques .............................................................................................. 133
8.5 Memory-mapped files ..................................................................................................................... 140
8.6 Special Purpose File System ........................................................................................................... 142
8.7 Naming, searching, access, backups ............................................................................................... 142
Reference .................................................................................................................................................. 154

III
List of Figures

Figure 1: Conceptual view of a computer system ......................................................................................... 1


Figure 2: View of operating system with components.................................................................................. 3
Figure 3: memory management .................................................................................................................. 10
Figure 4: Operating system Device............................................................................................................. 11
Figure 5 : System software ......................................................................................................................... 15
Figure 6: client server model ...................................................................................................................... 16
Figure 7: Microsoft Word Compatibility Mode .......................................................................................... 21
Figure 8: Simple Structure .......................................................................................................................... 24
Figure 9: A monolithic kernel, such as Linux and other Unix systems ...................................................... 25
Figure 10: Layered ...................................................................................................................................... 26
Figure 11: A Microkernel architecture........................................................................................................ 27
Figure 12: Abstraction ................................................................................................................................ 30
Figure 13: User mode and kernel mode ...................................................................................................... 34
Figure 14: Interrupt ..................................................................................................................................... 35
Figure 15: State Diagram ............................................................................................................................ 41
Figure 16: Context Switching ..................................................................................................................... 46
Figure 17: Mutual exclusion problem statement and solution .................................................................... 51
Figure 18: Deadlock modeling (resource allocation) .................................................................................. 52
Figure 19: Scheduler ................................................................................................................................... 70
Figure 20: Round-robin scheduling. (a) The list of runnable processes. (b) The list of runnable processes
after B uses up its quantum. ........................................................................................................................ 84
Figure 21: Swapping ................................................................................................................................... 92
Figure 22: Paging ........................................................................................................................................ 94
Figure 23: Thrashing ................................................................................................................................... 97
Figure 24: Serial Transmission ................................................................................................................. 100
Figure 25: Parallel Transmission .............................................................................................................. 101
Figure 26: Single buffer ............................................................................................................................ 104
Figure 27: Double buffer .......................................................................................................................... 105
Figure 28: Circular buffer ......................................................................................................................... 105
Figure 29: Split-Brain Failures ................................................................................................................. 109
Figure 30 : Single-level directory ............................................................................................................. 125

IV
Figure 31: Two-level directory structure .................................................................................................. 126
Figure 32: Tree-structured directory structure .......................................................................................... 127
Figure 33: Disk partitioning ...................................................................................................................... 129
Figure 34: Sample root (/) File System ..................................................................................................... 130
Figure 36: Virtual File System .................................................................................................................. 132
Figure 37: File-System Layout ................................................................................................................. 134
Figure 38: Contiguous allocation of disk space ........................................................................................ 136
Figure 39: Linked Allocation .................................................................................................................... 137
Figure 40: Linked-List Allocation ............................................................................................................ 138
Figure 41: Linked allocation of disk space ............................................................................................... 138
Figure 42: Indexed allocation of disk space.............................................................................................. 139
Figure 43: File-allocation table ................................................................................................................. 140
Figure 44: multiple and overlapped views to a memory-mapped file....................................................... 141
Figure 45:Sequential file Access............................................................................................................... 143
Figure 46: Full backup .............................................................................................................................. 147
Figure 47: Differential backup .................................................................................................................. 148
Figure 48: Incremental backup ................................................................................................................. 149
Figure 49: Modern backup ........................................................................................................................ 151
Figure 50:Synthetic Full backup ............................................................................................................... 152

V
List of Tables
Table 1: Comparison of dispatcher and scheduler ........................................................................ 47
Table 2: FCFS Scheduling Policy ................................................................................................. 63
Table 3: Difference between Process and Thread......................................................................... 66
Table 4: Processes vs. Threads ..................................................................................................... 67
Table 5: Comparison between scheduler ...................................................................................... 71

VI
Preface
Operating System (or shortly OS) primarily provides services for running applications on a
computer system. Operating systems are an essential part of any computer system. The primary
need for the OS arises from the fact that user needs to be provided with services and OS ought to
facilitate the provisioning of these services. Similarly, a course on operating systems is an
essential part of any computer science education. This field is undergoing rapid change, as
computers are now prevalent in virtually every ground of day-to-day life from embedded devices
in automobiles through the most sophisticated planning tools for governments and multinational
firms. Yet the fundamental concepts remain fairly clear, and it is on these that we base this
module. As prerequisites, we assume that the reader is familiar with basic data structures,
computer organization, and a high-level language, such as C++ or Java. The hardware topics
required for an understanding of operating systems are covered. We also include an overview of
the fundamental data structures that are prevalent in most operating systems.
Concepts are presented using intuitive descriptions. Important theoretical results are covered.
The notes at the end of each chapter contain pointers to presented as well as references to recent
material for further reading.
The fundamental concepts and algorithms covered in the module are often based on those used in
open-source operating systems. Our aim is to present these concepts and algorithms in a general
setting that is not tied to one particular operating system. However, we present a large number of
examples that pertain to the most popular and the most innovative operating systems, including
Linux, Microsoft Windows, Apple Mac OS X, and Solaris. We also include examples of both
Android and iOS, currently the two dominant mobile operating systems. The organization of the
module reflects our many years of teaching courses on operating systems, as well as curriculum
guidelines published by the University curriculum.

VII
Course Description
The course introduces students to basics of operating system design principles and components,
and their functions. It will also discuss memory management, processor management, process
management and deadlocks, concurrency control, scheduling and dispatching, device
management, file systems, file management, security and protection, and system performance
evaluation. In addition, students will be introduced with different operating systems, and they
will see their similarities and differences.

Course Objective
At the end of this module students should be able to:

• To understand the purpose of modern operating systems.

• To understand how operating systems have evolved over time from primitive batch systems
to sophisticated multiuser systems.

• To understand the tradeoffs inherent in operating system design.

• To understand the functions of a contemporary operating system with respect to convenience,


efficiency, and the ability to evolve.

• To gain a preliminary understanding of networked, client-server, distributed operating


systems and how they differ from single user operating systems.

• To understand potential threats to operating systems and the security features designed to
guard against them.

VIII
Chapter one
1. History and Overview
Every general-purpose computer consists of the hardware, operating system, system programs
and application programs. The hardware consists of memory, CPU, ALU, I/O devices,
peripherals devices and storage devices. System programs consist of compilers, loaders, editors
OS etc. The application program consists of business programs. All these components make a
complex system and as a result operating system is the one responsible to manage all these
devices and provide user programs with a simpler interface to the hardware.
Every computer must have the operating system to run other programs and so that it is the most
important program that runs on the computer. Operating system controls and coordinates the use
of the hardware among the various system programs and application program for various users.
It simply provides an environment within which other program can do useful work.

1.1 Computer system components

Users

Editor, Loader, Compiler MS-Word, VB, Games

Operating system

Computer Hardware

Figure 1: Conceptual view of a computer system

1
1. Computer Hardware: provides basic computing resources (CPU, memory, I/O devices).
2. System and Applications programs: programs that address particular needs of the user and
define the ways in which the system resources are used to solve the computing problems of
the users (compilers, database systems, video games, business programs).
3. Users: people, machines, other computers
− From an OS point of view, the user is not trusted.
− Users must request resources through the OS; e.g., reading from and writing onto disks is
handled by the OS.
4. Operating system – controls and coordinates the use of the hardware among the various
application programs for the various users.
Definition: "Operating system" is a hard term to define and has no universally accepted
definition since it is vague in what should be and what should not be part of it.

- Operating system is a set of special programs that run on a computer system that allow it to
work properly. It performs basic tasks such as recognizing input from the keyboard, keeping
track of files, and directories on the disk, sending output to the display screen and controlling
peripheral devices.
- Operating system is designed to perform two basic functions:
• It controls the allocation and use of computing system’s resources among the various users
and tasks.
• It provides an interface between the computer hardware and the programmer that simplifies
and makes feasible for coding, creation, debugging of application programs.
Another Definition: OS is software that runs in supervisory mode. It is protected from the user
tampering (play falsely in secretly) by the hardware.

1.2 View of operating system with components

2
Figure 2: View of operating system with components

- An operating system is lower-level software that user programs run on. It is built directly on
the hardware and provides an interface between the hardware and the user program. It shares
characteristics with both software and hardware.
- We can view operating system as:
Resource manager; Manages and allocates hardware and software resources, OS keeps track
of the status of each resource and decides who gets a resource, for how long and when OS
makes sure that different programs and users running at the same time do not interfere with
each other. It is also responsible for security, ensuring that unauthorized users do not access
the system.
- Resource management also includes multiplexing (sharing resources) /multiplex: Combine
several signals into a single signal/ in two ways:
o Time multiplexing: different programs or users take turns to use a resource; e.g. CPU
use by multiple processes, sharing the printer
o Space multiplexing: different programs or users get part of resource; e.g., memory,
disks.
Maintains fairness and efficiency
- Control program that prevents both improper use of the resources by programs and access
conflicts
- Extended machine that hides the messy details which must be performed or presents a
virtual machine to the user that is easier to use. It means an operating system transforms the
physical world of devices, instructions, memory, and time into virtual world that is the result
of abstractions built by the operating system.

3
1.3 Operating System Services
- An operating system provides an environment for the execution of programs. It provides
certain services to programs and to the users of those programs. The specific services
provided, of course, differ from one operating system to another, but we can identify
common classes. These operating system services are provided for the convenience of the
programmer, to make the programming task easier.
- Common classes of services
− Program execution: The operating system must be able to load a program into memory
and to run that program.
− I/O operations: A running program may require I/O, which may involve a file or an I/O
device. For efficiency and protection, users usually cannot control I/O devices directly.
Therefore, the operating system must provide a means to do I/O.
− File-system manipulation: to create, read, write and delete files and directories; the
operating system gives permission to programs.
− Communications: There are many circumstances in which one process needs to exchange
information with another process. Such communication may occur between processes that
are executing on the same computer or between processes that are executing on different
computer systems tied together by a computer network. These communications may be
implemented via shared memory or through message passing, in which packets of
information are moved between processes by the operating system.
− Error detection: Errors may occur in the CPU, memory, in I/O devices (such as a parity
error on tape, a connection failure on a network, or lack of paper in the printer), and in the
user program (such as an arithmetic overflow, an attempt to access an illegal memory
location, or a too-great use of CPU time). For each type of error, the operating system
should take the appropriate action to ensure correct and consistent computing.
− Resource allocation: when there are multiple users or multiple jobs running at the same
time, resources must be allocated to each of them.
− Accounting: to keep track of which users use how much and what kinds of computer
resources for accumulating usage statistics.
− Protection: of information, one process not to interfere with another or the OS when a
program requires I/O, memory, etc.

4
− System calls: modern processors provide instructions that can be used as system calls that
serve as an interface between a process and OS. A system call instruction is an instruction
that generates interrupt which cause the operating system to gain control of the process.
1.4. Types and structure of operating system
1.4.1. Types of operating systems
There are different types of operating system because of the architectural difference between
computers

− Batch systems (early ones): operators batch jobs with similar needs together and run on a
computer as group. The CPU is often idle because of the speed of I/O devices.
− Multi programmed systems: when two or more programs are in memory sharing the
processor. It increases CPU utilization/The act of using/ by organizing jobs so that it always
has one to execute.
− Timesharing (multi-tasking): supports interactive users by allowing many users to share
the computer simultaneously. In time sharing systems each user is given a time slice for
executing his job until the time slice ends.
− Multiprocessor systems: Have more than one processor in close communication. They
share the computer bus, system clock and I/O devices and sometimes memory. It is possible
for two processes run in parallel.
− Distributed systems: Depend on networking for their operation and runs on and controls
the resources of multiple machines. It provides resource sharing across the boundaries of
single computer systems. Distributed operating system looks to users like a single machine
operating systems that owns the whole network and makes it look like a virtual
uniprocessor.
− Real time systems: Were originally used to control autonomous/Existing as an independent
entity/ system such as satellites, robots and communication systems. It is one that must
react to input and responds them quickly. It also has well defined, fixed time constraint.
1.4.2 Operating system structures
Modern operating systems are large and complex that Consists of different components
interconnected and melded into a kernel. For designing a system, the following three different
types of system structures are used.

5
1. Simple structure
2. Layered structure
3. Microkernel
1. Simple Structure: Frequently, such operating systems started as small, simple, and limited
systems and then grew beyond their original scope. MS-DOS is an example of such a system.
It was originally designed and implemented by a few people who had no idea that it would
become so popular.
2. Layered structure: Were developed in which functions are organized hierarchically and
interaction takes place only between adjacent layers. Most or all of the layers operate in
kernel mode. The bottom layer is the hardware.
3. Microkernel: Is a small operating system core that provides the foundation for modular
extensions. The main function is to provide a communication facility between the client
program and the various services that are also running on the user space. Microkernel
architecture assigns only a few essential functions to the kernel, including the address space,
IPC and basic scheduling.
Discussion Questions
1. Why do we study operating system?
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
__________________________________________________________________
2. Indicate some reasons for studying operating systems
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________

6
3. What are the main resources of an operating system?
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________

4. Discuss About History of Operating system


___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
5. Discuss about the listed different OS below
✓ Mac OS X, Time Machine.
✓ Unix, The Shell Terminal.
✓ Ubuntu, Simplified Linux Setup.
✓ BeOS, 64-Bit Journaling File System.
✓ IRIX, SGI Dogfight.
✓ NeXTSTEP, Right-Click Context Menu.
✓ MS-DOS, BASIC.
✓ Windows 3.0, Alt-Tab Task Switching.

7
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

1.5 Device Management in Operating System


Device Management is another important function of the operating system. Device management is
responsible for managing all the hardware devices of the computer system. It may also include the
management of the storage device as well as the management of all the input and output devices of the
computer system. It is the responsibility of the operating system to keep track of the status of all the
devices in the computer system. The status of any computing devices, internal or external may be either
free or busy. If a device requested by a process is free at a specific instant of time, the operating system
allocates it to the process.
An operating system manages the devices in a computer system with the help of device controllers and
device drivers. Each device in the computer system is equipped with the help of device controller. For
example, the various devices controllers in a computer system may be disk controller, printer controller,
tape-drive controller and memory controller. All these devices’ controllers are connected with each other
through a system bus. The device controllers are actually the hardware components that contains some
buffers registers to store the data temporarily. The transfer of data between a running process and the
various devices of the computer system is accomplished only through these devices controllers.

8
Some important points of device management
1. An operating system communicates with the devices controllers with the help of device
drivers while allocating the device to the various processes running on the computer
system.
2. Device drivers are the software programs that are used by an operating system to control
the functioning of various devices in a uniform manner.
3. The device drivers may also be regarded as the system software programs acting as an
intermediary between the processes and the devices controllers.
4. The device controller used in the device management operation usually includes three
different registers command, status, and data.

5. The other major responsibility of the device management function is to implement the
Application Programming Interface (API).
1.6. Security Management in Operating System
The security management function of an operating system helps in implementing mechanisms that secure
and protect the computer system internally as well as externally. Therefore an operating system is
responsible for securing the system at two different levels which are internal security and external
security.
1) Internal security
Internal security refers to the protection of activities of one process from the activities of another process.
The term internal security may also be regarded as system protection. The internal security of the
computer system also ensures the reliability of the computer system. There may be a number of processes
running in the computer systems use the concept of least privilege to implement internal security.
2) External security
External security refers to the implementation of a mechanism for securing the data and programs stored
in the computer system as well as the various resources of the computer system against unauthorized
access. The term external security may also be regarded as system security. External security is
particularly required when a computer system is either on a network or connected to the internet.
1.7. What is Memory Management Unit in operating system?
Memory management is the process of managing the computer memory which consist of
primary memory or secondary memory. In this, we allocate the memory portions to programs
and software after freeing the space of the computer memory. Basically, memory

9
management is of critical importance for operating system because the multi-tasking can take
place in the system which switches the memory space from one process to another. Moreover,
the concept of the virtual memory is used in the system according to which programs from main
memory are loaded to the secondary memory when the space is not large enough to hold the
programs.
The Disk swapping is used in which virtual memory separates the memory addresses using the
physical addresses. The management of the virtual memory is carried out in computer system
which will enhance the performance of the system by collecting the garbage database which is
meant for allocation and deallocation of resources. As this garbage collection table is

implemented in the programming structures that uses the region-based management for the
objects.

Figure 3: memory management

10
Brainstorming

1. What you understand from the figure below?

Figure 4: Operating system Device

______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

11
2. Indicate some important topic areas such as function and design, concurrency,
scheduling, dispatch, memory management, device management, file systems, security,
and protection
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________

1.8 Interruption in operating system


An interrupt is a signal from a device attached to a computer or from a program within the
computer that requires the operating system to stop and figure out what to do next. After the
interrupt signal is sensed, the computer either resumes running the current program or begins
running another program
1.9 Concurrency and its importance
Concurrency is the execution of the multiple instruction sequences at the same time. It happens
in the operating system when there are several process threads running in parallel. It helps in
techniques like coordinating execution of processes, memory allocation and execution
scheduling for maximizing throughput.

12
1.10 The purpose and role of OS in computer engineering
Operating system (OS), program that manages a computer's resources, especially the allocation
of those resources among other programs. Typical resources include the central processing unit
(CPU), computer memory, file storage, input/output (I/O) devices, and network connections. The
purpose of operating systems is to manage computer memory, processes and the operation of all
hardware and software. An operating system is the most important software on a computer as it
enables the computer hardware to communicate effectively with all other computer software.
1. Program Execution: The Operating System is responsible for execution of all types of
programs whether it be user programs or system programs. The Operating System
utilizes various resources available for the efficient running of all types of
functionalities.
2. Handling Input/Output Operations: The Operating System is responsible for handling
all sort of inputs, i.e., from keyboard, mouse, desktop, etc. The Operating System does
all interfacing in the most appropriate manner regrading all kind of Inputs and Outputs.
For example, there is difference in nature of all types of peripheral devices such as
mouse or keyboard, then Operating System is responsible for handling data between
them.
3. Manipulation of File System: The Operating System is responsible for making of
decisions regarding the storage of all types of data or files, i.e., floppy disk/hard
disk/pen drive, etc. The Operating System decides as how the data should be
manipulated and stored.
4. Error Detection and Handling: The Operating System is responsible for detection of
any types of error or bugs that can occur while any task. The well secured OS
sometimes also acts as countermeasure for preventing any sort of breach to the
Computer System from any external source and probably handling them.
5. Resource Allocation: The Operating System ensures the proper use of all the resources
available by deciding which resource to be used by whom for how much time. All the
decisions are taken by the Operating System.

13
6. Accounting: The Operating System tracks an account of all the functionalities taking
place in the computer system at a time. All the details such as the types of errors
occurred are recorded by the Operating System.
7. Information and Resource Protection: The Operating System is responsible for using
all the information and resources available on the machine in the most protected way.
The Operating System must foil an attempt from any external resource to hamper any
sort of data or information.
Summery Questions
1.

14
Chapter Two
2. Design Principles
2.1 Functionality of a typical operating system
An operating system has three main functions: (1) manage the computer's resources, such as the
central processing unit, memory, disk drives, and printers, (2) establish a user interface, and (3)
execute and provide services for applications software. Thus, you both establish a user interface
and execute software. In any computer, the operating system:
 Controls the backing store and peripherals such as scanners and printers.
 Deals with the transfer of programs in and out of memory.
 Organizes the use of memory between programs.
 Organizes processing time between programs and users.
 Maintains security and access rights of users.
How The Operating System Works
Figure 5 : System software

2.2 Mechanisms to support client-server models and hand-held devices


in the client-server architecture, when the client computer sends a request for data to the server
through the internet, the server accepts the requested process and deliver the data packets
requested back to the client. Clients do not share any of their resources.

15
Figure 6: client server model
Discussion Questions
1. What is the mechanism of client server model?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

2. How does HTTP support the client server model?


______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

16
3. What are the types of client-server models?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

2.2.1 What Does Handheld Mean?


A handheld is any portable device that can be carried and held in one's palm. A handheld can be
any computing or electronic device that is compact and portable enough to be held and used in
one or both hands. A handheld may contain cellular communication, but this category can also
include other computing devices. A handheld is primarily designed to provide a suite of
computing, communication and informational tools in a device about the size of standard palm.
Typically, handheld devices are not as powerful as a computer, but modern handhelds
increasingly include powerful dual-core processors, RAM, SD storage capacity, an operating
system, and native and add-on applications. They are often powered by a dry cell lithium or
similar battery. Moreover, these types of devices increasingly use a touch screen interface.
Personal digital assistants (PDA), tablet PCs and portable media players are all considered
handheld devices.
A mobile device (or handheld computer) is a computer small enough to hold and operate in the
hand. Typically, any handheld computer device will have an LCD.

1. What are the features of a smartphone?


______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

17
2. Which type of screen is there in today's handheld device?

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
______________________________

3. What is the use of handheld devices?


___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

2.3. Design issues (efficiency, robustness, flexibility, portability, security, compatibility)


Efficiency: An OS allows the computer system resources to be used efficiently. Ability to
Evolve: An OS should be constructed in such a way as to permit the effective development,
testing, and introduction of new system functions at the same time without interfering with
service.

18
✓ Efficiency: Most I/O devices slow compared to main memory (and the CPU)
▪ Use of multiprogramming allows for some processes to be waiting on I/O while another
process executes
▪ Often, I/O still cannot keep up with processor speed
▪ Swapping may use to bring in additional Ready processes; More I/O operations
✓ Optimize I/O efficiency especially Disk & Network I/O
✓ The quest for generality/uniformity:
o Ideally, handle all I/O devices in the same way; Both in the OS and in user
applications
o Problem:
▪ Diversity of I/O devices
▪ Especially, different access methods (random access versus stream based) as well as
vastly different data rates.
▪ Generality often compromises efficiency!
o Hide most of the details of device I/O in lower-level routines so that processes and
upper levels see devices in general terms such as read, write, open, close, lock, unlock
Robustness
In computer science, robustness is the ability of a computer system to cope with errors during
execution and cope with erroneous input. Robustness can encompass many areas of computer
science, such as robust programming, robust machine learning, and Robust Security Network.
Formal techniques, such as fuzz testing, are essential to showing robustness since this type of
testing involves invalid or unexpected inputs. Alternatively, fault injection can be used to test
robustness. Various commercial products perform robustness testing of software analysis.
A distributed system may suffer from various types of hardware failure. The failure of a link, the
failure of a site, and the loss of a message are the most common types. To ensure that the system
is robust, we must detect any of these failures, reconfigure the system so that computation can
continue, and recover when a site or a link is repaired.
In general, building robust systems that encompass every point of possible failure is difficult
because of the vast quantity of possible inputs and input combinations. Since all inputs and input
combinations would require too much time to test, developers cannot run through all cases
exhaustively. Instead, the developer will try to generalize such cases. For example, imagine

19
inputting some integer values. Some selected inputs might consist of a negative number, zero,
and a positive number. When using these numbers to test software in this way, the developer
generalizes the set of all reals into three numbers. This is a more efficient and manageable
method, but more prone to failure. Generalizing test cases is an example of just one technique to
deal with failure specifically, failure due to invalid user input. Systems generally may also fail
due to other reasons as well, such as disconnecting from a network.
Regardless, complex systems should still handle any errors encountered gracefully. There are
many examples of such successful systems. Some of the most robust systems are evolvable and
can be easily adapted to new situations.
Portability
Portability is the ability of an application to run properly in a different platform to the one it was
designed for, with little or no modification.
Portability in high-level computer programming is the usability of the same software in different
environments. When software with the same functionality is produced for several computing
platforms, portability is the key issue for development cost reduction.
Compatibility
Compatibility is the capacity for two systems to work together without having to be altered to do
so. Compatible software applications use the same data formats. For example, if word processor
applications are compatible, the user should be able to open their document files in either
product.
Compatibility issues come up when users are using the same type of software for a task, such as
word processors, that cannot communicate with each other. This could be due to a difference in
their versions or because they are made by different companies.
The huge variety of application software available and all the versions of the same software
mean there are bound to be compatibility issues, even when people are using the same kind of
software. Compatibility issues come up when users are using the same type of software for a
task, such as word processors, that cannot communicate with each other. This could be due to a
difference in their versions or because they are made by different companies.
Compatibility issues can be small, for example certain features not working properly in older
versions of the same software, but they can also be problematic, such as when a newer version of
the software cannot open a document created in an older version.

20
In Microsoft Word for example, documents created in Word 2016 or 2013 can be opened in
Word 2010 or 2007, but some of the newer features (such as collapsed headings or embedded
videos) will not work in the older versions. If someone using Word 2016 opens a document
created in Word 2010, the document will open in Compatibility Mode. Microsoft Office does
this to make sure that documents created in older versions still work properly.

Figure 7: Microsoft Word Compatibility Mode

The feature in figure 7 is an example of something called backwards compatibility, which is the
ability of newer software to interact with files (or programs or systems) made with older versions
of that software. It is usually built into the software and is a way to avoid compatibility issues.
Another way to avoid this is to update your software.
Flexibility
Flexible operating systems are taken to be those whose designs have been motivated to some
degree by the desire to allow the system to be tailored, either statically or dynamically, to the
requirements of specific applications or application domains.
2.4. Influences of security, networking, multimedia, windows
An operating system (OS) is basically a collection of software that manages computer hardware
resources and provides common services for computer programs. Operating system is a crucial
component of the system software in a computer system.
Networking
Network Operating System is one of the important types of operating system. Network Operating
System runs on a server and gives the server the capability to manage data, users, groups,
security, applications, and other networking functions. The basic purpose of the network
operating system is to allow shared file and printer access among multiple computers in a
network, typically a local area network (LAN), a private network or to other networks. Some
examples of network operating systems include Microsoft Windows Server 2003, Microsoft
Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD.
Advantages

21
• Centralized servers are highly stable.
• Security is server managed.
• Upgradation of new technologies and hardware can be easily integrated into the system.
• It is possible to remote access to servers from different locations and types of systems.
Disadvantages
• High cost of buying and running a server.
• Dependency on a central location for most operations.
• Regular maintenance and updates are required.
Security
Operating systems security plays a primitive role in protecting memory, files, user authentication
and data access protection. Consistent protection means that the system meets standard security
requirements and have the required functionality to enforce security practices. For every
computer system and software design, it is imperative that it should address all security concerns
and implement required safeguards to enforce security policies. At the same time, it is important
to keep a balance since rigorous security measures can not only increase costs but also limit the
user-friendliness, usefulness and smooth performance of the system. Hence, system designers
have to ensure effective performance without compromising on security. A computer’s operating
system must concentrate on delivering a functionally complete and flexible set of security
mechanism for security policies to be effectively enforced.
Multimedia
Multimedia Operating Systems are the operating systems that can deal with the multimedia files.
Multimedia files are different from the traditional files (e.g., texts). They need special
considerations for process management, secondary storage management, file management, and
soon. operating systems may get the task to handle different kinds of data as well which comes in
the category of multimedia. A recent trend in technology is the inclusion of multimedia data
within computer systems. Multimedia kind of data consists of continuous media in the form of
files (audio or video) data as well as conventional files to run. Continuous media data vary from
conventional data like that where continuous media files such as frames of video or images or
audio files must be delivered according to certain time restrictions.
Video on demand requires huge servers. The system has to be able to access, say, 1000 disks,
and distribute signals to the distribution network at high speed in real time. The only way for an

22
operating system to be able to do this is to reserve bandwidth, CPU, memory, etc. ahead of time.
So, the server has an admission control algorithm; it cannot accept a new request unless it can be
reasonably confident that it will be able to satisfy it.
Uncompressed movies are far too big to transmit. Thus, the system needs a compression
(encoding) algorithm and a decompression (decoding) algorithm. The former can be slow and/or
expensive, because it is only done once, but the latter has to be fast. Unlike a regular file
compression algorithm, an image compression algorithm can be lossy. This means that some
data can be lost. The standard compression algorithm for images is JPEG. An operating system
whose primary job is serving videos would differ from a traditional operating system in three
ways.
• process scheduling
• the file system
• disk scheduling
If all that the system is doing is serving videos, and if all of the videos have the same frame rate,
video resolution, etc, then process scheduling is very simple. Each video has a thread which
reads one frame at a time and sends it to the user. Round Robin is a perfect scheduling algorithm
for this.
But you need a timing mechanism to make sure that each process runs at the correct frequency.
Run a clock with 30 ticks per second. At each tick, all threads are run sequentially in the same
order, when a thread is done, it issues a suspend system call that releases the CPU. This
algorithm works perfectly as long as the number of threads is small enough. But there is a
problem. The frame sizes for MPEG differ in size, and processes come and go.
Windows
In 1985 Microsoft came out with its Windows operating system, which gave PC compatibles
some of the same capabilities as the Macintosh. Year after year, Microsoft refined and improved
Windows so that Apple, which failed to come up with a significant new advantage, lost its
edge. IBM tried to establish yet another operating system, OS/2, but lost the battle to Gates’s
company. In fact, Microsoft also had established itself as the leading provider of
application software for the Macintosh. Thus, Microsoft dominated not only the operating system
and application software business for PC-compatibles but also the application software business
for the only nonstandard system with any sizable share of the desktop computer market.

23
2.5 OS Structuring methods (monolithic, layered, modular, micro-kernel models)
2.5.1 Simple Structure
• Operating systems such as MS-DOS and the original UNIX did not have well-defined
structures.
• There was no CPU Execution Mode (user and kernel), and so errors in applications could
cause the whole system to crash.

Figure 8: Simple Structure

2.5.2 Monolithic Approach


• Functionality of the OS is invoked with simple function calls within the kernel, which is one
large program.
• Device drivers are loaded into the running kernel and become part of the kernel.

24
Figure 9: A monolithic kernel, such as Linux and other Unix systems
2.5.3 Layered Approach
This approach breaks up the operating system into different layers.
• This allows implementers to change the inner workings, and increases modularity.
• As long as the external interface of the routines don’t change, developers have more
freedom to change the inner workings of the routines.
• With the layered approach, the bottom layer is the hardware, while the highest layer is the
user interface.
✓ The main advantage is simplicity of construction and debugging.
✓ The main difficulty is defining the various layers.
✓ The main disadvantage is that the OS tends to be less efficient than other
implementations.

25
Figure 10: Layered

2.5.4 Microkernels
This structures the operating system by removing all nonessential portions of the kernel and
implementing them as system and user level programs. Generally, they provide minimal process
and memory management, and a communications facility. Communication between components
of the OS is provided by message passing.
The benefits of the microkernel are as follows:
✓ Extending the operating system becomes much easier.

✓ Any changes to the kernel tend to be fewer, since the kernel is smaller.

✓ The microkernel also provides more security and reliability.

✓ Main disadvantage is poor performance due to increased system overhead from message
passing

26
Figure 11: A Microkernel architecture

The Microsoft Windows NT Operating System. The lowest level is a monolithic kernel, but
many OS components are at a higher level, but still part of the OS.

Tip Questions

1. What is the difference between monolithic and layered structure?

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

2. How is a micro kernel structured?

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

27
3. What is modular kernel and layered approach in operating system?

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

4. Where is microkernel used?

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

5. When a computer is switched on where is the operating system loaded?

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

28
2.6 Abstractions, processes, and resources
Abstraction
The process of establishing the decomposition of a problem into simpler and more understood
primitives is basic to science and software engineering. This process has many underlying
techniques of abstraction.
An abstraction is a model. The process of transforming one abstraction into a more detailed
abstraction is called refinement. The new abstraction can be referred to as a refinement of the
original one. Abstractions and their refinements typically do not coexist in the same system
description. Precisely what is meant by a more detailed abstraction is not well defined. There
needs to be support for substitutability of concepts from one abstraction to another. Composition
occurs when two abstractions are used to define another higher abstraction. Decomposition
occurs when an abstraction is split into smaller abstractions.
Information management is one of the goals of abstraction. Complex features of one abstraction
are simplified into another abstraction. Good abstractions can be very useful while bad
abstractions can be very harmful. A good abstraction leads to reusable components.
Information hiding distinguishes between public and private information. Only the essential
information is made public while internal details are kept private. This simplifies interactions and
localizes details and their operations into well-defined units.
Abstraction, in traditional systems, naturally forms layers representing different levels of
complexity. Each layer describes a solution. These layers are then mapped onto each other. In
this way, high level abstractions are materialized by lower-level abstractions until a simple
realization can take place.

29
Figure 12: Abstraction

Abstraction can be accomplished on functions, data, and processes. In functional abstraction,


details of the algorithms to accomplish the function are not visible to the consumer of the
function. The consumer of the function needs to only know the correct calling convention and
have trust in the accuracy of the functional results.
In data abstraction, details of the data container and the data elements may not be visible to the
consumer of the data. The data container could represent a stack, a queue, a list, a tree, a graph,
or many other similar data containers. The consumer of the data container is only concerned
about correct behavior of the data container and not many of the internal details. Also, exact
details of the data elements in the data container may not be visible to the consumer of the data
element. An encrypted certificate is the ultimate example of an abstract data element. The
certificate contains data that is encrypted with a key not know to the consumer. The consumer
can use this certificate to be granted capabilities but cannot view nor modify the contents of the
certificate.
Traditionally, data abstraction and functional abstraction combine into the concept of abstract
data types (ADT). Combining an ADT with inheritance gives the essences of an object-based
paradigm.
In process abstraction, details of the threads of execution are not visible to the consumer of the
process. An example of process abstraction is the concurrency scheduler in a database system. A
database system can handle many concurrent queries. These queries are executed in a particular
order, some in parallel while some sequential, such that the resulting database cannot be

30
distinguished from a database where all the queries are done in a sequential fashion. A consumer
of a query which represents one thread of execution is only concerned about the validity of the
query and not the process used by the database scheduler to accomplish the query.
Process
In the Operating System, a Process is something that is currently under execution. So, an active
program can be called a Process. For example, when you want to search something on web then
you start a browser. This is denoted by process state. It can be ready, waiting, running, etc.
Resource
operating system (OS), program that manages a computer's resources, especially the allocation of
those resources among other programs. Typical resources include the central processing unit
(CPU), computer memory, file storage, input/output (I/O) devices, and network connections.
operating system (OS), program that manages a computer’s resources, especially the allocation
of those resources among other programs. Typical resources include the central processing
unit (CPU), computer memory, file storage, input/output (I/O) devices, and network connections.
Management tasks include scheduling resource use to avoid conflicts and interference between
programs. Unlike most programs, which complete a task and terminate, an operating system runs
indefinitely and terminates only when the computer is turned off.
Modern multiprocessing operating systems allow many processes to be active, where each
process is a “thread” of computation being used to execute a program. One form of
multiprocessing is called time-sharing, which lets many users share computer access by rapidly
switching between them. Time-sharing must guard against interference between users’ programs,
and most systems use virtual memory, in which the memory, or “address space,” used by a
program may reside in secondary memory (such as on a magnetic hard disk drive) when not in
immediate use, to be swapped back to occupy the faster main computer memory on demand.
This virtual memory both increases the address space available to a program and helps to prevent
programs from interfering with each other, but it requires careful control by the operating system
and a set of allocation tables to keep track of memory use. Perhaps the most delicate and critical
task for a modern operating system is allocation of the CPU; each process is allowed to use the
CPU for a limited time, which may be a fraction of a second, and then must give up control and
become suspended until its next turn. Switching between processes must itself use the CPU
while protecting all data of the processes.

31
The first digital computers had no operating systems. They ran one program at a time, which had
command of all system resources, and a human operator would provide any special resources
needed. The first operating systems were developed in the mid-1950s. These were small
“supervisor programs” that provided basic I/O operations (such as controlling punch card readers
and printers) and kept accounts of CPU usage for billing. Supervisor programs also
provided multiprogramming capabilities to enable several programs to run at once. This was
particularly important so that these early multimillion-dollar machines would not be idle during
slow I/O operations.
2.7 Application program interfaces (APIs) specific to operating systems
An application program interface (API) is code that allows two software programs to
communicate with each other. An API defines the correct way for a developer to request services
from an operating system (OS) or other application, and expose data within different contexts
and across multiple channels.
Operating System (OS) application programmer interfaces (APIs) are a key enabler to target
independent software and seamless upgrading from the software perspective when the
underlying hardware is changed. This is one of the significant cost reduction mechanisms
promised by the use of open systems.
There are four principal types of API commonly used in web-based applications: public, partner,
private and composite. In this context, the API "type" indicates the intended scope of use. Public
APIs an enterprise also may seek to monetize the API by imposing a per-call cost to utilize the
public API. Partner APIs.
Questions
1. What is API and types of API?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

32
2. Is API part of operating system?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
_______________________________________________________________________
3. Why use APIs instead of system calls?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
2.5 User mode and kernel mode
A processor in a computer running Windows has two different modes: user mode and kernel
mode. The processor switches between the two modes depending on what type of code is
running on the processor. Applications run in user mode, and core operating system components
run in kernel mode. While many drivers run in kernel mode, some drivers may run in user mode.
User mode
When you start a user-mode application, Windows creates a process for the application. The
process provides the application with a private virtual address space and a private handle table.
Because an application's virtual address space is private, one application cannot alter data that
belongs to another application. Each application runs in isolation, and if an application crashes,
the crash is limited to that one application. Other applications and the operating system are not
affected by the crash.
In addition to being private, the virtual address space of a user-mode application is limited. A
processor running in user mode cannot access virtual addresses that are reserved for the
operating system. Limiting the virtual address space of a user-mode application prevents the
application from altering, and possibly damaging, critical operating system data.

33
Kernel mode
All code that runs in kernel mode shares a single virtual address space. This means that a kernel-
mode driver is not isolated from other drivers and the operating system itself. If a kernel-mode
driver accidentally writes to the wrong virtual address, data that belongs to the operating system
or another driver could be compromised. If a kernel-mode driver crashes, the entire operating
system crashes. This diagram illustrates communication between user-mode and kernel-mode
components.

Figure 13: User mode and kernel mode

Necessity of Dual Mode (User Mode and Kernel Mode) in Operating System
The lack of a dual mode i.e., user mode and kernel mode in an operating system can cause
serious problems. Some of these are
• A running user program can accidentally wipe out the operating system by overwriting it
with user data.
• Multiple processes can write in the same system at the same time, with disastrous results.
These problems could have occurred in the MS-DOS operating system which had no mode bit
and so no dual mode.

34
2.6 Interrupts methods and implementations
Interrupts in operating system
Interrupts are signals sent to the CPU by external devices, normally I/O devices. They tell the
CPU to stop its current activities and execute the appropriate part of the operating system.
Software Interrupts are generated by programs when they want to request a system call to be
performed by the operating system. An interrupt occurs when the output device is idle, the ISR
gets from the FIFO and write the data to the output device.
For example if we are implementing a digital controller that executes a control algorithm 100
times a second, then we will set up the internal timer hardware to request an interrupt every 10
ms.
How are interrupts implemented?

Figure 14: Interrupt

Monolithic operating system


A monolithic kernel is an operating system architecture where the entire operating system is
working in kernel space. A set of primitives or system calls implement all operating
system services such as process management, concurrency, and memory management.

35
Monolithic kernel is a single large process running entirely in a single address space. It is a
single static binary file. The kernel can invoke functions directly. Examples of monolithic
kernel-based OSs: Unix, Linux. In microkernels, the kernel is broken down into separate
processes, known as servers.
A layered operating system is an operating system that groups related functionality together, and
separates it from the unrelated. Its architectural structure resembles a layer cake. It starts at level
0, or the hardware level and works its way up to the operator, or user.
Monolithic kernel is a single large process running entirely in a single address space. It is a
single static binary file. Examples of monolithic kernel-based OSs: Unix, Linux. In microkernels,
the kernel is broken down into separate processes, known as servers.

Is Linux monolithic or microkernel?


The example of operating system having the Monolithic kernels is UNIX, LINUX while the os
having Microkernel are QNX, L4, HURD, initially Mach (not mac os x) later it will convert into
hybrid kernel, even MINIX is not pure kernel because device driver is compiled as part of the
kernel.
kernel and OS
The operating system is the software package that communicates directly to the hardware and
our application. The kernel is the lowest level of the operating system. The kernel is the main
part of the operating system and is responsible for translating the command into something that
can be understood by the computer.
1. Is 64 bits better or 32 bits?

___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

36
2. What is the main function of BIOS?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
3. Which operating system is best Why?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
________________________

4. What are the components of operating system?


___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

37
5. What is difference between client and server?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

6. Compare and Contrast monolithic operating system and A layered operating system?
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

7. What is the difference between kernel and OS?


_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

38
Chapter Three
3. Concurrency
3.1. Process States and state diagrams
All modern computers often do several things at the same time. People used to work with
personal computers may not be fully aware of this fact, so a few examples may make the point
clearer. First consider a Web server. Requests come in from all over asking for Web pages.
When a request comes in, the server checks to see if the page needed is in the cache. If it is, it is
sent back; if it is not, a disk request is started to fetch it.
However, from the CPU's perspective, disk requests take eternity. While waiting for the disk
request to complete, many more requests may come in. If there are multiple disks present, some
or all of them may be fired off to other disks long before the first request is satisfied. Clearly
some way is needed to model and control this concurrency. Processes (and especially threads)
can help here. Now consider a user PC. When the system is booted, many processes are secretly
started, often unknown to the user. For example, a process may be started up to wait for
incoming e-mail. Another process may run on behalf of the antivirus program to check
periodically if any new virus definitions are available. In addition, explicit user processes may be
running, printing files and burning a CDROM, all while the user is surfing the Web. All this
activity has to be managed, and a multiprogramming system supporting multiple processes
comes in very handy here.
Process concepts
A question that arises in discussing operating systems involves what to call all the CPU
activities. A batch system executes jobs, whereas a time-shared system has user’s programs, or
tasks. Even on a single-user system such as Microsoft Windows, a user may be able to run
several programs at one time. In many respects, all these activities are similar, so we call all of
them processes.
 Process is a dynamic entity i.e., a program in execution.
 Processes exist in a limited span of time.
 A process has object program, data, resources and the status of the process on execution.
 A process is not a closed system; there is a communication between processes through a
shared environment

39
- A process is a program in execution. The execution of a process must progress in a sequential
fashion.
Process
- A process is defined as an entity which represents the basic unit of work to be implemented
in the system.
- Components of a process are: -
• Object Program: - Code to be executed
• Data - Data to be used for executing the program
• Resources While executing the program, it may require some resources
• Status verifies the status of the process execution. A process can run to completion only
when all requested resources have been allocated to the process. Two or more processes
could be executing the same program, each using their own data and resources
- A program by itself is not a process. It is a static entity made up of program statement while
process is a dynamic entity. Program contains the instructions to be executed by processor.
- A program takes a space at single place in main memory and continues to stay there. A
program does not perform any action by itself.
Programs vs. process
Program Process
✓ Static entity Dynamic entity
✓ Exist in a single space and continue to exist. Exist in a limited span of time.
✓ Programs contain instructions Executes instruction
There are two types of processes:
➢ Sequential Processes: Execution progresses in a sequential fashion, i.e., one after the other.
So, at any point in time, at most one process is being executed.
➢ Concurrent Processes: There are two types of concurrent processes.
• True Concurrency (Multiprocessing): Two or more processes are executed simultaneously
in a multiprocessor environment. So, supports real parallelism.
• Apparent Concurrency (Multiprogramming): Two or more processes are executed in
parallel in a uniprocessor environment.

40
State Diagram

Figure 15: State Diagram

The process, from its creation to completion, passes through various states. The minimum
number of states is five.
The names of the states are not standardized although the process may be in one of the following
states during execution.
1. New
A program which is going to be picked up by the OS into the main memory is called a new
process.
HTML Tutorial
2. Ready
Whenever a process is created, it directly enters in the ready state, in which, it waits for the CPU
to be assigned. The OS picks the new processes from the secondary memory and put all of them
in the main memory.
The processes which are ready for the execution and reside in the main memory are called ready
state processes. There can be many processes present in the ready state.

41
3. Running
One of the processes from the ready state will be chosen by the OS depending upon the
scheduling algorithm. Hence, if we have only one CPU in our system, the number of running
processes for a particular time will always be one. If we have n processors in the system then we
can have n processes running simultaneously.
4. Block or waits
From the Running state, a process can make the transition to the block or wait state depending
upon the scheduling algorithm or the intrinsic behavior of the process.
When a process waits for a certain resource to be assigned or for the input from the user then the
OS move this process to the block or wait state and assigns the CPU to the other processes.
5. Completion or termination
When a process finishes its execution, it comes in the termination state. All the context of the
process (Process Control Block) will also be deleted the process will be terminated by the
Operating system.
6. Suspend ready
A process in the ready state, which is moved to secondary memory from the main memory due to
lack of the resources (mainly primary memory) is called in the suspend ready state.
If the main memory is full and a higher priority process comes for the execution then the OS
have to make the room for the process in the main memory by throwing the lower priority
process out into the secondary memory. The suspend ready processes remain in the secondary
memory until the main memory gets available.
7. Suspend wait
Instead of removing the process from the ready queue, it's better to remove the blocked process
which is waiting for some resources in the main memory. Since it is already waiting for some
resource to get available hence it is better if it waits in the secondary memory and make room for
the higher priority process. These processes complete their execution once the main memory gets
available and their wait is finished.
Operations on the Process
1. Creation
Once the process is created, it will be ready and come into the ready queue (main memory) and
will be ready for the execution.

42
2. Scheduling
Out of the many processes present in the ready queue, the Operating system chooses one process
and start executing it. Selecting the process which is to be executed next, is known as scheduling.

3. Execution
Once the process is scheduled for the execution, the processor starts executing it. Process may
come to the blocked or wait state during the execution then in that case the processor starts
executing the other processes.
4. Deletion/killing
Once the purpose of the process gets over then the OS will kill the process. The Context of the
process (PCB) will be deleted and the process gets terminated by the Operating system.

3.2 Structures (ready list, process control blocks, and so forth)


The ready processes in the system are kept in a `queue' called the ready list. This list is sorted by
the priority of the processes; the lowest priority process appears at the head of the list and the
highest priority process is at the tail. PCBs maintain information that the OS needs to manage the
process Typically include information such as Process identification number (PID)Process state
Program counter Scheduling priority Credentials A pointer to the process’s parent process
Pointers to the process’s child processes to locate the process’s data and instructions in memory
to allocated resources.
Process table the OS maintains pointers to each process’s PCB in a system-wide or per-user
process table Allows for quick access to PCBs When a process is terminated, the OS removes the
process from the process table and frees all of the process’s resources Process table and process
control blocks

43
Implementation of Processes
 The OS maintains a table (an array of structures), called the Process Table or Process
Control Block.
 It enables an interrupted process to resume normally.
 Each process is represented in the operating system by a process control block (PCB)
also called a task control block. PCB is the data structure used by the operating system.
Operating system groups all information that needs about particular process.
 PCB contains many pieces of information associated with a specific process which is
described below.
 It is an area of memory containing all the relevant information associated with each
process.
 These may include
✓ Process state
✓ Program counter
✓ Stack pointer
✓ Value of CPU registers when the process is suspended.
✓ CPU scheduling information such as priority
✓ The area of memory used by the process (memory management information)
✓ Accounting information: amount of CPU time used, time limits, process no, etc.
✓ I/O status information: list of I/O devices such as tape derives allocated for the
process, a list of open files, etc.
✓ Pointer to the next process’s PCB
- Process control block includes CPU scheduling, I/O resource management, file management
information etc. The PCB serves as the repository for any information which can vary from
process to process. Loader/linker sets flags and registers when a process is created. If that
process gets suspended, the contents of the registers are saved on a stack and the pointer to
the particular stack frame is stored in the PCB. By this technique, the hardware state can be
restored so that the process can be scheduled to run again.
• The information is system dependent; e.g., there is an entry “parent process” in UNIX but
none in windows.
• All PCBs are linked to form a list, which is accessed by a pointer in a central table.

44
• When a process changes state from ready to running, its PCB is used by the OS to restart.
The use of PCB will be shown later in Process Scheduling.
In any multiprogramming system, the CPU switches from process to process quickly, running
each for tens or hundreds of milliseconds. While, strictly speaking, at any instant of time, the
CPU is running only one process, in the course of 1 second, it may work on several of them,
giving the illusion of parallelism.
Sometimes people speak of pseudo-parallelism in this context, to contrast it with the true
hardware parallelism of multiprocessor systems (which have two or more CPUs sharing the same
physical memory). Keeping track of multiple, parallel activities is hard for people to do.
Therefore, operating system designers over the years have evolved a conceptual model
(sequential processes) that makes parallelism easier to deal with.
THE PROCESS MODEL
In this model, all the runnable software on the computer, sometimes including the operating
system, is organized into a number of sequential processes, or just processes for short. A process
is just an instance of an executing program (program is sequence of instructions defined to
perform some task), including the current values of the program counter, registers, and variables.
Conceptually, each process has its own virtual CPU. In reality, of course, the real CPU switches
back and forth from process to process, but to understand the system, it is much easier to think
about a collection of processes running in (pseudo) parallel than to try to keep track of how the
CPU switches from program to program. This rapid switching back and forth is called
multiprogramming.
3.3 Dispatching and context switching
Performed by the OS to stop executing a running process and begin executing a previously ready
process Save the execution context of the running process to its PCB Load the ready process’s
execution context from its PCB Must be transparent to processes Require the processor to not
perform any “useful” computation OS must therefore minimize context-switching time
Performed in hardware by some architectures.
In computing, a context switch is the process of storing the state of a process or thread, so
that it can be restored and resume execution at a later point. In a multitasking context, it refers to
the process of storing the system state for one task, so that task can be paused and another task
resumed.

45
The term dispatching is associated with scheduling and means roughly selecting the next task to
run. So, in a typical task switch, for example due to a timer interrupt, the context switcher first
saves the context of the interrupted task, establishes the context to run system code and then calls
the dispatcher.

Figure 16: Context Switching

Example
There are 4 processes in the ready queue, P1, P2, P3, P4; Their arrival times are t0, t1, t2, t3
respectively. A First in First out (FIFO) scheduling algorithm is used. Because P1 arrived first,
the scheduler will decide it is the first process that should be executed, and the dispatcher will
remove P1 from the ready queue and give it to the CPU. The scheduler will then determine P2 to
be the next process that should be executed, so when the dispatcher returns to the queue for a
new process, it will take P2 and give it to the CPU. This continues in the same way for P3, and
then P4.

46
Properties DISPATCHER SCHEDULER

Dispatcher is a module that gives control of Scheduler is something which


CPU to the process selected by short term selects a process among
Definition: scheduler various processes

There are 3 types of


There are no different types in dispatcher. It is schedulers i.e., Long-term,
Types: just a code segment. Short-term, Medium-term

Working of dispatcher is dependent on Scheduler works


scheduler. Means dispatcher have to wait until independently. It works
Dependency: scheduler selects a process. immediately when needed

Scheduler works on various


Dispatcher has no specific algorithm for its algorithm such as FCFS, SJF,
Algorithm: implementation RR etc.

Time taken by scheduler is


The time taken by dispatcher is called usually negligible. Hence, we
Time Taken: dispatch latency. neglect it.

Dispatcher is also responsible for: Context


Switching, Switch to user mode, jumping to
Functions: proper location when process again restarted

Table 1: Comparison of dispatcher and scheduler

3.4 The role of interrupts


Role of Interrupts. Interrupts are signals sent to the CPU by external devices, normally I/O
devices. They tell the CPU to stop its current activities and execute the appropriate part of

47
the operating system. Hardware Interupts are generated by hardware devices to signal that they
need some attention from the OS.
There are three types of interrupts:
1. Hardware Interupts are generated by hardware devices to signal that they need some
attention from the OS. They may have just received some data (e.g., keystrokes on the
keyboard or a data on the ethernet card); or they have just completed a task which the
operating system previous requested, such as transferring data between the hard drive and
memory.
2. Software Interupts are generated by programs when they want to request a system
call to be performed by the operating system.
3. Traps are generated by the CPU itself to indicate that some error or condition occurred
for which assistance from the operating system is needed.
Interrupts are important because they give the user better control over the computer. Without
interrupts, a user may have to wait for a given application to have a higher priority over the CPU
to be ran. This ensures that the CPU will deal with the process immediately.
3.5 Concurrent execution: advantages and disadvantages
Concurrency is the execution of the multiple instruction sequences at the same time. It happens
in the operating system when there are several process threads running in parallel. The running
process threads always communicate with each other through shared memory or message
passing. Concurrency results in sharing of resources result in problems like deadlocks and
resources starvation. It helps in techniques like coordinating execution of processes, memory
allocation and execution scheduling for maximizing throughput.

Principles of Concurrency
Both interleaved and overlapped processes can be viewed as examples of concurrent processes,
they both present the same problems. The relative speed of execution cannot be predicted. It
depends on the following:
• The activities of other processes
• The way operating system handles interrupts
• The scheduling policies of the operating system

48
Problems in Concurrency
• Sharing global resources –Sharing of global resources safely is difficult. If two
processes both make use of a global variable and both perform read and write on that
variable, then the order in which various read and write are executed is critical.
• Optimal allocation of resources
It is difficult for the operating system to manage the allocation of resources optimally.
• Locating programming errors
It is very difficult to locate a programming error because reports are usually not
reproducible.
• Locking the channel
It may be inefficient for the operating system to simply lock the channel and prevents
its use by other processes.
Advantages of Concurrency:
• Running of multiple applications
It enable to run multiple applications at the same time.
• Better resource utilization –It enables that the resources that are unused by one
application can be used for other applications.
• Better average response time –Without concurrency, each application has to be run to
completion before the next one can be run.
• Better performance –It enables the better performance by the operating system. When
one application uses only the processor and another application uses only the disk
drive then the time to run both applications concurrently to completion will be shorter
than the time to run each application consecutively.
Drawbacks of Concurrency
• It is required to protect multiple applications from one another.
• It is required to coordinate multiple applications through additional mechanisms.
• Additional performance overheads and complexities in operating systems are required
for switching among applications.
• Sometimes running too many applications concurrently leads to severely degraded
performance.

49
Issues of Concurrency:
• Non-atomic –Operations that are non-atomic but interruptible by multiple processes
can cause problems.
• Race conditions –A race condition occurs of the outcome depends on which of
several processes gets to a point first.
• Blocking –Processes can block waiting for resources. A process could be blocked for
long period of time waiting for input from a terminal. If the process is required to
periodically update some data, this would be very undesirable.
• Starvation – It occurs when a process does not obtain service to progress.
• Deadlock –It occurs when two processes are blocked and hence neither can proceed
to execute.
In general Advantages of concurrency
• Reduced waiting time response time or turnaround time.
• Increased throughput or resource utilization.
• If we run only one transaction at a time than the acid property is sufficient but it is possible
that when multiple transactions are executed concurrently than database may become
inconsistent.
3.6 The mutual exclusion problem and some solutions
It must implement mutual exclusion: only one process can be in the critical section at a time. It
must be free of deadlocks: if processes are trying to enter the critical section, one of them must
eventually be able to do so successfully, provided no process stays in the critical section
permanently.
In this problem, there is a collection of asynchronous processes, each alternately executing a
critical and a noncritical section, that must be synchronized so that no two processes ever execute
their critical sections concurrently or the mutual-exclusion solution to this makes the shared
resource available only while the process is in a specific code segment called the critical section.
It controls access to the shared resource by controlling each mutual execution of that part of
its program where the resource would be used. Mutual exclusion is a property of concurrency
control, which is instituted for the purpose of preventing race conditions.

50
Figure 17: Mutual exclusion problem statement and solution

3.7 Deadlock: causes, conditions, prevention


Deadlock is a situation which involves the interaction of more than one resources and processes
with each other. When a process requests for the resource that is been held another process
which needs another resource to continue, but is been held by the first process, then it is called a
deadlock. Deadlock prevention works by preventing one of the four Coffman conditions from
occurring. Removing the mutual exclusion condition means that no process will have exclusive
access to a resource. Algorithms that avoid mutual exclusion are called non-blocking
synchronization algorithms.
The following four conditions must hold for there to be a deadlock
1. Mutual exclusion condition-each resource is assigned to exactly one process.
2. Hold and wait condition-process holding resources can request additional resources.
3. No preemption condition-previously granted resources can't be forcibly taken away; only the
process can voluntarily release resource.
4. Circular wait condition-there must be a circular chain of two or more processes. Each of
which is waiting for a resource held by the next member of the chain.
– One mechanism of attacking deadlock is by trying to negate some of the conditions-
deadlock avoidance.

51
E.g., traffic deadlock

Figure 18: Deadlock modeling (resource allocation)

Deadlock Avoidance
• Avoid deadlock by careful resource scheduling.
• Requires that the system has some additional prior information available.
• Simplest and most useful model requires that each process declare the maximum
number of resources of each type that it may need.
• The deadlock avoidance algorithm dynamically examines the resource allocation state
to ensure that there can never be a circular wait.
• Resource allocation state is defined by the number of available and allocated resources,
and the maximum demands of the process.
Deadlock Prevention
– Prevent deadlock by resource scheduling so as to negate at least one of the four
conditions
– Attacking the mutual exclusion condition
– Attacking the hold and wait condition
– Attacking the no preemption condition
– Attacking the circular wait condition

52
3.8 Models and mechanisms (semaphores, monitors, condition variables, rendezvous)

What are condition variables in OS?


Condition variables are synchronization primitives that enable threads to wait until a particular
condition occurs. Condition variables are user-mode objects that cannot be shared across
processes. Condition variables support operations that "wake one" or "wake all" waiting threads.
A rendezvous occurs when two processes synchronize and subsequently exchange messages.
Rendezvous is symmetric, in that processes that wish to communicate both use the same
primitive; and processes invoke Rendezvous with class designations, not procedure names.
Monitors are defined as the construct of programming language, which helps in controlling
shared data access. The Monitor is a module or package which encapsulates shared data
structure, procedures, and the synchronization between the concurrent procedure invocations.

Semaphores are integer variables that are used to solve the critical section problem by
using two atomic operations, wait and signal that are used for process synchronization. The wait
operation decrements the value of its argument S, if it is positive.
3.9. Producer-consumer problems and synchronization
3.9.1 The Producer-Consumer Problem
The Producer-Consumer problem is a classic problem this is used for multi-process
synchronization i.e., synchronization between more than one processes. In the producer-
consumer problem, there is one Producer that is producing something and there is one
Consumer that is consuming the products produced by the Producer.
As an example of how these primitives can be used, let us consider the producer-consumer
problem (also known as the bounded-buffer problem). Two processes share a common, fixed-

53
size buffer. One of them, the producer, puts information into the buffer, and the other one, the
consumer, takes it out. (It is also possible to generalize the problem to have m producers and n
consumers, but we will consider only the case of one producer and one consumer because this
assumption simplifies the solutions.)
Trouble arises when the producer wants to put a new item in the buffer, but it is already full. The
solution is for the producer to go to sleep, to be awakened when the consumer has removed one
or more items. Similarly, if the consumer wants to remove an item from the buffer and sees that
the buffer is empty, it goes to sleep until the producer puts something in the buffer and wakes it
up. This approach sounds simple enough, but it leads to the same kinds of race conditions we
saw earlier with the spooler directory. To keep track of the number of items in the buffer, we will
need a variable, count. If the maximum number of items the buffer can hold is N, the producer’s
code will first test to see if count is N. If it is, the producer will go to sleep; if it is not, the
producer will add an item and increment count. The consumer’s code is similar: first test count to
see if it is 0. If it is, go to sleep; if it is nonzero, remove an item and decrement the counter. Each
of the processes also tests to see if the other should be awakened, and if so, wakes it up.
To express system calls such as sleep and wakeup in C, we will show them as calls to library
routines. They are not part of the standard C library but presumably would be made available on
any system that actually had these system calls. The procedures insert item and remove item,
which are not shown, handle the bookkeeping of putting items into the buffer and taking items
out of the buffer. Now let us get back to the race condition. It can occur because access to count
is unconstrained. As a consequence, the following situation could possibly occur. The buffer is
empty and the consumer has just read count to see if it is 0.
What's the problem here?
The following are the problems that might occur in the Producer-Consumer:
The producer should produce data only when the buffer is not full. If the buffer is full, then the
producer shouldn't be allowed to put any data into the buffer.
The consumer should consume data only when the buffer is not empty. If the buffer is empty,
then the consumer shouldn't be allowed to take any data from the buffer.
The producer and consumer should not access the buffer at the same time.
What's the solution?
The above three problems can be solved with the help of semaphores

54
In the producer-consumer problem, we use three semaphore variables:
Semaphore S: This semaphore variable is used to achieve mutual exclusion between
processes. By using this variable, either Producer or Consumer will be allowed to use or access
the shared buffer at a particular time. This variable is set to 1 initially.
Semaphore E: This semaphore variable is used to define the empty space in the buffer.
Initially, it is set to the whole space of the buffer i.e., "n" because the buffer is initially empty.
Semaphore F: This semaphore variable is used to define the space that is filled by the
producer. Initially, it is set to "0" because there is no space filled by the producer initially.
By using the above three semaphore variables and by using the wait () and signal () function,
we can solve our problem (the wait () function decreases the semaphore variable by 1 and
the signal () function increases the semaphore variable by 1). So. let's see how.
The following is the pseudo-code for the producer:
void producer () {
while(T) {
produce ()
wait(E)
wait(S)
append ()
signal(S)
signal(F)
}
}
The above code can be summarized as:
while () is used to produce data, again and again, if it wishes to produce, again and again.
produce () function is called to produce data by the producer.
wait(E) will reduce the value of the semaphore variable "E" by one i.e., when the producer
produces something then there is a decrease in the value of the empty space in the buffer. If the
buffer is full i.e., the value of the semaphore variable "E" is "0", then the program will stop its
execution and no production will be done.
wait(S) is used to set the semaphore variable "S" to "0" so that no other process can enter into
the critical section.

55
append () function is used to append the newly produced data in the buffer.
signal(s) is used to set the semaphore variable "S" to "1" so that other processes can come into
the critical section now because the production is done and the append operation is also done.
signal(F) is used to increase the semaphore variable "F" by one because after adding the data
into the buffer, one space is filled in the buffer and the variable "F" must be updated.
This is how we solve the produce part of the producer-consumer problem. Now, let's see the
consumer solution. The following is the code for the consumer:
void consumer () {
while(T) {
wait(F)
wait(S)
take ()
signal(S)
signal(E)
use ()
}
}
The above code can be summarized as:
while () is used to consume data, again and again, if it wishes to consume, again and again.
wait(F) is used to decrease the semaphore variable "F" by one because if some data is
consumed by the consumer, then the variable "F" must be decreased by one.
wait(S) is used to set the semaphore variable "S" to "0" so that no other process can enter into
the critical section.
take () function is used to take the data from the buffer by the consumer.
signal(S) is used to set the semaphore variable "S" to "1" so that other processes can come into
the critical section now because the consumption is done and the take operation is also done.
signal(E) is used to increase the semaphore variable "E" by one because after taking the data
from the buffer, one space is freed from the buffer and the variable "E" must be increased.
use () is a function that is used to use the data taken from the buffer by the process to do some
operation.
So, this is how we can solve the producer-consumer problem.

56
3.9.2 Synchronization
Synchronization mechanism is intended for groups of processes rather than two-process
producer-consumer type situations. Some applications are divided into phases and have the rule
that no process may proceed into the next phase until all processes are ready to proceed to the
next phase. This behavior may be achieved by placing a barrier at the end of each phase. When a
process reaches the barrier, it is blocked until all processes have reached the barrier. This allows
groups of processes to synchronize.
3.10. Multiprocessor issues (spin-locks, reentrancy)
What is spin lock
Spinlock: when a thread is acquiring a lock, if the lock has been acquired by other threads, the
thread will wait in a loop, and then continuously judge whether the lock can be acquired
successfully. It will not exit the loop until the lock is acquired. The thread that gets the lock is
always active, but it doesn’t perform any effective task. Using this lock will cause a lot of
problems busy-waiting.
The problems of spin lock: There is one problem when using spin lock
1. If a thread holds the lock for a long time, it will cause other threads waiting for the lock to
enter the cycle waiting and consume CPU. Improper use will result in high CPU utilization.
2. The spin lock implemented by Java above is not fair, that is, it cannot satisfy the priority of the
thread with the longest waiting time to obtain the lock. Unfair locks can lead to “thread
starvation”.
Advantages of spin lock
✓ Spin lock will not make the thread state switch, always in the user state, that is, the thread is
always active; it will not make the thread into the blocking state, reduce unnecessary context
switching, and the execution speed is fast.
✓ When the lock cannot be acquired, the non spin lock will enter the blocking state and enter
the kernel state. When the lock is acquired, it needs to recover from the kernel state and need
to switch the thread context. (When the thread is blocked, it will enter the kernel (Linux)
scheduling state, which will cause the system to switch back and forth between the user state
and the kernel state, seriously affecting the performance of the lock.)

57
Reentrant spin lock and non-reentrant spin lock
A careful analysis of the code at the beginning of the article shows that it does not support
reentry. That is, when a thread has acquired the lock for the first time, it reacquires the lock again
before the lock is released, and it cannot acquire it successfully for the second time. Because
CAS is not satisfied, the second acquisition will enter the while loop waiting. If it is a reentrant
lock, the second acquisition should be successful. Moreover, even if it can be acquired
successfully for the second time, when the lock is released for the first time, the lock acquired for
the second time will also be released, which is unreasonable.
In software engineering, a spinlock is a lock which causes a thread trying to acquire it to simply
wait in a loop ("spin") while repeatedly checking if the lock is available. The longer a thread
holds a lock, the greater the risk that the thread will be interrupted by the OS scheduler while
holding the lock. In computing, a computer program or subroutine is called reentrant if multiple
invocations can safely run concurrently on multiple processors, or on a single processor system,
where a reentrant procedure can be interrupted in the middle of its execution and then safely be
called again ("re-entered") before its previous.
Discussion Questions

1. What is process and process state diagram?


2. What are the 5 states of process?
3. What is a state in state diagram?
4. What does it mean Concurrency and Deadlock?
5. Why do we use interrupts?
6. Which interrupt has highest priority?
7. What is meant by context switching?
8. What is meant by dispatching in OS?
9. What is deadlock in OS and its characteristics?
10. What is the importance of deadlock?
11. What are the methods of handling deadlock?

58
Chapter Four
Scheduling and dispatch
Scheduling is used when the scheduler wants to view all the partner schedules and place the
appointment for new tasks manually into a time slot. If your business typically queues multiple
tasks and then schedules them across the partner base at a later time, select To Be Scheduled on
each incident.
Dispatching is intended to handle scenarios where the task is assigned to a partner using the next
available time slot. If your business typically schedules one task at a time, click Dispatch on
the Incidents form or Service Orders form to create the appointment on the Dispatch
Scheduling board.
The Dispatch Scheduling form tries to identify the best available partner by matching the
duration required by the tasks with the next available partner who has the appropriate skills,
certifications and coverage area.
4.1. Preemptive and non-preemptive scheduling
What is Preemptive Scheduling?
Preemptive Scheduling is a scheduling method where the tasks are mostly assigned with their
priorities. Sometimes it is important to run a task with a higher priority before another lower
priority task, even if the lower priority task is still running. At that time, the lower priority task
holds for some time and resumes when the higher priority task finishes its execution.
What is Non- Preemptive Scheduling?
In this type of scheduling method, the CPU has been allocated to a specific process. The process
that keeps the CPU busy will release the CPU either by switching context or terminating. It is the
only method that can be used for various hardware platforms. That’s because it doesn’t need
specialized hardware (for example, a timer) like preemptive Scheduling. Non-Preemptive
Scheduling occurs when a process voluntarily enters the wait state or terminates.

59
Difference Between Preemptive and Non-Preemptive Scheduling in OS
Non-preemptive Scheduling
✓ Once the processor starts its execution, it must finish it before executing the other. It can’t
be paused in the middle.

✓ CPU utilization is less efficient compared to preemptive Scheduling.

✓ Waiting and response time of the non-preemptive Scheduling method is higher.

✓ When any process enters the state of running, the state of that process is never deleted from
the scheduler until it finishes its job.

✓ Non-preemptive Scheduling is rigid.

✓ Examples: First Come First Serve, Shortest Job First, Priority Scheduling, etc.

✓ In non-preemptive scheduling process cannot be Scheduled

✓ In this process, CPU is allocated to the process until it terminates or switches to the waiting
state.

✓ Non-preemptive Scheduling has no such overhead of switching the process from running
into the ready state.
Preemptive Scheduling
✓ A processor can be preempted to execute the different processes in the middle of any
current process execution.

✓ CPU utilization is more efficient compared to Non-Preemptive Scheduling.

✓ Waiting and response time of preemptive Scheduling is less.

✓ Preemptive Scheduling is prioritized. The highest priority process is a process that is


currently utilized.

✓ Preemptive Scheduling is flexible.

60
✓ Examples: – Shortest Remaining Time First, Round Robin, etc.

✓ Preemptive Scheduling algorithm can be pre-empted that is the process can be Scheduled

✓ In this process, the CPU is allocated to the processes for a specific time period.

✓ Preemptive algorithm has the overhead of switching the process from the ready state to the
running state and vice-versa.

Advantages of Preemptive Scheduling


Here, are pros/benefits of Preemptive Scheduling method:
• Preemptive scheduling method is more robust, approach so one process cannot monopolize
the CPU
• Choice of running task reconsidered after each interruption.
• Each event cause interruption of running tasks
• The OS makes sure that CPU usage is the same by all running process.
• In this, the usage of CPU is the same, i.e., all the running processes will make use of CPU
equally.
• This scheduling method also improvises the average response time.
• Preemptive Scheduling is beneficial when we use it for the multi-programming
environment.
Advantages of Non-preemptive Scheduling
Here, are pros/benefits of Non-preemptive Scheduling method:
• Offers low scheduling overhead
• Tends to offer high throughput
• It is conceptually very simple method
• Less computational resources need for Scheduling
Disadvantages of Preemptive Scheduling
Here, are cons/drawback of Preemptive Scheduling method:
• Need limited computational resources for Scheduling
• Takes a higher time by the scheduler to suspend the running task, switch the context, and
dispatch the new incoming task.
• The process which has low priority needs to wait for a longer time if some high priority
processes arrive continuously.

61
Disadvantages of Non-Preemptive Scheduling
Here, are cons/drawback of Non-Preemptive Scheduling method:
• It can lead to starvation especially for those real-time tasks
• Bugs can cause a machine to freeze up
• It can make real-time and priority Scheduling difficult
• Poor response time for processes
Example of Non-Preemptive Scheduling
In non-preemptive SJF scheduling, once the CPU cycle is allocated to process, the process holds
it till it reaches a waiting state or terminated.
KEY DIFFERENCES
• In Preemptive Scheduling, the CPU is allocated to the processes for a specific time period,
and non-preemptive scheduling CPU is allocated to the process until it terminates.
• In Preemptive Scheduling, tasks are switched based on priority while non-preemptive
Scheduling no switching takes place.
• Preemptive algorithm has the overhead of switching the process from the ready state to the
running state while Non-preemptive Scheduling has no such overhead of switching.
• Preemptive Scheduling is flexible while Non-preemptive Scheduling is rigid.

4.2. Schedulers and policies


To make your day more logical and efficient, you work on a schedule. An operating system
operates in a similar manner: by scheduling tasks, improving efficiency, reducing delays and
wait times (response times to the system), and managing CPU resources better.
This activity is called process scheduling. A process is like a job in computer systems that can
be executed. Some processes are input/output (I/O) like graphics display process, others are
CPU-focused and can be transparent to users. If your computer freezes, sometimes the
underlying issue could be that a system process is trying to acquire CPU resources, but those
resources are already occupied by other processes. Through process scheduling, the operating
system tries to avoid this kind of deadlocks and lockups.

62
Criteria for Scheduling
There are several criteria for invoking the best scheduling policies for a system:

Criteria Description

CPU Utilization Reduces the strain on the CPU and manages the percentage of time the CPU is busy

Throughput Increases the number of processes completed in a given time frame

Wait Time Reduces the waiting time of a process

Response Time Minimizes the time a user has to wait for a process to run

Turnaround Time Total time a process takes to run, from start to finish (includes all waiting time)

Scheduling Policies
To fulfill those criteria, a scheduler has to use various policies or strategies:
1. Fairness
Just as it isn't fair for someone to bring a loaded shopping cart to the 10-items-or-less checkout, the
operating system shouldn't give an unfair advantage to a process that will interfere with the criteria we
listed (CPU utilization, wait time, throughput). It's important to balance long-running jobs and ensure that
the lighter jobs can be run quickly. Let's take a look at the policies and then do a final comparison that
addresses the fairness of each item.
2. FCFS - First Come First Served
Also called FIFO (first-in-first-out), first-come-first-served (FCFS) processes jobs in the order in which
they are received. This is not a very fair policy, because a long-running job could be running, and other
processes have to wait for it to finish. To the end-user, this could look like a system freeze or lock-up.
Consider the following example of a long-running process A that now holds other processes B, C and D
as hostage.

Table 2: FCFS Scheduling Policy

63
3. Round Robin
This policy works like musical chairs but more methodical. A timer is used to determine when to move
the current running process to the back of the line. For example, you set the timer to 10ms; if the printer
process isn't done within that time frame, move it to the end of the line and move up the next process.
If the time (10ms) is too long, processes still have to wait longer, which basically puts you back into
FCFS territory. However, if the time is too small, you spend more time context switching and hence, the
throughput suffers.
4.3. Processes and threads
A process is an instance of program execution. This means, for example, that if you open up two
browser windows then you have two processes, even though they are running the same program.
The life-cycle of a process can be described by a state diagram which has states representing the
execution status of the process at various times and transitions that represent changes in
execution status. The operating system maintains management information about a process in a
process control block (PCB). Modern operating systems allow a process to be divided into
multiple threads of execution, which share all process management information except for
information directly related to execution. This information is held in a thread control block
(TCB). Threads in a process can execute different parts of the program code at the same time.
They can also execute the same parts of the code at the same time, but with different execution
state:
✓ They have independent current instructions; that is, they have (or appear to have)
independent program counters.
✓ They are working with different data; that is, they are (or appear to be) working with
independent registers.
Threads
Modern operating systems allow a process to be divided into multiple threads of execution. The
threads within a process share all process management information except for information
directly related to execution. This information is moved out of the PCB into thread control block
(TCBs).
Threads in a process can execute different parts of the program code at the same time. They can
also execute the same parts of the code at the same time, but with different execution state:

64
✓ They have independent current instructions; that is, they have (or appear to have)
independent program counters.
✓ They are working with different data; that is, they are (or appear to be) working with
independent registers.
This is accomplished by moving execution state out of the PCB into thread control blocks
(TCBs). Each thread has its own TCB.
Processes start out with a single main thread. The main thread can create new threads using a
thread fork system call. The new threads can also use this system call to create more threads.
Consequently, a thread not only belongs to a process; it also has a parent thread - the thread that
created it.
Questions
1. What is the Difference between Process and Thread?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

65
Difference between Process and Thread
S.NO Process Thread

1. Process means any program is in execution. Thread means segment of a process.


2. Process takes more time to terminate. Thread takes less time to terminate.
3. It takes more time for creation. It takes less time for creation.

4. It also takes more time for context switching. It takes less time for context switching.
Thread is more efficient in term of
5. Process is less efficient in term of communication. communication.
6. Process consumes more resources. Thread consumes less resources.
7. Process is isolated. Threads share memory.
8. Process is called heavy weight process. Thread is called light weight process.
Thread switching does not require to call a
operating system and cause an interrupt to
9. Process switching uses interface in operating system. the kernel.
If one process is blocked then it will not affect the Second thread in the same task could not
10. execution of other process run, while one server thread is blocked.
Thread has Parents’ PCB, its own Thread
Process has its own Process Control Block, Stack and Control Block and Stack and common
11. Address Space. Address space.

Table 3: Difference between Process and Thread

A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set
of registers, ( and a thread ID. ) Traditional ( heavyweight ) processes have a single thread of
control - There is one program counter, and one sequence of instructions that can be carried out
at any given time.

66
Processes vs. Threads: Advantages and Disadvantages

PROCESS THREAD

✓ Processes are heavyweight operations. ✓ Threads are lighter weight operations.

✓ Each process has its own memory space. ✓ Threads use the memory of the process they
belong to.

✓ Inter-process communication is slow as ✓ Inter-thread communication can be faster than


processes have different memory addresses. inter-process communication because threads
of the same process share memory with the
process they belong to.

✓ Context switching between processes is more ✓ Context switching between threads of the same
expensive. process is less expensive

✓ Processes don’t share memory with other ✓ Threads share memory with other threads of
processes. the same process.

Table 4: Processes vs. Threads

What About Concurrency and Parallelism?


A question you might ask is whether processes or threads can run at the same time. The answer
is It depends. On a system with multiple processors or CPU cores (as is common with modern
processors), multiple processes or threads can be executed in parallel. On a single processor,
though, it is not possible to have processes or threads truly executing at the same time. In this
case, the CPU is shared among running processes or threads using a process scheduling
algorithm that divides the CPU’s time and yields the illusion of parallel execution. The time
given to each task is called a “time slice.” The switching back and forth between tasks happens
so fast it is usually not perceptible. The terms, “parallelism” (genuine simultaneous execution)
and “concurrency” (interleaving of processes in time to give the appearance of simultaneous
execution), distinguish between the two types of real or approximate simultaneous operation.
Properties of Process
Here are the important properties of the process:
• Creation of each process requires separate system calls for each process.

67
• It is an isolated execution entity and does not share data and information.
• Processes use the IPC (Inter-Process Communication) mechanism for communication that
significantly increases the number of system calls.
• Process management takes more system calls.
• A process has its stack, heap memory with memory, and data map.

4.4 SCHEDULING
When a computer is multiprogrammed, it frequently has multiple processes or threads competing
for the CPU at the same time. This situation occurs whenever two or more of them are
simultaneously in the ready state. If only one CPU is available, a choice has to be made which
process to run next. The part of the operating system that makes the choice is called the
scheduler, and the algorithm it uses is called the scheduling algorithm. These topics form the
subject matter of the following sections.
Many of the same issues that apply to process scheduling also apply to thread scheduling,
although some are different. When the kernel manages threads, scheduling is usually done per
thread, with little or no regard to which process the thread belongs. Initially we will focus on
scheduling issues that apply to both processes and threads.
4.4.1 INTRODUCTION TO SCHEDULING
Back in the old days of batch systems with input in the form of card images on a magnetic tape,
the scheduling algorithm was simple: just run the next job on the tape. With multiprogramming
systems, the scheduling algorithm became more complex because there were generally multiple
users waiting for service. Some mainframes still combine batch and timesharing service,
requiring the scheduler to decide whether a batch job or an interactive user at a terminal should
go next.
(As an aside, a batch job may be a request to run multiple programs in succession, but for this
section, we will just assume it is a request to run a single program.)
Because CPU time is a scarce resource on these machines, a good scheduler can make a big
difference in perceived performance and user satisfaction. Consequently, a great deal of work
has gone into devising clever and efficient scheduling algorithms. With the advent of personal
computers, the situation changed in two ways. First, most of the time there is only one active
process. A user entering a document on a word processor is unlikely to be simultaneously

68
compiling a program in the background. When the user types a command to the word processor,
the scheduler does not have to do much work to figure out which process to run-the word
processor is the only candidate. Second, computers have gotten so much faster over the years
that the CPU is rarely a scarce resource any more. Most programs for personal computers are
limited by the rate at which the user can present input (by typing or clicking), not by the rate the
CPU can process it. Even compilations, a major sink of CPU cycles in the past, take just a few
seconds in most cases nowadays. Even when two programs are actually running at once, such as
a word processor and a spreadsheet, it hardly matters which goes first since the user is probably
waiting for both of them to finish. As a consequence, scheduling does not matter much on simple
PCs. Of course, there are applications that practically eat the CPU alive, for instance rendering
one hour of high-resolution video while tweaking the colors in each of the 108,000 frames (in
NTSC) or 90,000 frames (in PAL) require industrial-strength computing power. However,
similar applications are the exception rather than the rule.
When we turn to networked servers, the situation changes appreciably. Here multiple processes
often do compete for the CPU, so scheduling matters again. For example, when the CPU has to
choose between running a process that gathers the daily statistics and one that serves user
requests, the users will be a lot happier if the latter gets first crack at the CPU.
In addition to picking the right process to run, the scheduler also has to worry about making
efficient use of the CPU because process switching is expensive. To start with, a switch from
user mode to kernel mode must occur. Then the state of the current process must be saved,
including storing its registers in the process table so they can be reloaded later. In many systems,
the memory map (e.g., memory reference bits in the page table) must be saved as well. Next a
new process must be selected by running the scheduling algorithm. After that, the MMU must be
reloaded with the memory map of the new process. Finally, the new process must be started.
In addition to all that, the process switch usually invalidates the entire memory cache, forcing it
to be dynamically reloaded from the main memory twice (upon entering the kernel and upon
leaving it). All in all, doing too many process switches per second can chew up a substantial
amount of CPU time, so caution is advised.
The objective of multiprogramming is to have some process running at all times, to maximize
CPU utilization. The objective of time sharing is to switch the CPU among processes so
frequently. In uniprocessor only one process is running. A process migrates between various

69
scheduling queues throughout its lifetime. The process of selecting processes from among these
queues is carried out by a scheduler. The aim of processor scheduling is to assign processes to be
executed by the processor. Scheduling affects the performance of the system, because it
determines which process will wait and which will progress.
Types of Scheduling

Long-term Scheduling: Long term scheduling is performed when a new process is created. It is
shown in the figure below. If the number of ready processes in the ready queue becomes very
high, then there is an overhead on the operating system (i.e., processor) for maintaining long
lists, context switching and dispatching increases. Therefore, allow only limited number of
processes in to the ready queue. The "long-term scheduler" managers this. Long-term scheduler
determines which programs are admitted into the system for processing. Once when admit a
process or job, it becomes process and is added to the queue for the short-term scheduler. In
some systems, a newly created process begins in a swapped-out condition, in which case it is
added to a queue for the medium-term scheduler scheduling manage queues to minimize
queueing delay and to optimize performance.

Figure 19: Scheduler

The long-term scheduler limits the number of processes to allow for processing by taking the
decision to add one or more new jobs, based on FCFS (First-Come, first-serve) basis or priority

70
or execution time or Input/output requirements. Long-term scheduler executes relatively
infrequently.

Medium-term Scheduling: Medium-term scheduling is a part of the swapping function. When


part of the main memory gets freed, the operating system looks at the list of suspend ready
processes, decides which one is to be swapped in (depending on priority, memory and other
resources required, etc.). This scheduler works in close conjunction with the long-term scheduler.
It will perform the swapping-in function among the swapped-out processes. Medium-term
scheduler executes somewhat more frequently.
Short-term Scheduling: Short-term scheduler is also called as dispatcher. Short-term scheduler
is invoked whenever an event occurs, that may lead to the interruption of the current running
process. For example, clock interrupts, I/O interrupts, operating system calls, signals, etc. Short-
term scheduler executes most frequently. It selects from among the processes that are ready to
execute and allocates the CPU to one of them. It must select a new process for the CPU
frequently. It must be very fast.

Table 5: Comparison between scheduler

Scheduling Criteria
Scheduling criteria is also called as scheduling methodology. Key to multiprogramming is

71
scheduling. Different CPU scheduling algorithms have different properties. The criteria used for
comparing these algorithms include the following:
• CPU Utilization:
Keep the CPU as busy as possible. It ranges from 0 to 100%. In practice, it ranges from 40 to
90%.
• Throughput:
Throughput is the rate at which processes are completed per unit of time.
• Turnaround time:
This is the how long a process takes to execute a process. It is calculated as the time gap
between the submission of a process and its completion.
• Waiting time:
Waiting time is the sum of the time periods spent in waiting in the ready queue.
• Response time:
Response time is the time it takes to start responding from submission time. It is calculated as
the amount of time it takes from when a request was submitted until the first response is
produced.
• Fairness:
Each process should have a fair share of CPU.
Non-preemptive Scheduling
In non-preemptive mode, once if a process enters into running state, it continues to execute until
it terminates or blocks itself to wait for Input/output or by requesting some operating system
service.
Preemptive Scheduling
In preemptive mode, currently running process may be interrupted and moved to the ready State
by the operating system. When a new process arrives or when an interrupt occurs, preemptive
policies may incur greater overhead than non-preemptive version but preemptive version may
provide better service. It is desirable to maximize CPU utilization and throughput, and to
minimize turnaround time, waiting time and response time.
PROCESS BEHAVIOR
Nearly all processes alternate bursts of computing with (disk) 1/0 requests, as shown in Fig.
below. Typically, the CPU runs for a while without stopping, then a system call is made to read

72
from a file or write to a file. When the system call completes, the CPU computes again until it
needs more data or has to write more data, and so on. Note that some 110 activities count as
computing. For example, when the CPU copies bits to a video RAM to update the screen, it is
computing, not doing 1/0, because the CPU is in use. 1/0 in this sense is when a process enters
the blocked state waiting for an external device to complete its work.

Bursts of CPU usage alternate with periods of waiting for UO.


(a) A CPU-bound process. (b) An UO-bound process.
The important thing to notice about the figure is that some processes, such as the one in Fig. (a),
spend most of their time computing, while others, such as the one in Fig. (b), spend most of their
time waiting for I/0. The former is called compute-bound; the latter are called I/O-bound.
Compute-bound processes typically have long CPU bursts and thus infrequent 1/0 waits, whereas
I/O bound processes have short CPU bursts and thus frequent I/0 waits. Note that the key factor
is the length of the CPU burst, not the length of the I/0 burst. I/O bound processes are I/0 bound
because they do not compute much between I/0 requests, not because they have especially long
I/0 requests. It takes the same time to issue the hardware request to read a disk block no matter
how much or how little time it takes to process the data after they arrive.
It is worth noting that as CPUs get faster, processes tend to get more I/O bound. This effect
occurs because CPUs are improving much faster than disks.
As a consequence, the scheduling of I/O-bound processes is likely to become a more important
subject in the future. The basic idea here is that if an I/O-bound process wants to run, it should
get a chance quickly so that it can issue its disk request and keep the disk busy.

73
WHEN TO SCHEDULE
A key issue related to scheduling is when to make scheduling decisions. It turns out that there are
a variety of situations in which scheduling is needed.
First, when a new process is created, a decision needs to be made whether to run the parent
process or the child process. Since both processes are in ready state, it is a normal scheduling
decision and can go either way, that is, the scheduler can legitimately choose to run either the
parent or the child next.
Second, a scheduling decision must be made when a process exits. That process can no longer
run (since it no longer exists), so some other process must be chosen from the set of ready
processes. If no process is ready, a system-supplied idle process is normally run.
Third, when a process blocks on I/0, or for some other reason, another process has to be selected
to run. Sometimes the reason for blocking may play a role in the choice. For example, if A is an
important process and it is waiting for B to exit its critical region, letting B run next will allow it
to exit its critical region and thus let A continue. The trouble, however, is that the scheduler
generally does not have the necessary information to take this dependency into account.
Fourth, when an I/0 interrupt occurs, a scheduling decision may be made. If the interrupt came
from an I/0 device that has now completed its work, some process that was blocked waiting for
the 110 may now be ready to run. It is up to the scheduler to decide whether to run the newly
ready process, the process that was running at the time of the interrupt, or some third process.
Scheduling algorithms can be divided into two categories with respect to how they deal with
clock interrupts. A nonpreemptive scheduling algorithm picks a process to run and then just lets
it run until it blocks (either on I/0 or waiting for another process) or until it voluntarily releases
the CPU. Even if it runs for hours, it will not be forceably suspended. In effect, no scheduling
decisions are made during clock interrupts. After clock interrupt processing has been completed,
the process that was running before the interrupt is resumed, unless a higher-priority process was
waiting for a now-satisfied timeout.
In contrast, a preemptive scheduling algorithm picks a process and lets it run for a maximum of
some fixed time. If it is still running at the end of the time interval, it is suspended and the
scheduler picks another process to run (if one is available).

74
CATEGORIES GOALS OF SCHEDULING ALGORITHMS
Not surprisingly, in different environments different scheduling algorithms are needed. This
situation arises because different application areas (and different kinds of operating systems)
have different goals. In other words, what the scheduler should optimize for is not the same in all
systems. Three environments worth distinguishing are
1. Batch.
2. Interactive.
3. Real time.
In order to design a scheduling algorithm, it is necessary to have some idea of what a good
algorithm should do. Some goals depend on the environment (batch, interactive, or real time),
but there are also some that are desirable in all cases. This are:
✓ Fairness - giving each process a fair share of the CPU
✓ Policy enforcement - seeing that stated policy is carried out
✓ Balance - keeping all parts of the system busy
Under all circumstances, fairness is important. Comparable processes should get comparable
service. Giving one process much more CPU time than an equivalent one is not fair. Of course,
different categories of processes may be treated differently. Think of safety control and doing the
payroll at a nuclear reactor's computer center.
Somewhat related to fairness is enforcing the system's policies. If the local policy is that safety
control processes get to run whenever they want to, even if it means the payroll is 30 sec late, the
scheduler has to make sure this policy is enforced.
Another general goal is keeping all parts of the system busy when possible. If the CPU and all
the 1/0 devices can be kept running all the time, more work gets done per second than if some of
the components are idle. In a batch system, for example, the scheduler has control of which jobs
are brought into memory to run.
Having some CPU-bound processes and some I/O-bound processes in memory together is a
better idea than first loading and running all the CPU-bound jobs and then, when they are
finished, loading and running all the I/O-bound jobs. If the latter strategy is used, when the CPU-
bound processes are running, they will fight for the CPU and the disk will be idle. Later, when
the I/O-bound jobs come in, they will fight for the disk and the CPU will be idle. Better to keep
the whole system running at once by a careful mix of processes.

75
BATCH SYSTEMS
Batch systems are still in widespread use in the business world for doing payroll, inventory,
accounts receivable, accounts payable, interest calculation (at banks), claims processing (at
insurance companies), and other periodic tasks. In batch systems, there are no users impatiently
waiting at their terminals for a quick response to a short request. Consequently, nonpreemptive
algorithms, or preemptive algorithms with long time periods for each process, are often
acceptable. This approach reduces process switches and thus improves performance. The batch
algorithms are actually fairly general and often applicable to other situations as well, which
makes them worth studying, even for people not involved in corporate mainframe computing.
So, the goals can be:
✓ Throughput - maximize jobs per hour
✓ Turnaround time - minimize time between submission and termination
✓ CPU utilization - keep the CPU busy all the time
The managers of large computer centers that run many batch jobs typically look at three metrics
to see how well their systems are performing: throughput, turnaround time, and CPU utilization.
Throughput is the number of jobs per hour that the system completes. All things considered,
finishing 50 jobs per hour is better than finishing 40 jobs per hour. Turnaround time is the
statistically average time from the moment that a batch job is submitted until the moment it is
completed. It measures how long the average user has to wait for the output.
Here the rule is: Small is Beautiful.
A scheduling algorithm that maximizes throughput may not necessarily minimize turnaround
time. For example, given a mix of short jobs and long jobs, a scheduler that always ran short jobs
and never ran long jobs might achieve an excellent throughput (many short jobs per hour) but at
the expense of a terrible turnaround time for the long jobs. If short jobs kept arriving at a fairly
steady rate, the long jobs might never run, making the mean turnaround time infinite while
achieving a high throughput.
CPU utilization is often used as a metric on batch systems. Actually though, it is not such a good
metric. What really matters is how many jobs per hour come out of the system (throughput) and
how long it takes to get a job back (turnaround time). Using CPU utilization as a metric is like
rating cars based on how many times per hour the engine turns over. On the other hand, knowing

76
when the CPU utilization is approaching 100% is useful for knowing when it is time to get more
computing power.
INTERACTIVE SYSTEMS
In an environment with interactive users, preemption is essential to keep one process from
hogging the CPU and denying service to the others. Even if no process intentionally ran forever,
one process might shut out all the others indefinitely due to a program bug. Preemption is needed
to prevent this behavior. Servers also fall into this category, since they normally serve multiple
(remote) users, all of whom are in a big hurry. So, the goals can be:
✓ Response time - respond to requests quickly
✓ Proportionality - meet users' expectations
For interactive systems, different goals apply. The most important one is to minimize response
time, that is, the time between issuing a command and getting the result. On a personal computer
where a background process is running (for example, reading and storing e-mail from the
network), a user request to start a program or open a file should take precedence over the
background work. Having all interactive requests go first will be perceived as good service.
A somewhat related issue is what might be called proportionality. Users have an inherent (but
often incorrect) idea of how long things should take. When a request that is perceived as
complex takes a long time, users accept that, but when a request that is perceived as simple takes
a long time, users get irritated. For example, if clicking on a icon that starts sending a fax takes
60 seconds to complete, the user will probably accept that as a fact of life because he does not
expect a fax to be sent in 5 seconds.
On the other hand, when a user clicks on the icon that breaks the phone connection after the fax
has been sent, he has different expectations. If it has not completed after 30 seconds, the user will
probably be swearing a blue streak, and after 60 seconds he will be frothing at the mouth. This
behavior is due to the common user perception that placing a phone call and sending a fax is
supposed to take a lot longer than just hanging the phone up. In some cases (such as this one),
the scheduler cannot do anything about the response time, but in other cases it can, especially
when the delay is due to a poor choice of process order.
REAL-TIME SYSTEMS
In systems with real-time constraints, preemption is, oddly enough, sometimes not needed
because the processes know that they may not run for long periods of time and usually do their

77
work and block quickly. The difference with interactive systems is that real-time systems run
only programs that are intended to further the application at hand. Interactive systems are general
purpose and may run arbitrary programs that are not cooperative or even malicious. So, the goals
can be:
✓ Real-time systems
✓ Meeting deadlines - avoid losing data
✓ Predictability - avoid quality degradation in multimedia systems
Real-time systems have different properties than interactive systems, and thus different
scheduling goals. They are characterized by having deadlines that must or at least should be met.
For example, if a computer is controlling a device that produces data at a regular rate, failure to
run the data-collection process on time may result in lost data. Thus, the foremost need in a real-
time system is meeting all (or most) deadlines.
In some real-time systems, especially those involving multimedia, predictability is important.
Missing an occasional deadline is not fatal, but if the audio process runs too erratically, the sound
quality will deteriorate rapidly. Video is also an issue, but the ear is much more sensitive to jitter
than the eye. To avoid this problem, process scheduling must be highly predictable and regular.
4.5 Scheduling Algorithm
A scheduling algorithm is the algorithm which dictates how much CPU time is allocated to
Processes and Threads. The goal of any scheduling algorithm is to fulfill a number of criteria: no
task must be starved of resources - all tasks must get their chance at CPU time.
Scheduling algorithms or scheduling policies are mainly used for short-term scheduling.
The main objective of short-term scheduling is to allocate processor time in such a way as to
optimize one or more aspects of system behavior. For these scheduling algorithms assume only a
single processor is present.
Scheduling algorithms decide which of the processes in the ready queue is to be allocated to the
CPU is basis on the type of scheduling policy and whether that policy is either preemptive or
non-preemptive. For scheduling arrival time and service time are also will play a role.
List of scheduling algorithms are as follows:
First-come, first-served scheduling (FCFS) algorithm
Shortest Job First Scheduling (SJF) algorithm
Shortest Remaining time (SRT) algorithm

78
Round-Robin Scheduling algorithm
Highest Response Ratio Next (HRRN) algorithm
Multilevel Feedback Queue Scheduling algorithm
4.5.1 FIRST-COME FIRST-SERVED
Probably the simplest of all scheduling algorithms is nonpreemptive first come first-served. With
this algorithm, processes are assigned the CPU in the order they request it. Basically, there is a
single queue of ready processes. When the first job enters the system from the outside in the
morning, it is started immediately and allowed to run as long as it wants to. It is not interrupted
because it has run too long. As other jobs come in, they are put onto the end of the queue.
When the running process blocks, the first process on the queue is run next. When a blocked
process becomes ready, like a newly arrived job, it is put on the end of the queue.
The great strength of this algorithm is that it is easy to understand and equally easy to program. It
is also fair in the same sense that allocating scarce sports or concert tickets to people who are
willing to stand on line starting at 2 A.M. is fair. With this algorithm, a single linked list keeps
track of all ready processes. Picking a process to run just requires removing one from the front of
the queue. Adding a new job or unblocked process just requires attaching it to the end of the
queue. What could be simpler to understand and implement?
Unfortunately, first-come first-served also has a powerful disadvantage. Suppose that there is one
compute-bound process that runs for 1 sec at a time and many I/O-bound processes that use little
CPU time but each have to perform 1000 disk reads to complete. The compute-bound process
runs for 1 sec, then it reads a disk block. All the 1/0 processes now run and start disk reads.
When the compute-bound process gets its disk block, it runs for another 1 sec, followed by all
the I/O-bound processes in quick succession.
The net result is that each I/O-bound process gets to read 1 block per second and will take 1000
sec to finish. With a scheduling algorithm that preempted the compute-bound process every
10msec, the I/O-bound processes would finish in 10 sec instead of 1000 sec, and without slowing
down the compute-bound process very much.

79
Illustration
Consider the following processes arrive at time 0
Process P1 P2 P3
CPU Burst/Service/Running Time (in ms) 24 3 3

Case i. If they arrive in the order of P1, P2, P3


Process P1 P2 P3
Service Time (Ts) 24 3 3
Turnaround time (Tr) 24 27 30
Response time 0 24 27
Tr/Ts 1 9 10
Average response time = (0+24+27)/3 = 17
Average turnaround time = (24+27+30)/3=27
Throughput = 3/30= 1/10
Case ii. If they arrive in the order of P3, P2, P1
Process P3 P2 P1
Service Time (Ts) 3 3 24
Turnaround time (Tr) 3 6 30
Response time 0 3 6
Tr/Ts 1 2 1.25
Average response time = (0+3+6)/3 = 3
Average turnaround time = (3+6+30)/3=13
Throughput = 3/30= 1/10
Consider the following processes arrive at time 0, 1, 2, 3 respectively
Process P1 P2 P3 P4
Arrival Time (Ta) 0 1 2 3
Service Time (Ts) 1 100 1 100

80
Turnaround time (Tr) 1 100 100 199
Response time 0 0 99 99
Tr/Ts 1 1 100 1.99
Average response time = (0+0+99+99)/4 = 49.5
Average turnaround time = (1+100+100+199)/4=100
Throughput = 4/202 = 1/101
4.5.2 SHORTEST JOB FIRST
Now let us look at another nonpreemptive batch algorithm that assumes the run times are known
in advance. In an insurance company, for example, people can predict quite accurately how long
it will take to run a batch of 1000 claims, since similar work is done every day. When several
equally important jobs are sitting in the input queue waiting to be started, the scheduler picks the
shortest job first. Look at Fig. below. Here we find four jobs A, B, C, and D with run times of 8,
4, 4, and 4 minutes, respectively. By running them in that order, the turnaround time for A is 8
minutes, for B is 12 minutes, for C is 16 minutes, and for D is 20 minutes for an average of 14
minutes.

An example of shortest job first scheduling. (a) Running four jobs in the original order. (b)
Running them in shortest job first order.
Now let us consider running these four jobs using shortest job first, as shown in Fig. (b). the
turnaround times are now 4, 8, 12, and 20 minutes for an average of 11 minutes. Shortest job first
is provably optimal. Consider the case of four jobs, with run times of a, b, c, and d, respectively.
The first job finishes at time a, the second finishes at time a + b, and so on. The mean turnaround
time is (4a + 3b + 2c + d)/4. It is clear that a contributes more to the average than the other times,
so it should be the shortest job, with b next, then c, and finally d as the longest as it affects only
its own turnaround time. The same argument applies equally well to any number of jobs.
It is worth pointing out that shortest job first is only optimal when all the jobs are available
simultaneously. As a counter example, consider five jobs, A through E, with run times of 2, 4, 1,
1, and 1, respectively. Their arrival times are 0, 0, 3, 3, and 3. Initially, only A or B can be

81
chosen, since the other three jobs have not arrived yet. Using shortest job first we will run the
jobs in the order A, B, C, D, E, for an average wait of 4.6. However, running them in the order B,
C, D, E, A has an average wait of 4.4.
Illustration
➢ Consider the following processes arrive at time 0
Process P1 P2 P3

CPU Burst (in ms) 24 3 3


Case i. FCFS
Process P1 P2 P3

Turnaround time 24 27 30

Response time 0 24 27

Average response time = (0+24+27)/3 = 17

Average turnaround time = (24+27+30)/3=27

Throughput = 3/30
Case ii. SJF
Process P3 P2 P1

Turnaround time 3 6 30

Response time 0 3 6

Average response time = (0+3+6)/3 = 3

Average turnaround time = (3+6+30)/3=13

Throughput = 3/30

➢ Consider the following processes arrive at time 0, 2, 4, 6, 8 respectively


Process P1 P2 P3 P4 P5

Arrival Time (Ta) 0 2 4 6 8

Service Time (Ts) 3 6 4 5 2

82
Turnaround time (Tr) 3 7 11 14 3

Response time 0 1 7 9 1

Tr/Ts 1 1.17 2.75 2.8 1.5

Average response time = (0+1+7+9+1)/5 = 3.6

Average turnaround time = (3+7+11+14+3)/5=7.6

Throughput = 5/20

4.5.3 SHORTEST REMAINING TIME NEXT


A preemptive version of shortest job first is shortest remaining time next. With this algorithm,
the scheduler always chooses the process whose remaining run time is the shortest. Again here,
the run time has to be known in advance.
When a new job arrives, its total time is compared to the current process' remaining time. If the
new job needs less time to finish than the current process, the current process is suspended and
the new job started. This scheme allows new short jobs to get good service.
Illustration
Consider the following processes arrive at time 0, 2, 4, 6, 8 respectively
Process P1 P2 P3 P4 P5
Arrival Time (Ta) 0 2 4 6 8
Service Time (Ts) 3 6 4 5 2
Turnaround time (Tr) 3 13 4 14 2
Response time 0 1 0 9 0
Tr/Ts 1 2.17 1 2.8 1
Average response time = (0+1+0+9+0)/5 = 2
Average turnaround time = (3+13+4+14+2)/5=7.2
Throughput = 5/20
SCHEDULING IN INTERACTIVE SYSTEMS
We will now look at some algorithms that can be used in interactive systems. These are common
on personal computers, servers, and other kinds of systems as well.

83
4.6.4 ROUND-ROBIN SCHEDULING
One of the oldest, simplest, fairest, and most widely used algorithms is round robin. Each
process is assigned a time interval, called its quantum, during which it is allowed to run. If the
process is still running at the end of the quantum, the CPU is preempted and given to another
process. If the process has blocked or finished before the quantum has elapsed, the CPU
switching is done when the process blocks, of course. Round robin is easy to implement. All the
scheduler needs to do is maintain a list of runnable processes, as shown in Fig. (a). When the
process uses up its quantum, it is put on the end of the list, as shown in Fig. (b).
The only interesting issue with round robin is the length of the quantum.
Switching from one process to another requires a certain amount of time for doing the
administration-saving and loading registers and memory maps, updating various tables and lists,
flushing and reloading the memory cache, and so on. Suppose that this process switch or context
switch, as it is sometimes called, takes 1 msec, including switching memory maps, flushing and
reloading the cache, etc.
Also suppose that the quantum is set at 4 msec. With these parameters, after doing 4 msec of
useful work, the CPU will have to spend (i.e., waste) 1 msec on process switching. Thus 20% of
the CPU time will be thrown away on administrative overhead. Clearly, this is too much.

Figure 20: Round-robin scheduling. (a) The list of runnable processes. (b) The list of runnable
processes after B uses up its quantum.

To improve the CPU efficiency, we could set the quantum to, say, 100 msec.

Now the wasted time is only 1%. But consider what happens on a server system if 50 requests
come in within a very short time interval and with widely varying CPU requirements. Fifty
processes will be put on the list of runnable processes. If the CPU is idle, the first one will start
immediately, the second one may not start until 100 msec later, and so on. The unlucky last one
may have to wait 5 sec before getting a chance, assuming all the others use their full quanta.

84
Most users will perceive a 5-sec response to a short command as sluggish. This situation is
especially bad if some of the requests near the end of the queue required only a few milliseconds
of CPU time. With a short quantum they would have gotten better service.
Another factor is that if the quantum is set longer than the mean CPU burst, preemption will not
happen very often. Instead, most processes will perform a blocking operation before the quantum
runs out, causing a process switch. Eliminating preemption improves performance because
process switches then only happen when they are logically necessary, that is, when a process
blocks and cannot continue.
The conclusion can be formulated as follows: setting the quantum too short causes too many
process switches and lowers the CPU efficiency, but setting it too long may cause poor response
to short interactive requests. A quantum around 20-50 msec is often a reasonable compromise.
Performance of RR Scheduling
• If there are n processes in the ready queue and time quantum is q, then each process gets 1/n
of the CPU time in chunks of at most q time units at once.
• No process waits for more than (n-1)*q time units until the next time quantum.
• The performance of RR depends on time slice. If it is large then it is the same as FCFS. If q
is small then overhead is too high.
Illustration
➢ Consider the following processes arrive at time 0, 2, 4 respectively
Process P1 P2 P3

Arrival Time (Ta) 0 2 4

Service Time (Ts) 3 7 4

Turnaround time (Tr) ___ ___ __

Response time ___ ___ __

Tr/Ts ___ ___ __

Average response time = __________________________

Average turnaround time =___________________________

Throughput = 3/14

85
4.5.5 PRIORITY SCHEDULING
Round-robin scheduling makes the implicit assumption that all processes are equally important.
Frequently, the people who own and operate multiuser computers have different ideas on that
subject. At a university, for example, the pecking order may be deans first, then professors,
secretaries, janitors, and finally students.
The need to take external factors into account leads to priority scheduling. The basic idea is
straightforward: each process is assigned a priority, and the runnable process with the highest
priority is allowed to run. Even on a PC with a single owner, there may be multiple processes,
some of them more important than others. For example, a daemon process sending electronic
mail in the background should be assigned a lower priority than a process displaying a video film
on the screen in real time.
To prevent high-priority processes from running indefinitely, the scheduler may decrease the
priority of the currently running process at each clock tick (i.e., at each clock interrupt). If this
action causes its priority to drop below that of the next highest process, a process switch occurs.
Alternatively, each process may be assigned a maximum time quantum that it is allowed to run.
When this quantum is used up, the next highest priority process is given a chance to run.
Priorities can be assigned to processes statically or dynamically. On a military computer,
processes started by generals might begin at priority 100, processes started by colonels at 90,
majors at 80, captains at 70, lieutenants at 60, and so on.
Alternatively, at a commercial computer center, high-priority jobs might cost $100 an hour,
medium priority $75 an hour, and low priority $50 an hour. The UNIX system has a command,
nice, which allows a user to voluntarily reduce the priority of his process, in order to be nice to
the other users. Nobody ever uses it.
Priorities can also be assigned dynamically by the system to achieve certain system goals. For
example, some processes are highly 1/0 bound and spend most of their time waiting for 110 to
complete. Whenever such a process wants the CPU, it should be given the CPU immediately, to
let it start its next 1/0 request, which can then proceed in parallel with another process actually
computing. Making the I/O-bound process wait a long time for the CPU will just mean having it
around occupying memory for an unnecessarily long time. A simple algorithm for giving good
service to I/O-bound processes is to set the priority to 1/f, where f is the fraction of the last
quantum that a process used. A process that used only 1 msec of its 50 msec quantum would get

86
priority 50, while a process that ran 25 msec before blocking would get priority 2, and a process
that used the whole quantum would get priority 1.
Illustration
Consider the following processes arrive at time 0
Process P1 P2 P3 P4 P5
Priority 2 4 5 3 1
Service Time (Ts) 3 6 4 5 2
Turnaround time (Tr) 18 10 4 15 20
Response time 15 4 0 10 18
Tr/Ts 6 1.67 1 3 10
Average response time = (0+15+4+10+18)/5 = 9.4
Average turnaround time = (18+10+4+15+20)/5=13.4
Throughput = 5/20= 0.25
It is often convenient to group processes into priority classes and use priority scheduling among
the classes but round-robin scheduling within each class. The Figure below shows a system with
four priority classes. The scheduling algorithm is as follows: as long as there are runnable
processes in priority class 4, just run each one for one quantum, round-robin fashion, and never
bother with lower-priority classes. If priority class 4 is empty, then run the class 3 processes
round robin. If classes 4 and 3 are both empty, then run class 2 round robin, and so on. If
priorities are not adjusted occasionally, lower priority classes may all starve to death.

87
Discussions Question
1. What is the use of scheduling?
2. Which scheduling algorithm is best?
3. Which scheduling algorithm is best?
4. Why do we use scheduling algorithms?
5. Where are scheduling algorithms used?
6. Which is fastest scheduling algorithm?
7. What is the difference between a process and a thread?
8. What is difference between preemptive and non preemptive scheduling?
9. Which condition is for preemptive scheduling?
10. Which algorithm can be either preemptive or Nonpreemptive?
11. How do you solve preemptive priority scheduling?

88
Chapter Five
5. Memory Management
Memory management is the functionality of an operating system which handles or manages
primary memory and moves processes back and forth between main memory and disk during
execution. Memory management keeps track of each and every memory location, regardless of
either it is allocated to some process or it is free. It checks how much memory is to be allocated
to processes. It decides which process will get memory at what time. It tracks whenever some
memory gets freed or unallocated and correspondingly it updates the status.
5.1. Review of physical memory and memory
Memory: RAM is often an area that offers significant performance improvements for most
applications, including SQL Server and Windows 2000. RAM provides the working memory of
your system; by having a great deal RAM, you avoid having to access the much slower disk
arrays. More RAM is always better, but systems that run parallel queries and populate full-text
indexes (and most are primarily DSS systems) require even more RAM.
If the more RAM, the better, how much can you get? Windows 2000 Server is a 32-bit operating
system; as a consequence, it can address only 4GB of memory. Windows 2000 Advanced Server
and Data Center are also 32-bit operating systems, but through the Address Windowing
Extensions (AWE) API, it can address 8GB and 64GB, respectively. You need at least 64 MB of
RAM for SQL Server, plus 32 MB of RAM for the operating system. The more RAM you have,
the more data that can be stored in the data cache and the more procedures that can be stored in
the procedure cache. If the data and procedures that you are querying are in RAM, the server will
not have to visit its disk system, providing a substantial improvement in performance.

Random access memory (RAM) also comes in a few flavors, but all of them appear to look the
same. However, there are slight differences that need to be considered when you’re upgrading
your computer, because they have different form factors and speeds. Whether you’re using this
computer for a DVS server or a workstation, it’s best to max out the memory on the
motherboard, but keep in mind that the standard 32-bit Windows OS can only read up to 4 GB of
RAM. If the software or hardware requirements call for anything more than 4 GB of memory,
it’s recommended that you upgrade to a 64-bit system.

89
Physical memory
Physical memory (also known as random-access memory (RAM)) is a form of very fast, but
volatile data storage. When a system is low on physical memory, it often leads to system-wide
delays or, in extreme cases, a complete hang of the system. RAM modules are typically
measured in nanoseconds (1000− 3), and physical disks are typically measured in milliseconds
(1000− 1). This makes physical memory roughly 100,000 times faster than a common physical
disk. Therefore, when possible, Windows and Windows Server keep the most frequently
accessed pages of memory in physical memory and rely on a disk only if needed.
When a system is low on physical memory, it often leads to system-wide delays or, in extreme
cases, a complete hang of the system. This chapter covers how physical memory is managed by
the operating system, how to identify low-memory conditions, and how to alleviate those
conditions.
5.2 Management hardware
In hardware, memory management involves components that physically store data, such as RAM
(random access memory) chips, memory caches, and flash-based SSDs (solid-state drives).
When a program no longer needs the data in previously allocated memory blocks, those blocks
become available for reassignment.
5.3 Overlays, swapping, and partitions
Overlays
The main problem in Fixed partitioning is the size of a process has to be limited by the maximum
size of the partition, which means a process can never be span over another. In order to solve this
problem, earlier people have used some solution which is called as Overlays. The concept
of overlays is that whenever a process is running it will not use the complete program at the same
time, it will use only some part of it. Then overlays concept says that whatever part you required,
you load it a once the part is done, then you just unload it, means just pull it back and get the new
part you required and run it. Formally, “The process of transferring a block of program code or
other data into internal memory, replacing what is already stored”. Sometimes it happens that
compare to the size of the biggest partition, the size of the program will be even more, then, in
that case, you should go with overlays. So, overlay is a technique to run a program that is bigger
than the size of the physical memory by keeping only those instructions and data that are needed

90
at any given time. Divide the program into modules in such a way that not all modules need to be
in the memory at the same time.
Advantage
• Reduce memory requirement
• Reduce time requirement
Disadvantage
• Overlap map must be specified by programmer
• Programmer must know memory requirement
• Overlapped module must be completely disjoint
• Programming design of overlays structure is complex and not possible in all cases
Example –
The best example of overlays is assembler. Consider the assembler has 2 passes, 2 pass means at
any time it will be doing only one thing, either the 1st pass or the 2nd pass. This means it will
finish 1st pass first and then 2nd pass. Let assume that available main memory size is 150KB and
total code size is 200KB
Pass 1.......................70KB

Pass 2.......................80KB

Symbol table.................30KB

Common routine...............20KB

As the total code size is 200KB and main memory size is 150KB, it is not possible to use 2
passes together. So, in this case, we should go with the overlay’s technique. According to the
overlays concept at any time only one pass will be used and both the passes always need symbol
table and common routine. Now the question is if overlays-driver is 10KB, then what is the
minimum partition size required? For pass 1 total memory needed is = (70KB + 30KB + 20KB +
10KB) = 130KB and for pass 2 total memory needed is = (80KB + 30KB + 20KB + 10KB) =
140KB.So if we have minimum 140KB size partition then we can run this code very easily.
Overlays driver: -It is the user responsibility to take care of overlaying, the operating system
will not provide anything. Which means the user should write even what part is required in the
1st pass and once the 1st pass is over, the user should write the code to pull out the pass 1 and

91
load the pass 2. That is what is the responsibility of the user, that is known as the Overlays
driver. Overlays driver will just help us to move out and move in the various part of the code.
Swapping
- Swapping is a mechanism in which a process can be swapped temporarily out of main
memory to a backing store, and then brought back into memory for continued execution.
- Backing store is a usually a hard disk drive or any other secondary storage which fast in
access and large enough to accommodate copies of all memory images for all users. It must
be capable of providing direct access to these memory images.
- Major time-consuming part of swapping is transfer time. Total transfer time is directly
proportional to the amount of memory swapped. Let us assume that the user process is of size
100KB and the backing store is a standard hard disk with transfer rate of 1 MB per second.
The actual transfer of the 100K process to or from memory will take.
100KB / 1000KB per second
= 1/10 second
= 100 milliseconds

Figure 21: Swapping

Partitions
partition is a logical division of a hard disk that is treated as a separate unit by operating systems
(OSes) and file systems. The OSes and file systems can manage information on each partition as
if it were a distinct hard drive. This allows the drive to operate as several smaller sections to

92
improve efficiency, although it reduces usable space on the hard disk because of additional
overhead from multiple OSes.
A disk partition manager allows system administrators to create, resize, delete and manipulate
partitions, while a partition table logs the location and size of the partition. Each partition
appears to the OS as a distinct logical disk, and the OS reads the partition table before any other
part of the disk. Once a partition is created, it is formatted with a file system such as:
• NTFS on Windows drives;

• FAT32 and exFAT for removable drives;

• HFS Plus (HFS+) on Mac computers; or

• Ext4 on Linux.
Data and files are then written to the file system on the partition. When users boot the OS in a
computer, a critical part of the process is to give control to the first sector on the hard disk. This
includes the partition table that defines how many partitions will be formatted on the hard disk,
the size of each partition and the address where each disk partition begins. The sector also
contains a program that reads the boot sector for the OS and gives it control so that the rest of the
OS can be loaded into random access memory.
5.4 Paging and segmentation
Paging:
Paging is a method or techniques which is used for non-contiguous memory allocation. It is a
fixed size partitioning theme (scheme). In paging, both main memory and secondary memory are
divided into equal fixed size partitions. The partitions of secondary memory area unit and main
memory area unit known as pages and frames respectively.
Paging is a memory management method accustomed fetch processes from the secondary
memory into the main memory in the form of pages. in paging, each process is split into parts
wherever size of every part is same as the page size. The size of the last half could also be but the
page size. The pages of process area unit hold on within the frames of main memory relying
upon their accessibility.

93
Figure 22: Paging

Segmentation:
Segmentation is another non-contiguous memory allocation scheme like paging. like paging, in
segmentation, process isn’t divided indiscriminately into mounted(fixed) size pages. It is variable
size partitioning theme. like paging, in segmentation, secondary and main memory are not
divided into partitions of equal size. The partitions of secondary memory area unit known as
segments. The details concerning every segment are hold in a table known as segmentation table.
Segment table contains two main data concerning segment, one is Base, which is the bottom
address of the segment and another is Limit, which is the length of the segment. In segmentation,
CPU generates logical address that contains Segment number and segment offset. If the segment
offset is a smaller amount than the limit then the address called valid address otherwise it throws
miscalculation because the address is invalid.
Tip Questions
1. What is Difference between paging and segmentation?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

2. What is the advantage and Disadvantage of swapping?

94
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

5.5 Placement and Replacement policies


Replacement Policies
Basic to the implementation of virtual memory is the concept of demand paging. This means
that the operating system, and not the programmer, controls the swapping of pages in and out of
main memory as they are required by the active processes. When a non-resident page is needed
by a process, the operating system must decide which resident page is to be replaced by the
requested page. The part of the virtual memory which makes this decision is called
the replacement policy.
There are many approaches to the problem of deciding which page to replace but the object is the
same for all--the policy which selects the page that will not be referenced again for the longest
time.
Examples:
First In First Out (FIFO):
• The page to be replaced is the "oldest" page in the memory, the one which was loaded
before all the others
Least Recently Used (LRU):
• The page to be replaced is the one which has not been referenced since all the others have
been referenced
Last In First Out (LIFO):
• The page to be replaced is the one most recently loaded into the memory
Least Frequently Used (LFU):

95
• The page to be replaced is the one used least often of the pages currently in the memory
Optimal (OPT or MIN):
• The page to be replaced is the one that will not be used for the longest period of time.
• This algorithm requires future knowledge of the reference string which is not usually
available. Thus, this policy is used for comparison studies
• The anomalies associated with replacement policies like FIFO have led to the interest in the
policies like LRU which do not suffer from such anomalies. They are known as stack
algorithms.
5.6 Working sets and thrashing
The "working set" is short hand for "parts of memory that the current algorithm is
using" and is determined by which parts of memory the CPU just happens to access. It is totally
automatic to you. If you are processing an array and storing the results in a table, the array and
the table are your working set.
This is discussed because the CPU will automatically store accessed memory in cache, close to
the processor. The working set is a nice way to describe the memory you want stored. If it is
small enough, it can all fit in the cache and your algorithm will run very fast. On the OS level,
the kernel has to tell the CPU where to find the physical memory your application is using
(resolving virtual addresses) every time you access a new page (typically 4k in size) so also you
want to avoid that hit as much as possible.
Thrashing in Operating System
In case, if the page fault and swapping happen very frequently at a higher rate, then the operating
system has to spend more time swapping these pages. This state in the operating system is
termed thrashing. Because of thrashing the CPU utilization is going to be reduced.
Let's understand by an example, if any process does not have the number of frames that it needs
to support pages in active use, then it will quickly page fault. And at this point, the process must
replace some pages. As all the pages of the process are actively in use, it must replace a page that
will be needed again right away. Consequently, the process will quickly fault again, and again,
and again, replacing pages that it must bring back in immediately. This high paging activity by a
process is called thrashing. During thrashing, the CPU spends less time on some actual
productive work spend more time swapping.

96
Figure 23: Thrashing

Causes of Thrashing
Thrashing affects the performance of execution in the Operating system. Also, thrashing results
in severe performance problems in the Operating system. When the utilization of CPU is low,
then the process scheduling mechanism tries to load many processes into the memory at the same
time due to which degree of Multiprogramming can be increased. Now in this situation, there are
more processes in the memory as compared to the available number of frames in the memory.
Allocation of the limited amount of frames to each process.
Whenever any process with high priority arrives in the memory and if the frame is not freely
available at that time, then the other process that has occupied the frame is residing in the frame
will move to secondary storage and after that this free frame will be allocated to higher priority
process.
We can also say that as soon as the memory fills up, the process starts spending a lot of time for
the required pages to be swapped in. Again, the utilization of the CPU becomes low because
most of the processes are waiting for pages. Thus, a high degree of multiprogramming and lack
of frames are two main causes of thrashing in the Operating system.
Effect of Thrashing
At the time, when thrashing starts then the operating system tries to apply either the Global page
replacement Algorithm or the Local page replacement algorithm.
Global Page Replacement
The Global Page replacement has access to bring any page, whenever thrashing found it tries to
bring more pages. Actually, due to this, no process can get enough frames and as a result, the

97
thrashing will increase more and more. Thus, the global page replacement algorithm is not
suitable whenever thrashing happens.
Local Page Replacement
Unlike the Global Page replacement, the local page replacement will select pages which only
belongs to that process. Due to this, there is a chance of a reduction in the thrashing. As it is also
proved that there are many disadvantages of Local Page replacement. Thus, local page
replacement is simply an alternative to Global Page replacement.
Techniques used to handle the thrashing
As we have already told you the Local Page replacement is better than the Global Page
replacement but local page replacement has many disadvantages too, so it is not suggestible.
Thus, given below are some other techniques that are used:
5.7. Caching
Caching is the process of storing data in a separate place (called the cache) such that they could
be accessed faster if the same data is requested in the future. When some data is requested, the
cache is first checked to see whether it contains that data. If data is already in the cache, it is
called a cache hit. Then the data can be retrieved from the cache, which is much faster than
retrieving it from the original storage location. If the requested data is not in the cache, it is
called a cache miss. Then the data needs to be fetched from the original storage location, which
would take a longer time. Caching is used in different places. In the CPU, caching is used to
improve the performance by reducing the time taken to get data from the main memory. In web
browsers, web caching is used to store responses from previous visits to web sites, in order to
make the next visits faster.

98
Discussion Question
1. What is the difference between virtual and physical?
2. What is the difference between virtual memory and virtual storage?
3. Is physical memory the same as RAM?
4. Why is virtual memory larger than physical memory?
5. Why is virtual memory slower than RAM?
6. What are overlays compare swapping and overlays?
7. What is the concept of overlay?
8. What is difference between overlays and virtual memory?
9. What is paging and segmentation explain with example?
10. What is paging in OS?
11. Why is paging used?
12. Why Segmentation is used in OS?
13. Why paging is faster than segmentation?
14. What are the similarities between paging and segmentation?
15. What are the causes of thrashing in OS?
16. What is the Difference between Buffering and Caching in OS?

99
Chapter Six
6. Device Management
Device management is the process of managing the implementation, operation and maintenance
of a physical and/or virtual device. It is a broad term that includes various administrative tools
and processes for the maintenance and upkeep of a computing, network, mobile and/or virtual
device.
Device management generally performs the following:
• Installing device and component-level drivers and related software
• Configuring a device so it performs as expected using the bundled operating system,
business/workflow software and/or with other hardware devices.
• Implementing security measures and processes.
Devices usually refer to physical/hardware devices such as computers, laptops, servers, mobile
phones and more. They could also be virtual, however, such as virtual machines or virtual
switches. In Windows, device management is also an administrative module that is used for
managing or configuring the physical devices, ports and interfaces of a computer or server.
6.1 Characteristics of serial and parallel devices
Serial Transmission
In Serial Transmission, data is sent bit by bit from one computer to another in bi-direction where
each bit has its clock pulse rate. Eight bits are transferred at a time having a start and stop bit
(usually known as a Parity bit), i.e. 0 and 1 respectively. For transmitting data to a longer
distance, serial data cables are used. However, the data transferred in the serial transmission is in
proper order. It consists of a D-shaped 9 pin cable that connects the data in series.

Figure 24: Serial Transmission

100
Serial Transmission has two subclasses synchronous and asynchronous. In asynchronous
transmission, an extra bit is added to each byte so that the receiver is alert about the arrival of
new data. Usually, 0 is a start bit, and 1 is the stop bit. In synchronous transmission, no extra bit
is added rather the data transferred in the form of frames which contains multiple bytes. The
serial transmission system would not be able to work without installing hardware at the sending
and receiving. The hardware residing in the sending and receiving end is capable of converting
the data from the parallel mode (used in the device) to the serial mode (used in the wires).
Parallel Transmission
In Parallel Transmission, various bits are sent together simultaneously with a single clock pulse.
It is a fast way to transmit as it uses many input/output lines for transferring the data.
Furthermore, it is advantageous because it conforms to the underlying hardware also, as the
electronic devices like computer and communication hardware uses parallel circuitry internally.
This is a reason the parallel interface complements the internal hardware well.

Figure 25: Parallel Transmission

The installation and troubleshooting are easier in parallel transmission system due to its
placement in a single physical cable. Parallel Transmission uses a 25 pin port having 17 signal
lines and 8 ground lines. The 17 signal lines are further divided as
• 4 lines that initiate handshaking,
• Status lines used to communicate and notify errors and
• 8 to transfer data.
Despite the speed of the data, the parallel transmission has a limitation called skew where bits
could travel in quite different speeds over the wires.

101
For transferring data between computers, laptops, two methods are used, namely, Serial
Transmission and Parallel Transmission. There are some similarities and dissimilarities between
them. One of the primary differences is that; in Serial Transmission, data is sent bit by bit
whereas, in Parallel Transmission a byte (8 bits) or character is sent at a time. The similarity is
that both are used to connect and communicate with peripheral devices. Furthermore, the parallel
transmission is time-sensitive, whereas serial transmission is not time-sensitive. Other
differences are discussed below.
Both Serial and Parallel Transmission have their advantages and disadvantages, respectively.
Parallel Transmission is used for a limited distance, provides higher speed. On the other hand,
Serial Transmission is reliable for transferring data to longer distance. Hence, we conclude that
both serial and parallel are individually essential for transferring data.
6.2 Buffering strategies
Buffering
In computer system when the speed in which data is received and the speed in which data is
processed are different, then there we use the buffer. Buffer is a memory space which stores the
input data and pass it on to the system according to this speed in this way there is no need to hold
the input device until it is processed. simply the data will be stored in buffer and the used by the
system. The buffer can be of any type, hardware or software, but in general software buffer are
used widely.
Example – In printers spoolers, we can pass a large no of pages to print as input, but the
processing/printing is slow. Here buffering is used.
I/O buffering the process of temporarily storing data that is passing between a processor and a
peripheral. The usual purpose is to smooth out the difference in rates at which the two devices
can handle data.
I/O buffering and its Various Techniques
A buffer is a memory area that stores data being transferred between two devices or between a
device and an application.
Uses of I/O Buffering
✓ Buffering is done to deal effectively with a speed mismatch between the producer and
consumer of the data stream.
✓ A buffer is produced in main memory to heap up the bytes received from modem.

102
✓ After receiving the data in the buffer, the data get transferred to disk from buffer in a single
operation.
✓ This process of data transfer is not instantaneous; therefore, the modem needs another buffer
in order to store additional incoming data.
✓ When the first buffer got filled, then it is requested to transfer the data to disk.
✓ The modem then starts filling the additional incoming data in the second buffer while the
data in the first buffer getting transferred to disk.
✓ When both the buffers completed their tasks, then the modem switches back to the first
buffer while the data from the second buffer get transferred to the disk.
✓ The use of two buffers disintegrates the producer and the consumer of the data, thus
minimizes the time requirements between them.
✓ Buffering also provides variations for devices that have different data transfer sizes.
Types of various I/O buffering techniques
1. Single buffer
A buffer is provided by the operating system to the system portion of the main memory.
Block oriented device
✓ System buffer takes the input.
✓ After taking the input, the block gets transferred to the user space by the process and then
the process requests for another block.
✓ Two blocks work simultaneously, when one block of data is processed by the user process,
the next block is being read in.
✓ OS can swap the processes.
✓ OS can record the data of system buffer to user processes.
Stream oriented device
✓ Line- at a time operation is used for scroll made terminals. User inputs one line at a time,
with a carriage return signaling at the end of a line.
✓ Byte-at a time operation is used on forms mode, terminals when each keystroke is
significant.

103
Figure 26: Single buffer

2. Double buffer
Block oriented
✓ There are two buffers in the system.
✓ One buffer is used by the driver or controller to store data while waiting for it to be taken by
higher level of the hierarchy.
✓ Other buffer is used to store data from the lower-level module.
✓ Double buffering is also known as buffer swapping.
✓ A major disadvantage of double buffering is that the complexity of the process get
increased.
✓ If the process performs rapid bursts of I/O, then using double buffering may be deficient.
Stream oriented
✓ Line- at a time I/O, the user process need not be suspended for input or output, unless
process runs ahead of the double buffer.
✓ Byte- at a time operation, double buffer offers no advantage over a single buffer of twice
the length.

104
Figure 27: Double buffer

3. Circular buffer
✓ When more than two buffers are used, the collection of buffers is itself referred to as a
circular buffer.
✓ In this, the data do not directly pass from the producer to the consumer because the data
would change due to overwriting of buffers before they had been consumed.
✓ The producer can only fill up to buffer i-1 while data in buffer i is waiting to be consumed.

Figure 28: Circular buffer

6.3 Direct memory access


Many devices can temporarily take control of the bus and perform data transfers to (and from)
main memory or other devices. Because the device is doing the work without the help of the
CPU, this type of data transfer is known as direct memory access (DMA). DMA transfers can be
performed between two devices, between a device and memory, or between memory and
memory. This chapter explains transfers between a device and memory only.
Direct memory access (DMA) is a method that allows an input/output (I/O) device to send or
receive data directly to or from the main memory, bypassing the CPU to speed up memory
operations. The process is managed by a chip known as a DMA controller (DMAC). A defined
portion of memory is used to send data directly from a peripheral to the motherboard without
involving the microprocessor, so that the process does not interfere with overall computer
operation.
In older computers, four DMA channels were numbered 0, 1, 2 and 3. When the 16-bit industry
standard architecture (ISA) expansion bus was introduced, channels 5, 6 and 7 were added.

105
ISA was a computer bus standard for IBM-compatible computers, allowing a device to initiate
transactions (bus mastering) at a quicker speed. The ISA DMA controller has 8 DMA channels,
each one of which associated with a 16-bit address and count registers. ISA has since been
replaced by accelerated graphics port (AGP) and peripheral component interconnect (PCI)
expansion cards, which are much faster. Each DMA transfers approximately 2 MB of data per
second. A computer's system resource tools are used for communication between hardware and
software.
The four types of system resources are:
✓ I/O addresses.
✓ Memory addresses.
✓ Interrupt request numbers (IRQ).
✓ Direct memory access (DMA) channels.
DMA channels are used to communicate data between the peripheral device and the system
memory. All four system resources rely on certain lines on a bus. Some lines on the bus are used
for IRQs, some for addresses (the I/O addresses and the memory address) and some for DMA
channels.
A DMA channel enables a device to transfer data without exposing the CPU to a work overload.
Without the DMA channels, the CPU copies every piece of data using a peripheral bus from the
I/O device. Using a peripheral bus occupies the CPU during the read/write process and does not
allow other work to be performed until the operation is completed.
With DMA, the CPU can process other tasks while data transfer is being performed. The transfer
of data is first initiated by the CPU. The data block can be transferred to and from memory by
the DMAC in three ways.
In burst mode, the system bus is released only after the data transfer is completed. In cycle
stealing mode, during the transfer of data between the DMA channel and I/O device, the system
bus is relinquished for a few clock cycles so that the CPU can perform other tasks. When the
data transfer is complete, the CPU receives an interrupt request from the DMA controller. In
transparent mode, the DMAC can take charge of the system bus only when it is not required by
the processor.
However, using a DMA controller might cause cache coherency problems. The data stored in
RAM accessed by the DMA controller may not be updated with the correct cache data if the

106
CPU is using external memory. Solutions include flushing cache lines before starting outgoing
DMA transfers, or performing a cache invalidation on incoming DMA transfers when external
writes are signaled to the cache controller.
6.4 Recovery from failures
Recovery from Failure is a phrase used to describe a need in aviation to continue real-time
operations to a safe conclusion despite a critical part of a system (technical, procedural, or
human) failing, sometimes at the most crucial time.
To maintain high availability of its stored data, ScaleOut StateServer creates up to two replicas
of every stored data object (up to three copies total as determined by
the max_replicas parameter). These replicas are apportioned to other hosts so as to maintain the
overall load-balance. The number of replicas per object depends on the number of available
hosts:

# hosts # replicas per object

1 0

2 1

>2 1 or 2, as specified

All updates to an object are transactionally applied to its replicas using a patented, quorum-based
updating algorithm. When a host fails or suffers a network outage, ScaleOut StateServer uses the
replicas on other hosts to preserve stored data and to provide continued access to the affected
objects. If a host suffers only a brief network outage, it resumes management of its objects once
the outage has been corrected. Otherwise, in a process called self-healing, one of the replica’s
hosts takes over management of each affected object, and an additional replica is created on
another surviving host. (The failed host leaves the store.) Note that a host’s failure only affects
the objects managed by that host; other objects usually remain continuously available during the
recovery process.

107
Detecting Failures
ScaleOut StateServer uses periodic heartbeat packet exchanges between pairs of hosts to detect a
network outage or host failure. To minimize overall networking overhead, ScaleOut StateServer
uses a highly efficient heartbeat algorithm that limits the number of heartbeat exchanges per
second so that overhead grows slowly with the number of hosts. Under normal conditions, the
maximum network bandwidth consumed by a host to send heartbeat packets is less than 1K
bytes/second.
Based on extensive evaluation of IP load balancing on server farms, ScaleOut StateServer uses a
default heartbeat exchange rate of one heartbeat packet per 300 milliseconds. A host reports a
possible outage if twenty consecutive heartbeat packets are not received from a remote host. This
indicates that either one of the hosts has a network outage or the remote host has failed. Once an
outage has been detected, the host begins a recovery process to isolate the problem and recover
from a failure.
The Recovery Process
After a heartbeat failure occurs, all hosts engage in a recovery protocol to establish the currently
responding membership. Hosts that do not respond because of server failures or network outages
are dropped from the membership of the distributed store. This process takes approximately five
to ten seconds after the heartbeat failure occurs. After the new membership is established, the
hosts perform a self-healing process in which:
• the hosts that are determined to have failed are removed from the membership,
• lost copies of stored objects are replicated on other hosts to restore full redundancy (i.e.,
one or two replicas per object for farms with three or more hosts),
• heartbeat exchanges are initiated between appropriate surviving hosts to replace the
terminated exchanges, and
• all hosts rebalance the storage load across the new membership. The self-healing and
dynamic rebalancing process may require a minute or more to replicate the affected objects
on new hosts, and this will temporarily slow the rate at which access requests to the
affected objects can be handled.
ScaleOut StateServer heals its distributed store by creating new replicas for stored objects that
were lost due to a server failure or network outage. This restores the full redundancy of the
distributed store. If two or more servers are removed from the membership during the recovery

108
process, some objects may be permanently lost. In this case, the store will
return object_not_found exceptions for access requests to missing objects. To maintain service
whenever possible, ScaleOut StateServer attempts to self-heal and restore service even if no
copies of an object still exist.
A host which suffers a network outage and cannot reach the network displays the isolated status
and assigns all remote hosts an unknown status. The host suspends all handling of access
requests until the network outage is corrected. This helps to maintain the consistency of stored
data; see Split-Brain Failures below.
A host becomes isolated when its connection to the network switch is unplugged, as shown in the
following diagram. This will cause the host to suspend its handling of access requests, and other
hosts may remove it from the membership. It may not be possible for the ScaleOut service to
detect this condition under all situations, in which case the host will form an independent
membership.

Figure 29: Split-Brain Failures

Once an active host can again reach the network, it determines if it is in the current membership.
Remote hosts may have formed a new membership that excludes the host so that they can
recover from the network outage. In this case, the host automatically restarts the StateServer
service so that the host can rejoin the distributed store. This behavior ensures that an isolated
host does not interfere with other hosts once a new membership has been formed. To enable
recovery from switch failures, ScaleOut StateServer does not automatically restart an isolated
host after it waits for a fixed recovery interval. Instead, it waits indefinitely for the network
outage to be corrected and then determines whether to restart the StateServer service.

109
Question
1. What are the characteristics of parallel data transmission?
2. What is the difference between parallel and Serial?
3. What is the major difference between Serial and parallel data transmission?
4. What are the advantages of parallel and serial transmission?
5. What does use buffering mean?
6. What are the advantages and disadvantages of direct memory access?
7. What is direct memory access with example?
8. What is DMA and its advantages?

Chapter Seven

110
7. Security and protection
7.1. Overview of system security
Security refers to providing a protection system to computer system resources such as CPU,
memory, disk, software programs and most importantly data/information stored in the computer
system. If a computer program is run by an unauthorized user, then he/she may cause severe
damage to computer or data stored in it. So, a computer system must be protected against
unauthorized access, malicious access to system memory, viruses, worms etc. We're going to
discuss following topics in this chapter.
• Authentication
• One Time passwords
• Program Threats
• System Threats
• Computer Security Classifications
Questions
1. What is the difference between protection and security in OS?
2. What are the different ways of ensuring security and protection in a system?
3. Why do we need security?
4. What is the goal of protection and security?

Answer

111
Authentication
Authentication refers to identifying each user of the system and associating the executing
programs with those users. It is the responsibility of the Operating System to create a protection
system which ensures that a user who is running a particular program is authentic. Operating
Systems generally identifies/authenticates users using following three ways −
• Username / Password − User need to enter a registered username and password with
Operating system to login into the system.
• User card/key − User need to punch card in card slot, or enter key generated by key
generator in option provided by operating system to login into the system.
• User attribute - fingerprint/ eye retina pattern/ signature − User need to pass his/her
attribute via designated input device used by operating system to login into the system.
One Time passwords
One-time passwords provide additional security along with normal authentication. In One-Time
Password system, a unique password is required every time user tries to login into the system.
Once a one-time password is used, then it cannot be used again. One-time password is
implemented in various ways.
• Random numbers − Users are provided cards having numbers printed along with
corresponding alphabets. System asks for numbers corresponding to few alphabets
randomly chosen.
• Secret key − User are provided a hardware device which can create a secret id mapped
with user id. System asks for such secret id which is to be generated every time prior to
login.
• Network password − Some commercial applications send one-time passwords to user on
registered mobile/ email which is required to be entered prior to login.
Program Threats
Operating system's processes and kernel do the designated task as instructed. If a user program
made these process do malicious tasks, then it is known as Program Threats. One of the
common examples of program threat is a program installed in a computer which can store and
send user credentials via network to some hacker. Following is the list of some well-known
program threats.

112 | P a g e
•Trojan Horse − Such program traps user login credentials and stores them to send to
malicious user who can later on login to computer and can access system resources.
•Trap Door − If a program which is designed to work as required, have a security hole in
its code and perform illegal action without knowledge of user then it is called to have a
trap door.
•Logic Bomb − Logic bomb is a situation when a program misbehaves only when certain
conditions met otherwise it works as a genuine program. It is harder to detect.
•Virus − Virus as name suggest can replicate themselves on computer system. They are
highly dangerous and can modify/delete user files, crash systems. A virus is generally a
small code embedded in a program. As user accesses the program, the virus starts
getting embedded in other files/ programs and can make system unusable for user
System Threats
System threats refers to misuse of system services and network connections to put user in
trouble. System threats can be used to launch program threats on a complete network called as
program attack. System threats creates such an environment that operating system resources/
user files are misused. Following is the list of some well-known system threats.
•Worm − Worm is a process which can choked down a system performance by using
system resources to extreme levels. A Worm process generates its multiple copies where
each copy uses system resources, prevents all other processes to get required resources.
Worms processes can even shut down an entire network.
•Port Scanning − Port scanning is a mechanism or means by which a hacker can detects
system vulnerabilities to make an attack on the system.
•Denial of Service − Denial of service attacks normally prevent user to make legitimate use
of the system. For example, a user may not be able to use internet if denial of service
attacks browser's content settings.
7.2 Policy/mechanism separation
The separation of mechanism and policy is a design principle in computer science. It states that
mechanisms (those parts of a system implementation that control the authorization of operations
and the allocation of resources) should not dictate (or overly restrict) the policies according to
which decisions are made about which operations to authorize, and which resources to allocate.

113 | P a g e
7.3. Security methods and devices
What is OS Security?
The term operating system (OS) security refers to practices and measures that can ensure the
confidentiality, integrity, and availability (CIA) of operating systems. The goal of OS security is
to protect the OS from various threats, including malicious software such as worms, trojans and
other viruses, misconfigurations, and remote intrusions. OS security typically involves the
implementation of control techniques that can protect your assets from unauthorized
modification and deletion or theft. The most common techniques used to protect operating
systems include the use of antivirus software and other endpoint protection measures, regular OS
patch updates, a firewall for monitoring network traffic, and enforcement of secure access
through least privileges and user controls.
What are Common OS Security Threats?
Here are a few of the most common threat vectors that can affect an operating system.
Malware
Malware is short for malicious software, which encompasses a range of attack vectors such as
viruses, worms, trojans, and rootkits. Malware is injected into a system without the owner’s
consent, or by masquerading as legitimate software, with the objective of stealing, destroying or
corrupting data, or compromising the device.
Malware can also replicate, allowing it to spread further in a corporate network and beyond.
Malware attacks often go undetected by the target user, allowing for the quiet extraction of
sensitive data. In other cases, attackers silently “herd” compromised devices into botnets and use
them for criminal activities such as distributed denial of services (DDoS) attacks.
Denial of Service Attacks
A Denial of Service (DoS) attack is intended to clog a system with fake requests so it becomes
overloaded, and eventually stops serving legitimate requests. Some DoS attacks, in addition to
overwhelming a system’s resources, can cause damage to the underlying infrastructure. Modern
DoS attacks are waged by a distributed network of thousands or millions of bots (automated
agents)—this is known as distributed denial of service (DDoS), and can be extremely difficult to
mitigate due to its huge scale.

114 | P a g e
An example of a DoS attack is the repeated use of system requests in a tight loop, or a “syn
flood” in which the attacker sends a large number of network requests, requiring the server to
acknowledge each one, and exhausting its resources.
Network Intrusion
Network intrusion occurs when an individual gains access to a system for improper use. There
are several types of network intrusion depending on the type of intruder:
• Careless insiders—authorized users who neglect to follow security policies or best practices,
causing exposure of sensitive assets.
• Malicious insiders—authorized users who misuse their privileges for malicious indigence.
• Masqueraders—external individuals who pose as legitimate users, exploiting the account or
credentials of an authorized user to gain access to the system.
• Clandestine users—attackers who penetrate the system by gaining supervisory control and
going around access controls.
Buffer Overflow
The main function of a buffer is to temporarily store data. Each buffer has a capacity of data it
can hold. During a buffer overflow attack, the buffer or other temporary data stores are
overflowing with data. When the buffer overflows, the program attempting to write the data may
overwrite other memory locations containing important information.
Threat actors look for buffer overflow vulnerabilities, which they can exploit to inject scripts that
help them hijack the system or crash it.
How Can You Ensure Operating System Security?
Here are a few ways you can improve operating system security in your organization.
Authentication Measures
Authentication involves matching an identified user with the programs or data they are allowed
to access. All operating systems have controls that can be used to verify that users who run a
particular program are authorized to do so.
You can use the following techniques to authenticate users at the operating system level:
o Security keys: keys are provided by a key generator, usually in the form of a physical
dongle. The user must insert the key into a slot in the machine to log in.
o Username-password combinations: The user enters a username that is registered with the
OS, along with a matching password.

115 | P a g e
o Biometric signatures: The user scans a physical attribute, such as a fingerprint or retina, to
identify themselves.
o Multi-factor authentication: Modern authentication systems use multiple methods to identify
a user, combining something the user knows (credentials), something they own (such as a
mobile device), and/or a physical characteristic (biometrics).
Using One-Time Passwords
One-time passwords offer an additional layer of security when combined with standard
authentication measures. Users must enter a unique password generated each time they log in to
the system. A one-time password cannot be reused.
Examples of one-time passwords include:
• Network passwords: An application sends a one-time password to the users via a registered
email address or mobile phone number. The user must enter this password to log in to the
computer.
• Random numbers: The user receives a card with listing numbers that correspond to matching
letters. The OS requires the user to enter the numbers that match a set of randomly generated
letters.
• Secret keys: The user receives a device that generates secret keys. The user then enters the
secret key into the OS system, which identifies the user credentials associated with the key.
Virtualization
Virtualization enables you to abstract software from hardware, effectively separating the two.
The main advantage of virtualization is that it introduces a high level of efficiency and
flexibility, while providing greater security coverage. There are many types of virtualizations,
including desktop, application, network, server, network, storage, and OS virtualization.
Operating system virtualization is a form of sandboxing. Learn more in our guide to sandboxing
security.
What is OS virtualization?
OS virtualization enables you to multiple isolated user environments using the same OS kernel.
The technology that creates and enables this type of isolation is called a “hypervisor”, which
serves as a layer located between the device and the virtualized resources.

116 | P a g e
The hypervisor manages the virtual machines (VM) running on the device (typically 2-3 Vms).
Each VM is used for each user or each security zone. There are several types of VMs that can
run alongside each other. Here are the three main categories:
Fully locked-down VM
Should be used to provide access to sensitive data and corporate systems, such as IT
environments, payment systems, and sensitive customer data.
Unlocked, open VM
Should be used to provide unrestricted access to non-corporate resources. For example, full web
browsing sessions, installation of applications, and use of external devices.
Semi-locked-down VM
Should be used to provide access to standard corporate applications and resources, such as office
documents, company email, and internal services.
Advantages of OS virtualization
Each type of VM is limited to the actions allowed by design. Any further action is restricted.
This keeps the environment secure. The hypervisor runs below the OS of the device and splits
the device into multiple VMs running locally with their own OS—effectively isolating users.
Because the users are isolated, the devices remain secure. This ensures that employees and third
parties can gain access to company resources without endangering company resources.
Another major advantage of OS virtualization is that none of the virtualized environments can
directly access the network. Instead, connectivity is enabled via an invisible, virtualized network
layer that implements network segmentation directly on the endpoint device.
Testing and Validating Operating System Security
Securing an operating system or any software is an ongoing process that requires constant
testing. Depending on the risk and priority of a system, security posture tests may take place on a
monthly, weekly or daily basis. Here are a few testing methods you can use.
Vulnerability Assessment
Vulnerability assessment involves testing for weaknesses that may be lying undetected in an
operating system. Identifying vulnerabilities allows you to identify possible vectors for an attack
so you can better understand the risk to your system.

117 | P a g e
As part of a continuous process, vulnerability assessment attempts to stay on top of newly
exposed vulnerabilities by locating, classifying and prioritizing them according to severity and
impact. This process usually combines manual tasks with automated tools.
The following are some of the typical methods used for OS vulnerability assessment:
• Scanning for known vulnerabilities
• Scanning the software and applications on an operating system
• Scanning for malware
• Scanning for missing patches and updates
• Patch testing
• Port scanning
Penetration Testing
Penetration testing, or pentesting, is a security assessment strategy that uses vulnerability
assessment to identify how an attacker may successfully exploit vulnerabilities in the system.
The penetration testing method involves simulating an exploit to evaluate system security.
Penetration testing helps discover vulnerabilities beyond the obvious, and seeks to identify the
methods an attacker may use to exploit them. Security teams can leverage the insights provided
by pentesting to put in place effective security measures.
There are three types of penetration testing, each of which provides different types of insights
into operating system security and potential for exploitation:
• White Box: The penetration tester has full technical knowledge of the system being tested.
• Grey Box: The pentester has limited technical knowledge of the system being tested.
• Black Box: The pentester doesn’t have any prior technical knowledge of the system being
tested.
Improving Operating System Security with Hysolate
Hysolate is a full OS isolation solution for Windows10, splitting your endpoint into a more
secure corporate zone and a less secure zone for daily tasks. This means that one OS can be
reserved for corporate access, with strict networking and security policies, and the other can be a
more open zone for accessing untrusted websites and applications.
Hysolate sits on the user endpoint so provides a good UX, but is managed by a granular
management console via the cloud. This means that admins can monitor and control exactly what
their team is using the isolated OS environment for, and it can easily be wiped if threats are

118 | P a g e
detected. Hysolate is easy to deploy, and can be scaled to your entire team, not just the technical
members. Hysolate isolates applications, websites, documents and peripherals, giving you
improved security and manageability.
7.4 Protection, access, and authentication
Authentication mechanism determines the user’s identity before revealing the sensitive
information. It is very crucial for the system or interfaces where the user priority is to protect the
confidential information. In the process, the user makes a provable claim about individual
identity (his or her) or an entity identity. The credentials or claim could be a username,
password, fingerprint etc. The authentication and non-repudiation, kind of issues are handled in
the application layer. The inefficient authentication mechanism could significantly affect the
availability of the service.
Use of Authentication in OS
• Authentication is used by a server when the server needs to know exactly who is accessing
their information or site.
• Authentication is used by a client when the client needs to know that the server is system it
claims to be.
• In authentication, the user or computer has to prove its identity to the server or client.
• Usually, authentication by a server entails the use of a user name and password. Other ways
to authenticate can be through cards, retina scans, voice recognition, and fingerprints.
• Authentication by a client usually involves the server giving a certificate to the client in
which a trusted third party such as Verisign or Thawte states that the server belongs to the
entity (such as a bank) that the client expects it to.
• Authentication does not determine what tasks the individual can do or what files the
individual can see. Authentication merely identifies and verifies who the person or system is.
Example of Authentication:
For example, there is a sender A sending an electronic document to the receiver B over the
internet. How does the system will identify that the sender A has sent a message dedicated to the
receiver B. An intruder C may intercept, modify and replay the document in order trick or steal
the information this type of attack is called fabrication.
In the given situation authentication mechanism ensures two things; first, it ensures that the
sender and receiver are righteous people and it known as data-origin authentication. Secondly, it

119 | P a g e
ensures the security of the established connection between sender and receiver with the help of
secret session key so that it could not be inferred and it is known as peer entity authentication.
Authentication refers to identifying each user of the system and associating the executing
programs with those users. It is the responsibility of the Operating System to create a protection
system which ensures that a user who is running a particular program is authentic. Operating
Systems generally identifies/authenticates users using following three ways
• Username / Password: User need to enter a registered username and password with Operating
system to login into the system.
• User card/key: User need to punch card in card slot, or enter key generated by key generator
in option provided by operating system to login into the system.
• User attribute - fingerprint/ eye retina pattern/ signature: User need to pass his/her attribute
via designated input device used by operating system to login into the system.
Access control for an operating system determines how the operating system implements
accesses to system resources by satisfying the security objectives of integrity, availability, and
secrecy. Such a mechanism authorizes subjects (e.g., processes and users) to perform certain
operations (e.g., read, write) on objects and resources of the OS (e.g., files, sockets).
Protection refers to a mechanism which controls the access of programs, processes, or users to
the resources defined by a computer system. We can take protection as a helper to multi
programming operating system, so that many users might safely share a common logical name
space such as directory or files.
7.5. Models of protection
Protection models represent the protected objects in a system, how users or subjects (their
proxies in the computer system) may request access to them, how access decisions are made, and
how the rules governing access decisions may be altered. The access matrix model is the primary
example of a protection model.
Access Matrix is a security model of protection state in computer system. It is represented as a
matrix. Each cell of matrix represents set of access rights which are given to the processes of
domain means each entry (i, j) defines the set of operations that a process executing in domain Di
can invoke on object Oj.
Access Matrix is a security model of protection state in computer system. It is represented as a
matrix. Access matrix is used to define the rights of each process executing in the domain with

120 | P a g e
respect to each object. The rows of matrix represent domains and columns represent objects.
Each cell of matrix represents set of access rights which are given to the processes of domain
means each entry (i, j) defines the set of operations that a process executing in domain Di can
invoke on object Oj.
According to the above matrix: there are four domains and four objects- three files (F1, F2, F3)
and one printer. A process executing in D1 can read files F1 and F3. A process executing in
domain D4 has same rights as D1 but it can also write on files. Printer can be accessed by only
one process executing in domain D2. The mechanism of access matrix consists of many
policies and semantic properties. Specifically, we must ensure that a process executing in
domain Di can access only those objects that are specified in row i.
Association between the domain and processes can be either static or dynamic. Access matrix
provides an mechanism for defining the control for this association between domain and
processes. When we switch a process from one domain to another, we execute a switch
operation on an object (the domain). We can control domain switching by including domains
among the objects of the access matrix. Processes should be able to switch from one domain
(Di) to another domain (Dj) if and only is a switch right is given to access (i, j).
7.6. Memory protection
Memory protection is a way to manage access rights to the specific memory regions. It is used
by the majority of multi-tasking operating systems. The main goal of the memory protection
appears to be a banning of a process to access the part of memory which is not allocated to that
process. Such bans improve reliability of the programs and operating systems as an error in one
program may not directly affect the memory of other applications. It is important to distinguish
between the general principle of memory protection and ASLR, and NX-bit.
7.7. Encryption
Encryption is a method of securing data by scrambling the bits of a computer's files so that they
become illegible. The only method of reading the encrypted files is by decrypting them with a
key; the key is unlocked with a password.
7.8. Recovery Management
Recovery Management is the process of planning, testing, and implementing the recovery
procedures ad standards required to restore service in the event of a component failure; either by
returning the component to normal operation, or taking alternative actions to restore service.

121 | P a g e
Discussion Questions
5. What are the models of OS security?
6. What are various types of security threats in an operating system?
7. What are the types of security in computer?
8. What are the best security practices?
9. Which is the most secured OS?
10. What is Kerberos Key?
11. What is encryption in operating system?
12. Why is encryption used?
13. What is mean by decrypting?
14. Why Recovery management is important?

Chapter Eight
122 | P a g e
8. File systems
In computing, file system or filesystem is a method and data structure that the operating system
uses to control how data is stored and retrieved. Without a file system, data placed in a storage
medium would be one large body of data with no way to tell where one piece of data stops and
the next begins. By separating the data into pieces and giving each piece a name, the data is
easily isolated and identified. Taking its name from the way paper-based data management
system is named, each group of data is called a file. The structure and logic rules used to manage
the groups of data and their names is called a file system.
8.1 Files: data, metadata, operations, organization, buffering, sequential, non sequential
Metadata
Metadata is data about data. This refers to not the data itself, but rather to any information that
describes some aspect of the data. Everything from the title, information on how data fits
together (e.g., which page goes before which other page), when and by whom the data was
created, and lists of web pages visited by people, can be classified as metadata.
Metadata can be stored in a variety of places. Where the metadata relates to databases, the data is
often stored in tables and fields within the database. Sometimes the metadata exists in a specialist
document or database designed to store such data, called a data dictionary or metadata
repository. There are some types of specialist data files that include both the raw data and the
metadata (e.g., the SPSS .sav data file and .mdd data file, Triple S .sss). More generally,
metadata can be stored anywhere (e.g., in emails, questionnaires, data collection instructions, or
spreadsheets).
Metadata and data analysis
In the context of data analysis, metadata has a more specific meaning. Metadata is the
information that is required for somebody to understand how to interpret and use the data. The
most common types of metadata which are useful for data analysis are: value labels and missing
value codes (the domain), variable labels, variable types, relationship to other data, variable sets,
and, in the case of surveys, change logs, weights, strata, and clusters.

Questions
1. Where is metadata stored?

123 | P a g e
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
2. What is Metadata?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
8.2 Directories: contents and structure
Directory
A directory is a container that is used to contain folders and files. It organizes files and folders
in a hierarchical manner. The directory can be viewed as a symbol table that translates file
names into their directory entries. If we take such a view, we see that the directory itself can be
organized in many ways. The organization must allow us to insert entries, to delete entries, to
search for a named entry, and to list all the entries in the directory.
In this section, we examine several schemes for defining the logical structure of the directory
system. When considering a particular directory structure, we need to keep in mind the
operations that are to be performed on a directory:
•Search for a file. We need to be able to search a directory structure to find the entry for a
particular file. Since files have symbolic names, and similar names may indicate a relationship
among files, we may want to be able to find all files whose names match a particular pattern.
•Create a file. New files need to be created and added to the directory.
•Delete a file. When a file is no longer needed, we want to be able to remove it from the
directory.
•List a directory. We need to be able to list the files in a directory and the contents of the
directory entry for each file in the list.

124 | P a g e
•Rename a file. Because the name of a file represents its contents to its users, we must be able to
change the name when the contents or use of the file changes. Renaming a file may also allow its
position within the directory structure to be changed.
•Traverse the file system. We may wish to access every directory and every file within a
directory structure. For reliability, it is a good idea to save the contents and structure of the entire
file system at regular intervals. Often, we do this by copying all files to magnetic tape. This
technique provides a backup copy in case of system failure. In addition, if a file is no longer in
use, the file can be copied to tape and the disk space of that file released for reuse by another file.
In the following sections, we describe the most common schemes for defining the logical
structure of a directory
Single-Level Directory
The simplest directory structure is the single-level directory. All files are contained in the same
directory, which is easy to support and understand A single-level directory has significant
limitations, however, when the number of files increases or when the system has more than one
user. Since all files are in the same directory, they must have unique names. If two users call
their data filetest.txt, then the unique-name rule is violated. For example, in one programming
class, 23 students called the program for their second assignmentprog2.c; another 11 called it
assign2.c. Fortunately, most file systems support file names of up to 255 characters, so it is
relatively easy to select unique file names. Even a single user on a single-level directory may
find it difficult to remember the names of all the files as the number of files increases. It is not
uncommon for a user to have hundreds of files on one computer system and an equal number of
additional files on another system. Keeping track of so many files is a daunting task.

Figure 30 : Single-level directory

Two-Level Directory

125 | P a g e
As we have seen, a single-level directory often leads to confusion of file names among different
users. The standard solution is to create a separate directory for each user. In the two-level
directory structure, each user has his own user file directory (UFD). The UFDs have similar
structures, but each list only the files of a single user. When a user job starts or a user logs in, the
system’s master file directory (MFD) is searched. The MFD is indexed by user name or account
number, and each entry points to the UFD for that user (Figure below). When a user refers to a
particular file, only his own UFD is searched. Thus, different users may have files with the same
name, as long as all the file names within each UFD are unique. To create a file for a user, the
operating system searches only that user’s UFD to ascertain whether another file of that name
exists. To delete a file, the operating system confines its search to the local UFD; thus, it cannot
accidentally delete another user’s file that has the same name.

Figure 31: Two-level directory structure

Although the two-level directory structure solves the name-collision problem, it still has
disadvantages. This structure effectively isolates one user from another. Isolation is an advantage
when the users are completely independent but is a disadvantage when the users want to
cooperate on some tasks and to access one another’s files. Some systems simply do not allow
local user files to be accessed by other users
Tree-Structured Directories
Once we have seen how to view a two-level directory as a two-level tree, the natural
generalization is to extend the directory structure to a tree of arbitrary height (fig). This
generalization allows users to create their own subdirectories and to organize their files
accordingly. A tree is the most common directory structure. The tree has a root directory, and
every file in the system has a unique path name.
A directory (or subdirectory) contains a set of files or subdirectories. A directory is simply
another file, but it is treated in a special way. All directories have the same internal format. One

126 | P a g e
bit in each directory entry defines the entry as a file (0) or as a subdirectory (1). Special system
calls are used to create and delete directories. In normal use, each process has a current directory.
The current directory should contain most of the files that are of current interest to the process.
When reference is made to a file, the current directory is searched. If a file is needed that is not in
the current directory, then the user usually must either specify a path name or change the current
directory to be the directory holding that file. To change directories, a system call is provided
that takes a directory name as a parameter and uses it to redefine the current directory. Thus, the
user can change her current directory whenever she wants. From one change directory () system
call to the next, all open()system calls search the current directory for the specified file. Note that
the search path may or may not contain a special entry that stands for “the current directory.”
The initial current directory of a user’s login shell is designated when the user job starts or the
user logs in.
The operating system searches the accounting file (or some other predefined location) to find an
entry for this user (for accounting purposes). In the accounting file is a pointer to (or the name
of) the user’s initial directory. This pointer is copied to a local variable for this user that specifies
the user’s initial current directory. From that shell, other processes can be spawned. The current
directory of any subprocess is usually the current directory of the parent when it was spawned.
Path names can be of two types: absolute and relative.
An absolute path name begins at the root and follows a path down to the specified file, giving
the directory names on the path. A relative path name defines a path from the current directory.
For example, in the tree-structured file system of Figure, if the current directory is
root/spell/mail, then the relative path nameprt/firstrefers to the same file as does the absolute
path name root/spell/mail/prt/first.

Figure 32: Tree-structured directory structure

127 | P a g e
Question
1. What is difference between file and directory?
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

8.3 File systems: partitioning, mount/unmount, and virtual file systems


Partition
A partition is a logical division of a hard disk that is treated as a separate unit by operating
systems (OSes) and file systems. The OSes and file systems can manage information on each
partition as if it were a distinct hard drive. This allows the drive to operate as several smaller
sections to improve efficiency, although it reduces usable space on the hard disk because of
additional overhead from multiple OSes.
A disk partition manager allows system administrators to create, resize, delete and manipulate
partitions, while a partition table logs the location and size of the partition. Each partition
appears to the OS as a distinct logical disk, and the OS reads the partition table before any other
part of the disk. Once a partition is created, it is formatted with a file system such as:
• NTFS on Windows drives;
• FAT32 and exFAT for removable drives;
• HFS Plus (HFS+) on Mac computers; or
• Ext4 on Linux.
Data and files are then written to the file system on the partition. When users boot the OS in a
computer, a critical part of the process is to give control to the first sector on the hard disk. This
includes the partition table that defines how many partitions will be formatted on the hard disk,
the size of each partition and the address where each disk partition begins. The sector also
contains a program that reads the boot sector for the OS and gives it control so that the rest of the
OS can be loaded into random access memory.
A key aspect of partitioning is the active or bootable partition, which is the designated partition
on the hard drive that contains the OS. Only the partition on each drive that contains the boot
loader for the OS can be designated as the active partition. The active partition also holds the

128 | P a g e
boot sector and must be marked as active. A recovery partition restores the computer to its
original shipping condition. In enterprise storage, partitioning helps enable short stroking, a
practice of formatting a hard drive to speed performance through data placement.

Figure 33: Disk partitioning

A partition is a logical division of a hard disk that is treated as a separate unit by operating
systems (OSes) and file systems. Each partition appears to the OS as a distinct logical disk, and
the OS reads the partition table before any other part of the disk.

Partitioning and its types


There are three types of partitions: primary partitions, extended partitions and logical drives. A
disk may contain up to four primary partitions (only one of which can be active), or three
primary partitions and one extended partition.
Disk partitioning
Disk partitioning or disk slicing is the creation of one or more regions on secondary storage, so
that each region can be managed separately. These regions are called partitions. It is typically the
first step of preparing a newly installed disk, before any file system is created. The disk stores
the information about the partitions' locations and sizes in an area known as the partition table

129 | P a g e
that the operating system reads before any other part of the disk. Each partition then appears to
the operating system as a distinct "logical" disk that uses part of the actual disk. System
administrators use a program called a partition editor to create, resize, delete, and manipulate the
partitions. Partitioning allows the use of different filesystems to be installed for different kinds of
files. Separating user data from system data can prevent the system partition from becoming full
and rendering the system unusable. Partitioning can also make backing up easier. A disadvantage
is that it can be difficult to properly size partitions, resulting in having one partition with too
much free space and another nearly totally allocated.
Mounting and Unmounting File Systems
Before you can access the files on a file system, you need to mount the file system. When you
mount a file system, you attach that file system to a directory (mount point) and make it
available to the system. The root (/) file system is always mounted. Any other file system can be
connected or disconnected from the root (/) file system. When you mount a file system, any files
or directories in the underlying mount point directory are unavailable as long as the file system is
mounted. These files are not permanently affected by the mounting process, and they become
available again when the file system is unmounted. However, mount directories are typically
empty, because you usually do not want to obscure existing files.
For example, the following figure shows a local file system, starting with a root (/) file system
and the sbin, etc, and opt subdirectories.

Figure 34: Sample root (/) File System

130 | P a g e
To access a local file system from the /opt file system that contains a set of unbundled products,
you must do the following:
 First, you must create a directory to use as a mount point for the file system you want to
mount, for example, /opt/unbundled.
 Once the mount point is created, you can mount the file system (by using
the mount command), which makes all of the files and directories
in /opt/unbundled available, as shown in the following figure.

Figure 35: Mounting a File System


The NFS Environment
NFS is a distributed file system service that can be used to share resources (files or directories)
from one system, typically a server, with other systems on the network. For example, you might
want to share third-party applications or source files with users on other systems.
NFS makes the actual physical location of the resource irrelevant to the user. Instead of placing
copies of commonly used files on every system, NFS allows you to place one copy on one
system's disk and let all other systems access it from the network. Under NFS, remote files are
virtually indistinguishable from local ones.

131 | P a g e
A system becomes an NFS server if it has resources to share on the network. A server keeps a list
of currently shared resources and their access restrictions (such as read/write or read-only
access). When you share a resource, you make it available for mounting by remote systems.
You can share a resource in these ways:
• By using the share or shareall command
• By adding an entry to the /etc/dfs/dfstab (distributed file system table) file and rebooting
the system.

Virtual File System


An operating system can have multiple file systems in it. Virtual File Systems are used to
integrate multiple file systems into an orderly structure. The key idea is to abstract out that part
of the file system that is common to all file systems and put that code in a separate layer that
calls the underlying concrete file system to actually manage the data.
Structure of Virtual File Systems in UNIX system:

Figure 36: Virtual File System

The VFS also has a 'lower' interface to the concrete file systems, which is labeled VFS
interface. This interface consists of several dozen function calls that the VFS can make
to each file system to get work done. VFS has two distinct interfaces: the upper one to the

132 | P a g e
user processes and the lower one to the concrete file systems. VFS supports remote file
systems using the NFS (Network File System) protocol.
Question
1. What is the purpose of partitioning?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

2. Which is memory and virtual file system?


______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
____________________________________
3. What is VFS in operating system?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

8.4 Standard implementation techniques


File system implementation defines how files and directories are stored, how disk space is
managed, and how to make everything work efficiently and reliably.

133 | P a g e
Figure 37: File-System Layout

File Systems are stored on disks. The above figure depicts a possible File-System Layout.
MBR: Master Boot Record is used to boot the computer
Partition Table: Partition table is present at the end of MBR. This table gives the starting and
ending addresses of each partition.
Boot Block: When the computer is booted, the BIOS reads in and executes the MBR. The first
thing the MBR program does is locate the active partition, read in its first block, which is called
the boot block, and execute it. The program in the boot block loads the operating system
contained in that partition. Every partition contains a boot block at the beginning though it does
not contain a bootable operating system.
Super Block: It contains all the key parameters about the file system and is read into memory
when the computer is booted or the file system is first touched.
File Allocation Methods
The direct-access nature of disks gives us flexibility in the implementation of files. In almost
every case, many files are stored on the same disk. The main problem is how to allocate space to
these files so that disk space is utilized effectively and files can be accessed quickly. Three major
methods of allocating disk space are in wide use: contiguous, linked, and indexed. Each method
has advantages and disadvantages. Although some systems support all three, it is more common
for a system to use one method for all files within a file-system type.
4. Contiguous Allocation
Contiguous Allocation: Each file is stored as a contiguous run of disk blocks.
Example:

134 | P a g e
 On a disk with 1KB blocks, a 50KB file would be allocated 50 consecutive blocks. With
2KB blocks it would be 25 consecutive blocks. Each file begins at the start of a new block, so
that if file A is occupying 3½ blocks, some space is wasted at the end of the last block.
Advantages:
 Simple to implement.
 The read performance is excellent because the entire file can be read from the disk in a single
operation.
Drawbacks:
 Over the course of time the disk becomes fragmented.
Contiguous allocation requires that each file occupy a set of contiguous blocks on the disk. Disk
addresses define a linear ordering on the disk. With this ordering, assuming that only one job is
accessing the disk, accessing block b+ 1 after block b normally requires no head movement.
When head movement is needed (from the last sector of one cylinder to the first sector of the
next Cylinder), the head need only move from one track to the next. Thus, the number of disk
seeks required for accessing contiguously allocated files is minimal, as is seek time when a seek
is finally needed.
Contiguous allocation of a file is defined by the disk address and length (in block units) of the
first block. If the file is n blocks long and starts at location b, then it occupies blocks b, b+1,b+ 2,
...,b+n−1. The directory entry for each file indicates the address of the starting block and the
length of the area allocated for this file

Accessing a file that has been allocated contiguously is easy. For sequential access, the file
system remembers the disk address of the last block referenced and, when necessary, reads the
next block

135 | P a g e
Figure 38: Contiguous allocation of disk space

File that starts at block b, we can immediately access block b+i. Thus, both sequential and direct
access can be supported by contiguous allocation. Contiguous allocation has some problems,
however. One difficulty is finding space for a new file. The system chosen to manage free space
determines how this task is accomplished; these management systems are discussed in. Any
management system can be used, but some are slower than others.
The contiguous-allocation problem can be seen as a particular application of the general dynamic
storage-allocation problem which involves how to satisfy a request of size n from a list of free
holes. First fit and best fit are the most common strategies used to select a free hole from the set
of available holes. Simulations have shown that both first fit and best fit are more efficient than
worst fit in terms of both time and storage utilization. Neither first fit nor best fit is clearly best in
terms of storage utilization, but first fit is generally faster.
All these algorithms suffer from the problem of external fragmentation. As files are allocated and
deleted, the free disk space is broken into little pieces. External fragmentation exists whenever
frees pace is broken into chunks. It becomes a problem when the largest contiguous chunk is
insufficient for a request; storage is fragmented into a number of holes, none of which is large
enough to store the data. Depending on the total amount of disk storage and the average file size,
external fragmentation may be a minor or a major problem. One strategy for preventing loss of
significant amounts of disk space to external fragmentation is to copy an entire file system onto
another disk. The original disk is then freed completely, creating one large contiguous free space.

136 | P a g e
We then copy the files back onto the original disk by allocating contiguous space from this one
large hole. This scheme effectively compacts all free space
In to one contiguous space, solving the fragmentation problem
5. Linked Allocation Linked List Allocation:
The second method for storing files is to keep each one as a linked list of disk blocks. The first
word of each block is used as a pointer to the next one. The rest of the block is for data. Unlike
Contiguous allocation no space is lost in disk fragmentation.

Figure 39: Linked Allocation

Random access of a file is very slow.


Linked-List Allocation Using a Table in Memory
The disadvantage of linked list can be overcome by taking the pointer word from each disk block
and putting it in a table in memory. Such a table in main memory is called a FAT (File
Allocation Table). Using FAT random access can be made much easier. The primary
disadvantage of this method is that the entire table must be in memory all the time to make it
work.
I-nodes: I-node is a data structure which is used to identify which block belongs to which file. It
contains the attributes and disk addresses of the file's blocks. Unlike the in-memory table the i-
node need to be in memory only when the corresponding file is open.

137 | P a g e
Figure 40: Linked-List Allocation

Linked allocation solves all problems of contiguous allocation. With linked allocation, each file
is a linked list of disk blocks; the disk blocks may be scattered anywhere on the disk. The
directory contains a pointer to the first and last blocks of the file. For example, a file of five
blocks might start at block 9 and continue at block 16, then block 1, then block 10, and finally
block 25
(Fig below). Each block contains a pointer to the next block. These pointers are not made
available to the user. Thus, if each block is 512 bytes in size, and a disk address (the pointer)
requires 4 bytes, then the user sees blocks of 508 bytes.

Figure 41: Linked allocation of disk space

3.Indexed Allocation
138 | P a g e
Linked allocation solves the external-fragmentation and size-declaration problems of contiguous
allocation. However, in the absence of a FAT, linked allocation cannot support efficient direct
access, since the pointers to the blocks are scattered with the blocks themselves all over the disk
and must be retrieved in order. Indexed allocation solves this problem by bringing all the
pointers together into one location in the index block.
Indexed allocation supports direct access, without suffering from external fragmentation, because
any free block on the disk can satisfy a request for more space. Indexed allocation does suffer
from wasted space, however. The pointer overhead of the index block is generally greater than
the pointer overhead of linked allocation. Consider a common case in which we have a file of
only one or two blocks. With linked allocation, we lose the space of only one pointer per
block. With indexed allocation, an entire index block must be allocated, even if only one or two
pointers will be non-null.

Figure 42: Indexed allocation of disk space

This point raises the question of how large the index block should be. Every file must have an
index block, so we want the index block to be as small as possible. If the index block is too
small, however, it will not be able to hold enough pointers for a large file, and a mechanism will
have to be available to deal with this issue
Each file has its own index block, which is an array of disk-block addresses. The ith entry in the
index block points to the ith block of the file. The directory

139 | P a g e
Figure 43: File-allocation table

8.5 Memory-mapped files


A memory-mapped file contains the contents of a file in virtual memory. This mapping between
a file and memory space enables an application, including multiple processes, to modify the file
by reading and writing directly to the memory. You can use managed code to access memory-
mapped files in the same way that native Windows functions access memory-mapped files, as
described in Managing Memory-Mapped Files. There are two types of memory-mapped files:
Persisted memory-mapped files
Persisted files are memory-mapped files that are associated with a source file on a disk. When
the last process has finished working with the file, the data is saved to the source file on the disk.
These memory-mapped files are suitable for working with extremely large source files.
Non-persisted memory-mapped files
Non-persisted files are memory-mapped files that are not associated with a file on a disk. When
the last process has finished working with the file, the data is lost and the file is reclaimed by
garbage collection. These files are suitable for creating shared memory for inter-process
communications (IPC).
Processes, Views, and Managing Memory
Memory-mapped files can be shared across multiple processes. Processes can map to the same
memory-mapped file by using a common name that is assigned by the process that created the
file. To work with a memory-mapped file, you must create a view of the entire memory-mapped
file or a part of it. You can also create multiple views to the same part of the memory-mapped
file, thereby creating concurrent memory. For two views to remain concurrent, they have to be

140 | P a g e
created from the same memory-mapped file. Multiple views may also be necessary if the file is
greater than the size of the application's logical memory space available for memory mapping (2
GB on a 32-bit computer).
There are two types of views: stream access view and random access view. Use stream access
views for sequential access to a file; this is recommended for non-persisted files and IPC.
Random access views are preferred for working with persisted files.
Memory-mapped files are accessed through the operating system's memory manager, so the file
is automatically partitioned into a number of pages and accessed as needed. You do not have to
handle the memory management yourself.
The following illustration shows how multiple processes can have multiple and overlapping
views to the same memory-mapped file at the same time.
The following image shows multiple and overlapped views to a memory-mapped file:

Figure 44: multiple and overlapped views to a memory-mapped file

Questions
1. What do you mean by mapping files into memory?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

141 | P a g e
______________________________________________________________________________
______________________________________________________________________________
2. What is memory mapped files and what are the advantages?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

8.6 Special Purpose File System


FAT file systems are commonly found on floppy disks, flash memory cards, digital cameras, and
many other portable devices because of their relative simplicity. Performance of FAT compares
poorly to most other file systems as it uses overly simplistic data structures, making file
operations time-consuming, and makes poor use of disk space in situations where many small
files are present. ISO 9660 and Universal Disk Format are two common formats that target
Compact Discs and DVDs. Mount Rainier is a newer extension to UDF supported by Linux 2.6
series and Windows Vista that facilitates rewriting to DVDs in the same fashion as has been
possible with floppy disks.
8.7 Naming, searching, access, backups
File Access Methods
Files store information. When it is used, this information must be accessed and read into
computer memory. The information in the file can be accessed in several ways. Some systems
provide only one access method for files. While others support many access methods, and
choosing the right one for a particular application is a major design problem.
1. Sequential file Access
The simplest access method is sequential access. Information in the file is processed in order,
one record after the other. This mode of access is by far the most common; for example, editors

142 | P a g e
and compilers usually access files in this fashion. Reads and writes make up the bulk of the
operations on a file. A read operation—read next ()—reads the next portion of the file and
automatically advances a file pointer, which tracks the I/O location. Similarly, the write
operation—write next ()—appends to the end of the file and advances to the end of the newly
written material (the new end of file). Such a file can be reset to the beginning, and on some
systems, a program may be able to skip forward or backward n records for some integer—
perhaps only for n= 1. Sequential access, which is depicted in Figure below, is based on a tape
model of a file and works as well on sequential-access devices as it does on random-access ones.

Figure 45:Sequential file Access

2. Direct Access
Another method is direct access (or relative access). Here, a file is made up of fixed-length
logical records that allow programs to read and write records rapidly in no particular order. The
direct-access method is based on a disk model of a file, since disks allow random access to any
file block. For direct access, the file is viewed as a numbered sequence of blocks or records.
Thus, we may read block 14, then read block 53, and then write block 7. There are no restrictions
on the order of reading or writing for a direct-access file.
Direct-access files are of great use for immediate access to large amounts of information.
Databases are often of this type. When a query concerning a particular subject arrives, we
compute which block contains the answer and then read that block directly to provide the desired
information.
As a simple example, on an airline-reservation system, we might store all the information about a
particular flight (for example, flight 713) in the block identified by the flight number. Thus, the
number of available seats for flight 713 is stored in block 713 of the reservation file. To store
information about a larger set, such as people, we might compute a hash function on the people’s

143 | P a g e
names or search a small in-memory index to determine a block to read and search. For the direct-
access method, the file operations must be modified to include the block number as a parameter.
Thus, we have read (n), where n is the block number, rather than read next(),and write(n) rather
than write next(). An alternative approach is to retain read next () and write next(), as with
sequential access, and to add an operation position file(n) where n is the block number. Then, to
effect a read(n), we would position file(n )and then read next(). The block number provided by
the user to the operation
File Attributes
A file is named, for the convenience of its human users, and is referred to by its name. A name is
usually a string of characters, such as example.c. Some systems differentiate between uppercase
and lowercase characters in names, whereas other systems do not. When a file is named, it
becomes independent of the process, the user, and even the system that created it. For instance,
one user might create the file example.c, and another user might edit that file by specifying its
name. The file’s owner might write the file to a USB disk, send it as an e-mail attachment, or
copy it across a network, and it could still be called example. On the destination system.
A file’s attributes vary from one operating system to another but typically consist of these:
•Name. The symbolic file name is the only information kept in human readable form.
•Identifier. This unique tag, usually a number, identifies the file within the file system; it is the
non-human-readable name for the file.
•Type. This information is needed for systems that support different types of files.
•Location. This information is a pointer to a device and to the location of the file on that device.
•Size. The current size of the file (in bytes, words, or blocks) and possibly the maximum allowed
size are included in this attribute.
•Protection. Access-control information determines who can do reading, writing, executing, and
so on.
time, date, and user identification. This information may be kept for creation, last
modification, and last use. These data can be useful for protection, security, and usage
monitoring.
File Operations
A file is an abstract data type. To define a file properly, we need to consider the operations that
can be performed on files. The operating system can provide system calls to create, write, read,

144 | P a g e
reposition, delete, and truncate files. Let’s examine what the operating system must do to
perform each of these six basic file operations. It should then be easy to see how other similar
operations, such as renaming a file, can be implemented.
•Creating a file. Two steps are necessary to create a file. First, space in the file system must be
found for the file. an entry for the new file must be made in the directory.
•Writing a file. To write a file, we make a system call specifying both the name of the file and
the information to be written to the file. Given the name of the file, the system searches the
directory to find the file’s location. The system must keep a write pointer to the location in the
file where the next write is to take place. The write pointer must be updated whenever a write
occurs.
•Reading a file. To read from a file, we use a system call that specifies the name of the file and
where (in memory) the next block of the file should be put. Again, the directory is searched for
the associated entry, and the system needs to keep a read pointer to the location in the file where
the next read is to take place. Once the read has taken place, the read pointer is updated. Because
a process is usually either reading from or writing to a file, the current operation location can be
kept as a per-process current file-position pointer. Both the read and write operations use this
same pointer, saving space and reducing system complexity.
•Repositioning within a file. The directory is searched for the appropriate entry, and the current-
file-position pointer is repositioned to a given value. Repositioning within a file need not involve
any actual I/O. This file operation is also known as a file seeks.
•Deleting a file. To delete a file, we search the directory for the named file. Having found the
associated directory entry, we release all file space, so that it can be reused by other files, and
erase the directory entry.
•Truncating a file. The user may want to erase the contents of a file but keep its attributes.
Rather than forcing the user to delete the file and then recreate it, this function allows all
attributes to remain unchanged—except for file length—but lets the file be reset to length zero
and its file space released.
Backup
A system backup is the process of backing up the operating system, files and system specific
useful/essential data. Backup is a process in which the state, files and data of a computer system
are duplicated to be used as a backup or data substitute when the primary system data is

145 | P a g e
corrupted, deleted or lost. There are mainly three types of backups are there: Full backup,
differential backup, and incremental backup. Let's take a look at each type of backup and its
respective pros and cons.
System backup primarily ensures that not only the user data in a system is saved, but also the
system's state or operational condition. This helps in restoring the system to the last saved state
along with all the selected backup data. Generally, the system backup is performed through
backup software and the end file (system backup) generated through this process is known as the
system snapshot/image. Moreover, in a networked/enterprise environment, the system backup
file/snapshot/image is routinely uploaded and updated on an enterprise local/remote storage
server.
Evolution of backup
Backup techniques have evolved over time and become increasingly sophisticated (and perhaps
complex as a result). Considerations such as time taken for backup, time taken for restores,
storage costs, network bandwidth savings, etc. –have all, over time, driven innovations that have
been designed to make backups better – but also increase complexity as a result.
Types of Backups: Full, Differential, and Incremental Backup
Full backup
They are the simplest form of backup and the easiest to understand. Full backup essentially
makes a backup of everything you wish to protect every time. So, all files, objects, bytes
however you wish to measure your data – every one of them is copied over to a secondary
storage target each time. If you perform a full backup once a day – then everything is copied
over once a day. Let’s take an example – say you have 4 files A, B, C, and D. And let’s say each
of them is about 1GB each and each of them takes 10 mins to backup.

• On Day 1 – you’ll backup 4GB and it’ll take you 40 mins


• On Day 2, let’s say File B changes to B1, and a new File called E is added. A-C & D remain
the same.
• When you run the backup on Day 2, it’ll backup all 5 files and it’ll take you 50mins
• One Day 3, let’s say File B changes again and becomes B2. File C also changes to C1, and
File D gets deleted.
• When you run the backup on Day 3, it’ll backup 4 files again (D is removed remember?) and
it’ll take you 40 mins.

146 | P a g e
Figure 46: Full backup

When you restore, you will most likely get data from the latest backup and it’ll take you 40 mins
to restore.
Differential backup
Full backups, as you can see take time. 40 minutes – 50 minutes each day as in our example.
The next optimization the industry made was a differential backup. Differential backup makes a
copy of files that have changed since the full backup.
Let’s take the same example – say you have 4 files A, B, C, and D. And let’s say each of them is
about 1GB each and each of them takes 10 mins to backup
• On Day 1 – you’ll backup 4GB and it’ll take you 40 mins
• On Day 2, let’s say File B changes to B1, and a new File called E is added. Files A, C & D
stay the same.
• When you run the backup on Day 2, it’ll backup just the 2 changed files and the backup will
take you 20mins
• One Day 3, let’s say File B changes again and becomes B2. File C also changes to C1 and
File D gets deleted.
• When you run the backup on Day 3, it’ll backup 3 files (B2, C1, and E) and it’ll take you 30
mins. Why did we backup E? Remember a differential backup picks up everything that
changed since the full backup.

147 | P a g e
Figure 47: Differential backup

When you restore data, just like in the previous case you’ll need to restore the Full backup first
and then layer in each incremental backup on top of that – in order. So, while we have been able
to improve backup speeds progressively, we have traded off restore times in each of the above
cases.
It is for this reason that traditional types of backup strategies recommend doing a full backup at
frequent points in time – weekly, monthly, quarterly, yearly, etc. The idea is to ensure that
you’re able to keep restore times in check. If you’re able to start the restore from a recent full
backup, then the number of subsequent backups to restore and overlay on top of it are limited –
thus saving time.
But modern, enterprise-class backup technology has progressed further than this and will allow
you to have the best of both worlds. Fast incremental backups and fast restores. The secret is
something called cataloging.
Incremental backup
But if you think about it, differential backup has the potential to keep getting bigger and take
longer and longer each day. After all, they’re backing up all changes since the full backup. So,
there could come a point where a daily differential backup is taking as much time as a full
backup (or perhaps more). Enter the next innovation – incremental backup. Incremental backup
only backup what was changed since the last backup. Sounds efficient right?
Let’s look at this with the same example:
So, you have 4 files A, B, C, and D. And let’s say each of them is about 1GB each and each of
them takes 10 mins to backup.

148 | P a g e
• On Day 1 – you’ll backup 4GB and it’ll take you 40 mins
• On Day 2, let’s say File B changes to B1, and a new File called E is added.
• When you run the backup on Day 2, it’ll backup just the 2 changed files – and it’ll take you
20 mins
• One Day 3, let’s say File B changes again to B2. File C also changes to C1 and File D gets
deleted.
• When you run the backup on Day 3, it’ll backup just the 2 files again (B2 and C1) (D is
removed – remember?) and it’ll take you 20 mins

Figure 48: Incremental backup

Let’s see what happens when you restore. When you restore data, just like in the previous case –
you’ll need to restore the Full backup first – and then layer in each incremental backup on top of
that – in order.
If you wish to get back the latest copy of data, it’ll take us 80 mins to restore – that 40 + 20 +
20. So, not great from a restore standpoint.
So, while we have been able to improve backup speeds progressively, we have traded off restore
times in each of the above cases.
It is for this reason that traditional types of backup strategies recommend doing a full backup at
frequent points in time – weekly, monthly, quarterly, yearly, etc. The idea is to ensure that
you’re able to keep restore times in check. If you’re able to start the restore from a recent full
backup, then the number of subsequent backups to restore and overlay on top of it are limited –
thus saving time.

149 | P a g e
But modern, enterprise-class backup technology has progressed further than this – and will allow
you to have the best of both worlds. Fast incremental backups and fast restores. The secret is
something called cataloging.
Modern enterprise class backup technology has progressed further and now offers best of both
the worlds – Fast incremental backups and fast restores. The secret is something
called Cataloging.
Cataloging is a meta-data – i.e., data about your data. In each of the above cases, our backups
were self-describing. There is no additional information required to restore from any of those
backups.
But meta-data describes data – it can contain interesting information about file versions, about
locations on media files, are kept, etc. – which can dramatically improve restore performance.
Let’s try the same example – this time with cataloging.
So, you have 4 files A, B, C, and D. And let’s say each of them is about 1GB each and each of
them takes 10 mins to backup
• On Day 1 – you’ll backup 4GB and it’ll take you 40 mins
• On Day 2, let’s say File B changes to B1 and a new File called E is added.
• When you run the backup on Day 2, it’ll backup just the 2 changed files – and it’ll take you
20 mins
• One Day 3, let’s say File B changes again to B2. File C also changes to C1, and File D gets
deleted.
• When you run the backup on Day 3, it’ll backup just the 2 files again (B2 and C1) (D is
removed – remember?) and it’ll take you 20 mins
Now, when you restore, the catalog will supply you the latest version of each file automatically –
So A, B2, C1 and E. In 40 minutes. And you’ll not even bother bringing back D because the
catalog knows it was deleted.
Modern backup software keeps a meta-data catalog which remembers which version of which
file is present in which backup – and allows a smart way of bringing back just the data that you
need on a restore. This way – one doesn’t have to start with a full backup and layer each
incremental on top. You can get the latest versions of all files in a single go. When you have the
strength of data cataloging working for you – you don’t need to run full backup over and over

150 | P a g e
again. You can run incremental backup forever.

Figure 49: Modern backup

Synthetic Full backup


A number of backup solutions now also offer a synthesized full backup. This is usually meant to
satisfy archaic backup policies (that are still extant) which dictate that one should have a full
backup available each week/month/year etc.
Rather than take the hit of running a full backup each week, month, or year – which is
technically unnecessary – modern backup software offers to “synthesize a full” backup for you.
It is the equivalent of running a restore of all your latest file versions – but rather than actually
restore the data, it re-records the meta-data as if to show that these files got backed up again. It
is a neat trick that doesn’t require any data movement – but simply adds/updates meta-data
records.

151 | P a g e
Figure 50:Synthetic Full backup

But what of real changes that may have occurred on the data source since the last incremental
backup? Not a problem – just couple the synthesized full with an incremental backup that runs
just before the synthesized full, and you’re good to go.
Know your backups
Backups are a necessary part of any good IT Administrator’s toolkit. Having a solid backup
strategy makes life a lot simpler and allows Administrators to focus on things that need their
attention instead of having to be in “crisis” mode all the time. Understanding how they work
makes an IT administrator’s job that much easier.
SEARCHING
As the number of files in your folders increases, browsing through folders becomes a
cumbersome way of looking for files. However, you can find the file you need from among
thousands of photos, texts and other files by using the search function of your operating system.
The search function allows you to look for files and folders based on file properties such as the
file name, save date or size. The search function allows you to look for files and folders based on
file properties such as the file name, save date or size.
In Windows, you can search for files quickly by clicking the Start button at the bottom left of the
screen. Then, simply type the full or partial name of the file, program or folder.
The search begins as soon as you start typing, and the results will appear above the search field.
If the file or program you are looking for does not appear right away, wait a moment, as the
search can take a while. Also note that the search results are grouped by file type.
If you are unable to find the file you are looking for by using the quick search, you can narrow
the search results by file type by clicking the icons above the search term. You can narrow down
your search results to: apps, settings, documents, folders, photos, videos and music.
Let's say you recently downloaded a few photos that were attached to an email message, but now
you're not sure where these files are on your computer. If you're struggling to find a file, you can
always search for it. Searching allows you to look for any file on your computer.
To do this, click the Spotlight icon in the top-right corner of the screen, then type the file
name or keywords in the search box. The search results will appear as you type. Simply click a
file or folder to open it. If you're using the search option, try using different terms in your search.

152 | P a g e
For example, if you're looking for a certain Microsoft Word document, try searching for a few
different file names you might have used when saving the document.
Questions
1. What is searching file and folder?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
2. Why do we need to backup files?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

3. What is the basic difference of the access methods?


___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

153 | P a g e
Reference

1. Andrew S. Tanenbaum (1992) Modern Operating Systems. Prentice-Hall International Inc.


2. Operating Systems, 4th edition by W. Stalling (editor) Prentice-Hall 2001
3. Distributed Systems: Concepts and Design (3rd edition), George Coulouris, Jean
4. Dollimore and Tim Kindberg, Addison Wesley Longman, 2000.
5. Distributed Programming with Java, Qusay H. Mahmoud, Manning Publications Co., 2000.
6. Distributed Systems: Principles and Paradigms, Andrew S. Tanenbaum
7. "A Model-Based Approach for Robustness Testing"(PDF). Dl.ifip.org.Retrieved 2016-11-13.
8. Baker, Jack W.; Schubert, Matthias; Faber, Michael H. (2008). "On the assessment of
robustness" (PDF). Structural Safety. 30 (3): 253–267. doi:10.1016/j.strusafe.2006.11.004.
Retrieved 2016-11-13.

154 | P a g e

You might also like