Os Material

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 145

lOMoARcPSD|17594797

OS Unit-1- Introduction

Operating Systems (Osmania University)

StuDocu is not sponsored or endorsed by any college or university


Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)
lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

UNIT-I
INTRODUCTION
Operating System acts as an intermediary between the user of a computer and the computer
hardware. The purpose of an operating system is to provide an environment in which a user
can execute programs in a convenient and efficient manner.
 Mainframe operating systems are designed primarily to optimize utilization of hardware.
 Personal computer (PC) operating systems support complex games, business applications
and everything in between.
 Mobile computer operating systems provides an environment in which a user can easily
interface with the computer to execute programs.

Components of Computer system


A computer system can be divided roughly into four components:
1. Hardware
2. Operating system
3. Application programs
4. Users

 Hardware such as Central processing unit (CPU), Memory and the Input/Output (I/O)
devices provides the basic computing resources for the system.
 Application programs such as word processors, spreadsheets, compilers and Web
browsers define the ways in which these resources are used to solve users’ computing
problems.
 Operating system controls the hardware and coordinates its use among the various
application programs for the various users. Operating system provides an Environment
within which other programs can do useful work.

SYSTEM VIEW OF OPERATING SYSTEM


From the computer’s point of view an operating system is viewed as a Resource Allocator
and a Control Program.
 The operating system acts as the manager of the resources such as CPU time, memory
space, file-storage space, I/O devices and so on. Resource allocation is important where
many users access the same mainframe or minicomputer.
1

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 An operating system is a control program that manages the execution of user programs
to prevent errors and improper use of the computer. It is especially concerned with the
operation and control of I/O devices.
Note: Resource utilization means how various hardware and software resources are shared.

USER VIEW OF OPERATING SYSTEM


The user’s view of the computer varies according to the Interface being used.
 Personal Computer: Most computer users sit in front of a PC consisting of a monitor,
keyboard, mouse and system unit. Such a system is designed for one user to monopolize
its resources. The goal is to maximize the work that the user is performing. These
operating systems designed mostly for ease of use without considering resource
utilization because these systems are single user systems.
 Main frame: A user sits at a terminal connected to a mainframe or a minicomputer.
Other users are accessing the same computer through other terminals. These users share
resources and may exchange information. The operating system in such cases is designed
to maximize resource utilization— to assure that all available CPU time, memory and I/O
are used efficiently and that no individual user takes more than her fair share.
 Workstations: Users sit at workstations connected to networks of other workstations and
servers. These users have dedicated resources at their disposal, but they also share
resources such as networking and servers, including file, compute and print servers.
Therefore the operating system is designed to compromise between individual usability
and resource utilization.
 Mobile Computers: The user interface for mobile computers generally features a touch
screen, where the user interacts with the system by pressing and swiping fingers across
the screen rather than using a physical keyboard and mouse.
 Embedded Computing: Some computers may not have user view. Embedded computers
in home devices and automobiles may have numeric keypads and may turn indicator
lights on or off to show status, but their operating systems are designed primarily to run
without user intervention. Ex: Printers, GPS, Microwave Ovens, TV, Digital Camera etc.

Defining Operating Systems


Universally there is no accepted definition for operating system:
 Operating system is software that is used for controlling and allocating resources. The
fundamental goal of computer systems is to execute user programs and to make solving
user problems easier. Computer hardware alone is not easy to use, application programs
are developed. These programs require certain common operations such as controlling the
I/O devices.
 The operating system is also defined as the program that is running at all times on the
computer is called the Kernel.

Terms related to operating system


 System programs: These are associated with the operating system but are not necessarily
part of the kernel.
 Application programs: Programs which are not associated with the operation system.

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 Middleware: It is a set of software frameworks that provide additional services to


application developers.
Ex: Mobile operating system of Apple’s iOS and Google’s Android features a core kernel
along with middleware that supports databases, multimedia and graphics.
 Firmware: Read Only memory (ROM), EEPROM are considered as firmware.

COMPUTER-SYSTEM ORGANIZATION
Computer system organization has several parts:
1. Computer system operation
2. Storage structure
3. I/O structure
Computer System Operation
 A modern general-purpose computer system consists of one or more CPUs and a number
of device controllers connected through a common bus that provides access to shared
memory.
 Each device controller is in charge of a specific type of device such as disk drives, audio
devices, or video displays. CPU and the device controllers can execute in parallel,
competing for memory cycles.
 To ensure orderly access to the shared memory, a memory controller synchronizes access
to the memory.

 For a computer to start running, it needs to run bootstrap program. This bootstrap
program is stored within Read-Only Memory (ROM).
 It initializes all aspects of the system, from CPU registers to device controllers to memory
contents.
 The bootstrap program must know how to load the operating system and how to start
executing that system.
 To accomplish this goal, the bootstrap program must locate the operating-system kernel
and load it into memory.
 Once the kernel is loaded and executing, it can start providing services to the system and
its users.
 Some services are provided outside of the kernel by system programs that are loaded into
memory at boot time to become System processes or System daemons that run the entire
time the kernel is running.
Ex: On UNIX, the first system process is ―init‖ and it starts many other daemons.
3

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

Hardware and Software Interrupts


 The occurrence of an event is usually signaled by an interrupt from either the hardware
or the software.
 Hardware may trigger an interrupt at any time by sending a signal to the CPU by way of
the system bus.
 Software may trigger an interrupt by executing a special operation called a System call or
Monitor call.
 When the CPU is interrupted, it stops what it is doing and immediately transfers
execution to a fixed location. The fixed location usually the starting address where the
service routine for the interrupt is located.
 The interrupt service routine executes and after completion the interrupt, the CPU
resumes the interrupted computation.
 Interrupt vector is an array which stores the addresses of the interrupt service routines for
the various devices.
Storage Structure
The CPU can load instructions only from memory, so any programs to run must be stored in
memory. There are two types of storages:
1. Volatile storage: Registers, Cache, Main memory.
2. Non-volatile storage: Solid state disks, Magnetic disks, Optical disks, Magnetic tapes.

Volatile storage
Volatile storage devices are fast and expensive but they loses its contents when power is
turned off.
 Register: Each byte of memory has its own address. Interaction is achieved through a
sequence of load or store instructions to specific memory addresses.
Load instruction moves a byte or word from main memory to an internal register within
the CPU. Store instruction moves the content of a register to main memory.
 Cache: It is faster storage system used to store the information temporarily and the size
of cache is very small. It is located between CPU and Main Memory.
 Main Memory: It is also called as Random Access memory (RAM) is a rewritable
memory. Computers run most of their programs from Main memory. Main memory is
implemented in Dynamic RAM (DRAM) technology. Main memory is too small to store
all needed programs and data permanently.

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

Non-volatile storage or Secondary storage devices


These are extension of main memory. These devices stores large quantities of data
permanently.
Read-Only Memory (ROM) stores static programs such as bootstrap program. Electrically
Erasable Programmable Read-Only Memory (EEPROM) can be changed but cannot be
changed frequently because it contains mostly static programs. Smartphones have EEPROM
to store their factory-installed programs.
 Solid-State Disks: Solid-state disk stores data in a large DRAM array during normal
operation but also contains a hidden magnetic hard disk and a battery for backup power.
If external power is interrupted, this solid-state disk’s controller copies the data from
RAM to the magnetic disk. When external power is restored, the controller copies the
data back into RAM. These are faster than magnetic disks.
 Magnetic disk: It provides storage for both programs and data. Most of the system
programs and application programs are stored on a disk until they are loaded into
memory.
 Optical Disk: It uses Optical Storage techniques. Ex: CD, DVD.
 Magnetic Tape: It uses a long strip of narrow plastic film with tapes of thin magnetizable
coating. This is used to record video and audio data.
 Flash memory: These are popular in cameras, Personal Digital Assistants (PDAs), in
robots and general-purpose computers. Flash memory is slower than DRAM but needs no
power to retain its contents.

I/O Structure
 A Computer system consists of CPUs and multiple device controllers that are connected
through a common bus.
 Each device controller is in charge of a specific type of devices. A device controller
maintains some local buffer storage and a set of special-purpose registers.
 The device controller is responsible for moving the data between the peripheral devices
that it controls and its local buffer storage.
 Operating systems have a device driver for each device controller. This device driver
understands the device controller and provides the rest of the operating system with a
uniform interface to the device.
 To start an I/O operation, the device driver loads the appropriate registers within the
device controller.
5

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 The device controller examines the contents of these registers to determine what action to
be taken such as read or write etc.
 The controller starts the transfer of data from the device to its local buffer.
 Once the transfer of data is complete, the device controller informs the device driver via
an interrupt that it has finished its operation.
 The device driver then returns control to the operating system, possibly returning the data
or status information.

COMPUTER-SYSTEM ARCHITECTURE
A computer system can be categorized according to the number of general-purpose
processors used.
1. Single-Processor Systems
2. Multi-Processor Systems
3. Clustered systems
Single Processor system
 Single processor system has one main CPU capable of executing a general-purpose
instruction set from system processes and user processes.
 All single processor systems have other special-purpose processors also. They come in
the form of device-specific processors such as disk, keyboard and graphics controllers,
I/O processors etc.
 These special-purpose processors runs a limited instruction set and do not run user
processes. They are managed by the operating system.
 Operating system sends information about their next task to these processors and
monitors their status.
 Example: A disk-controller microprocessor receives a sequence of requests from the
main CPU and implements its own disk queue and scheduling algorithm. This
arrangement relieves the main CPU of the overhead of disk scheduling.
Note: The use of special-purpose microprocessors does not turn a single-processor system
into a multiprocessor.
Multi-Processor system
Multi-processor systems have two or more processors that share the resources such as
computer bus, memory, clock and peripheral devices.
Multiprocessor systems have three main advantages:
i. Increases the throughput: By increasing the number of processors more work will be
done in less time (i.e.) the speed of the system will increases.
ii. Economy of scale: Multiprocessor systems share peripherals, mass storage and power
supplies; hence the cost is less as compared to multiple single-processor systems.
iii. Increased reliability: In single processor system if the processor fails the entire system
fails, but in multi-processor system if processor fails then the entire system will not fail,
other processor will pick up and shares the work of failed processor.
Multi-processor systems are of two types:
1. Asymmetric multiprocessing
2. Symmetric multiprocessing

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

Asymmetric Multi-Processing:
 Each processor is assigned a specific task in asymmetric multiprocessing and it uses
boss–worker relationship.
 The Boss processor controls the system by scheduling and assigning the tasks to worker
processor. The worker processor has to complete the task assigned by boss processor.
Symmetric Multi-Processing (SMP)
Each processor performs all tasks within the operating system and no boss–worker
relationship exists between processors.
The below figure shows the SMP architecture:

 Each processor has its own set of registers and cache memory and all processors share
physical memory.
 In SMP if there are N CPU’S then N processes can run without causing performance
degradation.
 It is the most common used system. All modern operating systems including Windows,
Mac OS X and Linux provide support for SMP.
Multicore processors
 Multicore processors are special type of multiprocessors in which multiple computing
cores reside on a single chip. Each core has its own register set and its own local cache.
 These are more efficient than multiple chips with single cores because on-chip
communication is faster and one chip with multiple cores uses less power than multiple
single-core chips.
The below figure shows dual-core design with two cores on the same chip

Blade processors
 In Blade servers multiple processor boards, I/O boards and networking boards are placed
in the same chassis.
 The difference between Blade processors and traditional multiprocessor systems is that
each blade-processor board boots independently and runs its own operating system.
Memory Access models
 Multiprocessing can cause a system to change its memory access model from uniform
memory access (UMA) to non-uniform memory access (NUMA).

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 UMA is defined as the situation in which access to any RAM from any CPU takes the
same amount of time.
 In NUMA, some parts of memory may take longer to access than other parts, NUMA
creates a performance issues.
Clustered Systems
 Clustered system is also a type of multiprocessor system. Clustered systems are
composed of two or more individual systems or nodes joined together.
 Each node may be a single processor system or a multicore system.
 Clustered computers share storage and are closely linked via a local-area network LAN.
 Clustering is usually used to provide High-availability service (i.e.) service will continue
even if one or more systems in the cluster fail.
Clustering can be structured Asymmetrically or Symmetrically.
 In Asymmetric clustering, one machine is in Hot-Standby mode while the other is
running the applications. The hot-standby host machine only monitors the active server. If
the active server fails, the hot-standby host becomes the active server.
 In Symmetric clustering, two or more hosts are running applications and are monitoring
each other. This structure is obviously more efficient, as it uses all of the available
hardware.
Parallel clusters: parallel clustering allow multiple hosts to access the same data on shared
storage. The clustering is done over Wide Area Networks (WAN’s).

OPERATING SYSTEM OPERATIONS


1. Dual mode or multimode operation
2. Timers
Dual mode or Multimode operation
In order to ensure the proper execution of the operating system, we must be able to
distinguish between the execution of operating-system code and user-defined code.
Operating system needs two modes of operations (Dual Mode):
i. User mode
ii. Kernel mode or Supervisor mode or System mode or Privileged mode.
 Mode bit is added to the hardware of the computer to indicate the current mode: kernel
(0) or user (1).
 Mode bit can distinguish between a task that is executed on behalf of either the operating
system or the user.
 The system is in user mode, when the computer system is executing on behalf of a user
application.
 When a user application requests a service from the operating system via a system call,
the system must transition from user to kernel mode to fulfill the request.
Modern operating systems are Interrupt driven. A trap or an Exception is a software-
generated interrupt caused either by an error or by a specific request from a user program that
an operating-system service to be performed.
Consider the figure that shows the transition from user to kernel mode.

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 At system boot time, the hardware starts in kernel mode.


 The operating system is then loaded and starts user applications in user mode.
 Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel
mode by changing the state of the mode bit to 0.
 (i.e.) Whenever the operating system gains control of the computer, it is in kernel mode.
 The system always switches to user mode by setting the mode bit to 1 before passing
control to a user program.
The dual mode of operation protects the operating system from errant users and errant users
from one another.
 We accomplish this protection by designating some of the machine instructions that may
cause harm as Privileged Instructions.
 The hardware allows privileged instructions to be executed only in kernel mode.
 If an attempt is made to execute a privileged instruction in user mode, the hardware does
not execute the instruction but rather treats it as illegal and traps it to the operating
system.
 The instruction to switch to kernel mode is an example of a privileged instruction.
 Examples of Privileged instructions include I/O control, timer management and interrupt
management.
Dual mode operation is implemented in Microsoft Windows7, Unix and Linux OS.
Sysem calls: System calls provide the means for a user program to ask the operating
system to perform tasks reserved for the operating system on the user program’s behalf.
When a system call is executed, it is typically treated by the hardware as software
interrupt. The kernel examines the interrupting instruction to determine what system call
has occurred.

Timer
 Timers are implemented in operating systems to maintain control over the CPU.
 A timer can be set to interrupt the computer after a specified period of time to avoid
getting stuck into an infinite loop.
 The period may be fixed or varied from 1 millisecond to 1 second
 A variable timer is implemented by a fixed-rate clock and a counter.
 The operating system sets the counter. Every time the clock ticks, the counter is
decremented.
 When the counter reaches 0, an interrupt occurs. Before turning over control to the user,
the operating system ensures that the timer is set to interrupt.

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 If the timer interrupts, control transfers automatically to the operating system, which may
treat the interrupt as a fatal error or may give the program more time.
 Instructions that modify the content of the timer are privileged.

PROCESS MANAGEMENT
A process is a program in execution. A program does nothing unless its instructions are
executed by a CPU.
Example:
1. A time-shared user program such as a compiler is a process.
2. A word-processing program being run by an individual user on a PC is a process.
3. A system task such as sending output to a printer is a process.
 A process needs certain resources including CPU time, memory, files and I/O devices to
accomplish its task.
 These resources are either given to the process when it is created or allocated to it while it
is running.
 A program is a passive entity, like the contents of a file stored on disk, whereas a process
is an active entity.
 The CPU executes one instruction of the process after another until all instructions in that
process completes.
 At any time, at most only one instruction is executed on behalf of the process.
 A process is the unit of work in a system. A system consists of a collection of processes
such as operating-system processes and user processes.
 Operating system process executes system code whereas user processes executes user
code.
The operating system is responsible for the following activities of process management:
1. Creating and deleting both user and system processes.
2. Scheduling processes and threads on the CPUs.
3. Suspending and resuming processes.
4. Providing mechanisms for process synchronization and process communication.

MEMORY MANAGEMENT
 Main memory is a large array of bytes. Each byte has its own address. Main memory is a
repository of quickly accessible data shared by the CPU and I/O devices.
 A program to be executed, it must be mapped to absolute addresses and loaded into
memory.
 As the program executes, it accesses program instructions and data from main memory by
generating these absolute addresses.
 The program terminates, its memory space is declared available and the next program can
be loaded and executed.
 Memory management is needed to improve both CPU utilization and computer speed.
Operating systems is responsible for following activities of memory management:
1. Allocating and deallocating memory space as needed.
2. Deciding which processes and data to move into the memory and move out of memory.
3. Keeping track of which parts of memory are currently being used and who is using them.
10

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

STORAGE MANAGEMENT
Storage management can be divided into 4 different categories:
1. File system management
2. Mass storage management
3. Cache
4. I/O devices
File system management
A file is a collection of related information that represents program and data.
Examples: Data files, text files etc.
OS is responsible for the following activities in connection with file management:
 Creating and deleting files.
 Creating and deleting directories to organize files.
 Supporting primitives for manipulating files and directories.
 Mapping files onto secondary storage
 Backing up files on stable (nonvolatile) storage media.
Mass-Storage Management
Secondary storage disks are permanent storage devices.
 Most programs including compilers, assemblers, word processors, editors and formatters
are stored on a disk until loaded into memory.
 Magnetic tape drives and tapes and CD and DVD drives and platters are typical tertiary
storage devices.
 The media tapes and optical platters vary between WORM (write-once, read-many-
times) and RW (read– write) formats.
The operating system is responsible for the following activities in connection with disk
management: Free-space management, Storage allocation, Disk scheduling.
Caching
Cache is faster storage system used to store the information temporarily and the size of cache
is very small.
 Information is normally kept in storage systems such as main memory. As it is used, it is
copied into the cache on a temporary basis.
 When we need a particular piece of information, we first check whether it is in the cache.
 If information is in cache then we use the information directly from the cache.
 If information is not cache, we use the information from the source, putting a copy in the
cache.
I/O Systems
One of the purposes of an operating system is to hide details of specific hardware devices
from the user. Only the device driver knows details of the specific device.
Example: In UNIX, the peculiarities of I/O devices are hidden from the bulk of the operating
system itself by the I/O subsystem.
The I/O subsystem consists of several components:
 A memory-management component that includes buffering, caching and spooling
 A general device-driver interface
 Drivers for specific hardware devices

11

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

PROTECTION AND SECURITY


Protection is a mechanism for controlling the access of processes or users to the resources
defined by a computer system.
 This mechanism must be provided to specify the controls to be imposed and the controls
to be enforced.
 If a computer system has multiple users and allows the concurrent execution of multiple
processes, then access to data must be regulated.
 For that purpose, mechanisms ensure that files, memory segments, CPU and other
resources can be operated on by only those processes that have gained proper
authorization from the operating system.
Example:
1. Memory-addressing hardware ensures that a process can execute only within its own
address space.
2. The timer ensures that no process can gain control of the CPU without eventually
relinquishing control.
3. Device-control registers are not accessible to users, so the integrity of the various
peripheral devices is protected.
Security is a mechanism to defend a system from external and internal attacks.
 Such attacks include viruses and worms, denial-of service attacks, identity theft and theft
of service such as unauthorized use of a system.
 Even though the system provides Protection mechanisms still system needs security
mechanisms.
Example: A user whose authentication information such as user id and password is stolen.
User data could be copied or deleted even though file and memory protection are working.

COMPUTING ENVIRONMENTS
There are several computing environment are built for different computing purposes:
1. Traditional computing
2. Mobile computing
3. Distributed computing
4. Client server computing
5. Peer-to- Peer computing
6. Virtualization
7. Cloud computing
8. Real time embedded system
Traditional computing
Traditional computing environment consisted of PC’s connected to a network, with servers
providing file and print services.
 In traditional computing, for a period of time, systems were either batch systems or
interactive systems.
 Batch systems processed jobs in bulk, with predetermined input from files or other data
sources.
 Interactive systems waited for input from users.

12

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 To optimize the use of the computing resources, multiple users shared time on these
systems.
 Time-sharing systems used a timer and scheduling algorithms to cycle processes rapidly
through the CPU by giving each user a share of the resources.
 Web technologies and increasing Wide Area Network (i.e. Internet) bandwidth are
stretching the boundaries of traditional computing.
 Companies establish portals, which provide Web accessibility to their internal servers.
 Network computers are essentially terminals that understand web-based computing are
used in place of traditional workstations where more security or easier maintenance is
desired.
 Mobile computers can also connect to wireless networks and cellular data networks to
use the company’s Web portal.
 At home most of the users once had a single computer with a slow modem connection to
the office, the Internet, or both.
Mobile Computing
Mobile computing refers to computing on handheld smartphones and tablet computers.
 These devices share the distinguishing physical features of being portable and
lightweight.
 As compared with desktop and laptop computers, mobile systems gave up screen size,
memory capacity and overall functionality in return for handheld mobile access to
services such as e-mail and web browsing.
 The memory capacity and processing speed of mobile devices are more limited than those
of PCs.
 In mobile devices the power consumption is less and use processors that are smaller and
slower and offer fewer processing cores.
 Apple iOS and Google Android operating systems are dominating mobile computing.
 Mobile systems are used for e-mail and web browsing, playing music and video, reading
digital books, taking photos, recording high-definition video, Global positioning system
(GPS) chips, accelerometers and gyroscopes.
Distributed Systems
It is a collection of physically separate, possibly heterogeneous, computer systems that are
networked to provide users with access to the various resources that the system maintains.
 Access to a shared resource increases computation speed, functionality, data availability
and reliability.
 A network is a communication path between two or more systems.
 Distributed systems depend on networking for their functionality.
 TCP/IP is the most common network protocol of the Internet.
Network Operating System is an operating system that provides features such as file
sharing across the network, along with a communication scheme that allows different
processes on different computers to exchange messages.
Distributed Operating System provides an autonomous environment. The different
computers communicate closely enough to provide the illusion that only a single operating
system controls the network.

13

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

Client–Server Computing
Client –Server computing is a Centralized system in which Server systems are used to satisfy
requests generated by client systems. PC’s and mobile devices are connected to the
Centralized system.
Server systems can be categorized into 2 types: Compute servers and File servers:
 Compute-Server System provides an interface to which a client can send a request to
perform an action (for example, read data). In response, the server executes the action and
sends the results to the client. A server running a database that responds to client requests
for data is an example of such a system.
 File-Server System provides a file-system interface where clients can create, update,
read and delete files. Ex: A web server that delivers files to clients running web browsers.

Peer-to-Peer Computing
The peer-to-peer (P2P) system model is a distributed system. In this model, clients and
servers are not distinguished from one another.
 In Peer-to-Peer computing all nodes within the system are considered peers and each may
act as either a client or a server depending on whether it is requesting or providing a
service.
 Peer-to-peer systems offer an advantage over traditional client-server systems. In a client-
server system, the server is a bottleneck; but in a peer-to-peer system, services can be
provided by several nodes distributed throughout the network.
 To participate in a peer-to-peer system, a node must first join the network of peers.
 Once a node has joined the network, it can begin providing services to other nodes in the
network and requesting services from other nodes in the network.
Services in Peer-to-Peer computing:
1. Centralized Lookup Service:
When a node joins a network, it registers its service with a centralized lookup service on
the network. Any node desiring a specific service first contacts this centralized lookup
service to determine which node provides the service. The remainder of the
communication takes place between the client and the service provider.
2. Non-Centralized Lookup Service: It uses no centralized lookup service.
A peer acting as a client must discover which node provides a desired service by
broadcasting a request for the service to all other nodes in the network. The node
providing that service responds to the peer making the request.
To support this approach, a discovery protocol must be provided that allows peers to
discover services provided by other peers in the network.

14

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

Example: Skype uses a hybrid peer-to-peer approach used to make voice and video calls and
also sends text messages by using Voice over IP (VoIP) technology.
It includes a centralized login server, but it also incorporates decentralized peers and allows
two peers to communicate.

Virtualization
Virtualization is a technology that allows operating systems to run as applications within
other operating systems.
 Virtualization allows an entire operating system written for one platform to run on
another platform.
 With virtualization an operating system that is natively compiled for a particular CPU
architecture runs within another operating system also native to that CPU.
 Virtualization first came about on IBM mainframes as a method for multiple users to run
tasks concurrently.
 Running multiple virtual machines allows many users to run tasks on a single user
system.
Example: An Apple laptop running Mac OS X on the x86 CPU can run a Windows guest to
allow execution of Windows applications.

 VMware is a virtualization software application. If VMware is installed on Windows OS,


then Windows is the host operating system and the VMware application was the virtual
machine manager (VMM).
 If VMware application runs one or more guest copies of other operating systems such as
Linux, then LINUX will be the guest operating system.
 The VMM runs the guest operating systems, manages their resource use and protects each
guest from the others.
Cloud Computing
Cloud computing is a type of computing that delivers computing, storage and even
applications as a service across a network.
 It is a logical extension of virtualization, because it uses virtualization as a base for its
functionality.
 The Amazon Elastic Compute Cloud (EC2) facility has thousands of servers, millions of
virtual machines and petabytes of storage available for use by anyone on the Internet.

15

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 Based on how much of those resources the users use, they have to pay money on monthly
basis.
The cloud is categorized into 3 ways: Public cloud, Private cloud, Hybrid cloud.
 Public cloud is a cloud available via Internet to anyone willing to pay for the services.
 Private cloud is a cloud run by a company for that company’s own use.
 Hybrid cloud is a cloud that includes both public and private cloud components.
Cloud services can be categorized into 3 ways: SaaS, PaaS, IaaS.
 Software as a service (SaaS)—one or more applications available via the Internet.
Example: word processors or spreadsheets
 Platform as a service (PaaS)—a software stack ready for application use via the Internet
Example: A database server.
 Infrastructure as a service (IaaS)—servers or storage available over the Internet.
Example: Storage available for making backup copies of production data.
The cloud services and the cloud user interface are protected by a firewall.

Real-Time Embedded Systems


Embedded computers are the most prevalent form of computers in existence.
 These devices are found everywhere from car engines and manufacturing robots to DVDs
and microwave ovens.
 They tend to have very specific tasks. They have little or no user interface preferring to
spend their time monitoring and managing hardware devices such as automobile engines
and robotic arms.
 Embedded systems always run Real-Time Operating Systems.
 Real-time system is used as a control device in a dedicated application.
 Sensors bring data to the computer. The computer must analyze the data and possibly
adjust controls to modify the sensor inputs.
 A real-time system has well-defined, fixed time constraints. Processing must be done
within the defined constraints, or the system will fail.
Example: Systems that control scientific experiments, home-appliance controllers, medical
imaging systems, industrial control systems, automobile-engine fuel-injection systems and
weapon systems are considered as real-time systems.

OPERATING-SYSTEM SERVICES
An Operating system provides an environment for the execution of programs. OS provides
certain services to programs and to the users of those programs.
Operating system services are provided for the convenience of the programmer and to make
the programming task easier.
The list of Operating system services that are helpful to the user:
1. User interface
2. Program Execution
3. I/O Operation
4. File system manipulation
5. Communication
6. Error Detection

16

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

7. Resource allocation
8. Accounting
9. Protection and Security

User Interface
Almost all operating systems have a User Interface (UI). An UI is generally of 3 types:
 Command-Line Interface (CLI) uses text commands and a method for entering them.
 Batch Interface: The commands and directives to control those commands are entered
into files and those files are executed.
 Graphical User Interface (GUI) is a window system with a pointing device (i.e. mouse)
to direct I/O, choose from menus and make selections and a keyboard to enter text.
Program Execution
The system must be able to load a program into main memory and to run that program. The
program must be able to end its execution, either normally or abnormally.
I/O operations
A running program may require I/O, which may involve a file or an I/O device. Example are
blanking a display screen, recording to a CD or DVD drive or.
File-system manipulation
 Programs need to read and write files and directories.
 They need to create and delete them by name, search for a file and list file information.
 Operating systems include permissions management to allow or deny access to files or
directories based on file ownership.
Communications
 One process in its life time needs to communicate with another process to exchange
information.
 Communication occurs between processes that are executing on the computer.
 Communications may be implemented via Shared Memory or Message Passing.
 In Shared memory communication two or more processes read and write to a shared
section of memory.
 In Message passing communication the packets of information in predefined formats are
moved between processes by the operating system.

17

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

Error Detection
The operating system needs to be detecting and correcting errors constantly. The different
types of errors occurred are:
 CPU and Memory hardware errors such as a memory error or a power failure.
 I/O devices errors such as a parity error on disk, a connection failure on a network, or
lack of paper in the printer
 User Program errors such as an arithmetic overflow, an attempt to access an illegal
memory location.
 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.
 Operating system resources are CPU cycles, main memory, file storage, I/O devices etc.
 The operating system manages many of these resources.
 CPU cycles, main memory and file storage may have special allocation code. I/O devices
may have much more general request and release code.
 In determining how best to use the CPU, operating systems have CPU-scheduling
routines that take into account the speed of the CPU, the jobs that must be executed, the
number of registers available and other factors.
 There may also be routines to allocate printers, USB storage drives and other peripheral
devices.
Accounting
 Operating system keeps track of different kind of resources used by all users.
 This record keeping may be used for accounting so that users can be billed or simply for
accumulating usage statistics.
 Usage statistics are valuable tool for researchers who wish to reconfigure the system to
improve computing services.
Protection and security
 Protection ensures that all access to system resources is controlled because when several
separate processes execute concurrently, it should not be possible for one process to
interfere with the others or with the operating system itself.
 Security of the system defends the system from outsider’s attacks such as invalid access
of system resources such as I/O devices etc. Security starts with user authentication by
providing username and password to gain access to system resources.

USER AND OPERATING-SYSTEM INTERFACE


There are two different types of interfaces are available:
1. Command Line Interface (CLI) or Command interpreter.
2. Graphical user interface (GUI)
Command Line Interface (CLI) or Command Interpreter
Command Line Interface allows users to directly enter commands to be performed by the
operating system.

18

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 Windows and UNIX treat the command interpreter as a special program that is running
when a job is initiated. Command interpreters in UNIX or Linux are called as Shells.
 Other operating systems include the command interpreter in the kernel.
 UNIX and Linux systems uses different shells such as Bourne shell, C shell, Bourne-
Again shell, Korn shell etc.
 The main function of the command interpreter is to get and execute the next user-
specified command mostly to manipulate files: create, delete, list, print, copy, execute etc.
 Programmers can add new commands to the system easily by creating new files with the
proper names.
 Command-interpreter program does not have to be changed for new commands to be
added.

These commands can be implemented in two ways:


1. The command interpreter itself contains the code to execute the command. A command to
delete a file may cause the command interpreter to jump to a section of its code that sets
up the parameters and makes the appropriate system call.
2. The command interpreter does not understand the command and then it merely uses the
command to identify a file to be loaded into memory and executed.
For example to delete a file in UNIX we use the following command: rm file.txt
The command would search for a file called rm and load the file into memory and then
execute it with the parameter file.txt.
The function associated with the rm command would be defined completely by the code in
the file rm.
Graphical User Interfaces
Graphical user interface (GUI) is a user friendly interfacing with the operating system.
 In GUI rather than entering commands directly via a command-line interface, users
employ a mouse-based window and menu system characterized by a desktop metaphor.
 The user moves the mouse to position its pointer on images or icons, on the screen that
represent programs, files, directories and system functions.

19

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 Depending on the mouse pointer’s location, clicking a button on the mouse can invoke a
program, select a file or directory known as a folder or pull down a menu that contains
commands.
 The first Graphical user interfaces appeared on the Xerox Alto computer in 1973.
 Graphical interfaces became more widespread with the advent of Apple Macintosh
computers in the 1980s.
 Microsoft’s first version of Windows Version 1.0 was based on the addition of a GUI
interface to the MS-DOS operating system.
 Smartphones and handheld tablet computers uses a touchscreen interface. Users interact
with touchscreen by pressing and swiping fingers across the screen.
 K Desktop Environment (KDE) and the GNOME desktop by the GNU project are GUI
designs which run on Linux OS.

SYSTEM CALLS
System calls provide an interface to the services made available by an operating system.
 System calls are generally available as routines written in C and C++ and also written
using assembly-language instructions.
 Each operating system has its own name for each system call.
 Application developers design programs according to an Application Programming
Interface (API).
 The API specifies a set of functions that are available to an application programmer
including the parameters that are passed to each function and the return values the
programmer can expect.
 The functions that make up an API typically invoke the actual system calls on behalf of
the application programmer.
Example: The Windows function CreateProcess( ) which is used to create a new process
actually invokes the NTCreateProcess( ) system call in the Windows kernel.

20

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

For most programming languages, the run-time support system (a set of functions built into
libraries included with a compiler) provides a System Call Interface that serves as the link to
system calls made available by the operating system.
 The system-call interface intercepts function calls in the API and invokes the necessary
system calls within the operating system.
 A number is associated with each system call and the system-call interface maintains a
table indexed according to these numbers.
 The system call interface then invokes the intended system call in the operating-system
kernel and returns the status of the system call and any return values.
The below figure shows the relationship between an API, the system-call interface and the
operating system for open( ) system call.

TYPES OF SYSTEM CALLS


System calls can be grouped into six major categories:
1. Process Control
2. File Manipulation
3. Device Manipulation
4. Information Maintenance
5. Communications
6. Protection
Process Control System Calls
The list of process control system calls are:
 create process( ) is used to create a new process.
 terminate process( ) is used to terminate the process that have already created.
 load( ) and execute( ): A process or job executing one program may want to load( ) and
execute( ) another program.
 end( ): It is used when a running program needs to be able to halt its execution normally.
 abort( ): It is used when a running program needs to be able to halt its execution
abnormally.
 wait event( ) After creating new processes, it may need to wait for a certain amount of
time to pass to finish its execution.
 signal event( ): The jobs or processes signals when an event has occurred.

21

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 get process attributes( ) and set process attributes( ) are used to control execution of a
process.
 acquire lock( ) or release lock( ): Acquire lock ( ) is used to lock the process and release
lock( ) is used to release the lock on process.
If the program runs into a problem or terminates abnormally and causes an error trap, a
dump of memory is taken and an error message generated. The dump is written to disk and
may be examined by a debugger. A debugger is a system program designed to aid the
programmer in finding and correcting errors, or bugs to determine the cause of the
problem.

File Management
 create( ) is used to create a new file and delete( ) is used to delete an existing file.
 Every file have some attributes includes file name, file type, protection codes, accounting
information and so on. get file attributes( ) and set file attributes( ) are the system calls
used to retrieve and get values of attributes.
 open( ) is used to open already created file.
 After opening a file, it may be read( ), write( ), or reposition( ).
 Close( ): After all the operations are performed with the file, the file needs to be close.
Device Management
 A process may need several resources to execute such as main memory, disk drives,
access to files and so on.
 If the resources are available, they can be granted and control can be returned to the user
process. Otherwise, the process will have to wait until sufficient resources are available.
 The various resources controlled by the operating system such as disk drives, files etc.
 A system with multiple users may require us to first request( ) a device to use it.
 Once the device has been requested, we can read( ), write( ) and reposition( ) the device.
 After we are finished with the device, we release( ) it.
Information Maintenance
Many system calls exist simply for the purpose of transferring information between the user
program and the operating system.
 Most systems have a system call to return the current time( ) and date( ).
 dump( ) system calls is helpful in debugging a program.
 Other system calls may return information about the system, such as the number of
current users, the version number of the operating system, the amount of free memory or
disk space and so on.
Communication
There are two common models of inter-process communication: Message passing model and
the Shared-memory model.
In Message-passing model, the communicating processes exchange messages with one
another to transfer information by establishing an internet connection.
 Messages can be exchanged between the processes either directly or indirectly through a
common mailbox.
 Each computer in a network has a host name and each process has a process name.

22

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 OS can refer to the process by translating Process name into process identifier.
 gethostid( ) and getprocessid( ) system calls used to retrieve host name and process id.
 open_connection( ) and close_connection( ) system calls used to opening and closing the
connection.
 accept_connection( ) is used to accept the connection by the receiptent.
In Shared-memory model, processes use shared memory create( ) and shared memory
attach( ) system calls to create and gain access to regions of memory owned by other
processes.
 Operating system tries to prevent one process from accessing another processes memory.
 Shared memory requires that two or more processes agree to remove this restriction.
 They can exchange information by reading and writing data in the shared areas.

Protection
Protection provides a mechanism for controlling access to the resources provided by a
computer system.
 System calls providing protection include set_permission( ) and get_permission( ), which
manipulate the permission settings of resources such as files and disks.
 The allow_user( ) and deny_user( ) system calls specify whether particular users can or
cannot be allowed access to certain resources.

SYSTEM PROGRAMS
System programs are also known as system utilities provide a convenient environment for
program development and execution.
System programs can be divided into following categories:
 File management. These programs create, delete, copy, rename, print, dump, list and
generally manipulate files and directories.
 Status information System programs ask the system for the date, time and amount of
available memory or disk space, number of users, detailed performance, logging and
debugging information.
Typically, these programs format and print the output to the terminal or other output
devices or files or display it in a window of the GUI.
 File modification. Several text editors are available to create, modify and search the
content of files stored on disk or other storage devices.
 Programming-language support: Compilers, assemblers, debuggers and interpreters for
common programming languages such as C, C++ and Java are often provided with the
operating system.
 Program loading and Execution: Once a program is assembled or compiled, it must be
loaded into memory to be executed. The system provides loaders, linkage editors and
overlay loaders.
 Communication: These programs provide the mechanism for creating virtual
connections among processes, users and computer systems.
They allow users to send messages to one another’s screens, to browse Web pages, to
send e-mail messages, to log in remotely or to transfer files from one machine to another.

23

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 Background services. All general-purpose systems have methods for launching certain
system-program processes at boot time. Some of these processes terminate after
completing their tasks, while others continue to run until the system is halted. Constantly
running system-program processes are known as services, subsystems or daemons.

OPERATING-SYSTEM DESIGN AND IMPLEMENTATION


Design Goals
1. Choice of Hardware: The design of the system will be affected by the choice of
hardware and the type of system such as batch, time sharing, single user, multiuser,
distributed, real time or general purpose.
2. Requirements Specification: The requirements may be much harder to specify.
 The requirements can be divided into two groups: User goals and System goals.
 User’s wants system should be convenient to use, easy to learn, reliable, safe and fast.
 The system should be easy to design, implement and maintain. System should be flexible,
reliable, error free and efficient.
Mechanisms and Policies
Mechanisms determine how to do something; policies determine what will be done.
Example: The timer construct is a mechanism for ensuring CPU protection, but deciding how
long the timer is to be set for a particular user is a policy decision.
 The separation of policy and mechanism is important for flexibility.
 Policies are likely to change across places or over time. In the worst case, each change in
policy would require a change in the underlying mechanism.
 A change in policy would require redefinition of certain parameters of the system.
Example: Consider a mechanism for giving priority to certain types of programs over others.
If the mechanism is properly separated from policy, it can be used either to support a policy
decision that I/O-intensive programs should have priority over CPU-intensive programs.

Implementation
Operating systems are collections of many programs, written by many people over a long
period of time. Once an operating system is designed, it must be implemented.
 Operating systems can be written in assembly languages and Higher level languages such
as C, C++, Python, PERL, Shell scripts.
 An operating system can be written in more than one language.
 The lowest levels of the kernel might be assembly language. Higher-level routines can be
written in C and system programs might be in C or C++, in interpreted scripting
languages like PERL or Python, or in shell scripts.
Example: A Linux distribution probably includes programs written in all of those languages.
 Advantages of using a higher-level language for implementing operating systems are the
code can be written faster and is easier to understand and debug.
 Only disadvantage of implementing an operating system in a higher-level language are
reduced speed and increased storage requirements. But compared to today’s processor
speed it is a minor issue.

24

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

OPERATING-SYSTEM STRUCTURE
Multi-Programming System
 The most important aspects of operating systems is the ability to multi-program.
 A single program cannot keep either the CPU or the I/O devices busy at all times. Single
users frequently have multiple programs running.
 Multiprogramming increases CPU utilization by organizing jobs (code and data) so that
the CPU always has one to execute.
 The operating system keeps several jobs in memory simultaneously. Since main memory
is too small to accommodate all jobs, the jobs are kept initially on the disk in the job
pool. This job pool consists of all processes residing on disk awaiting allocation of main
memory.
 The set of jobs in memory can be a subset of the jobs kept in the job pool. The operating
system picks and begins to execute one of the jobs in memory. Eventually, the job may
have to wait for some task, such as an I/O operation, to complete.

 In a non-multi programmed system, the CPU would sit idle.


 In a multi-programmed system, the operating system simply switches to, and executes,
another job. When that job needs to wait, the CPU switches to another job, and so on.
Eventually, the first job finishes waiting and gets the CPU back. As long as at least one
job needs to execute, the CPU is never idle.
 Multi-programmed systems provide an environment in which the various system
resources such as CPU, memory, and peripheral devices are utilized effectively, but they
do not provide for user interaction with the computer system.

Time-Sharing or Multi-tasking System


 Time sharing is a logical extension of multiprogramming. In time-sharing systems, the
CPU executes multiple jobs by switching among them, but the switches occur so
frequently that the users can interact with each program while it is running.
 Time sharing requires an interactive computer system, which provides direct
communication between the user and the system. The user gives instructions to the
operating system using a input device such as a keyboard, mouse, touch pad, or touch
screen, and waits for immediate results on an output device. Accordingly, the response
time should be less than one second.

25

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 A time-shared operating system allows many users to share the computer simultaneously.
Since each action or command in a time-shared system tends to be short, only a little CPU
time is needed for each user.
 As the system switches rapidly from one user to the next, each user is given the
impression that the entire computer system is dedicated to his use, even though it is being
shared among many users.
TYPES OF OS STRUCTURES
1. Simple Structure
2. Layered Approach
3. Microkernels
4. Modules
5. Hybrid Systems
Simple Structure
MS-DOS operating systems do not have well-defined structures.
 It was designed and implemented by few people and started as small, simple and limited
systems and then grew beyond their original scope that the implementers didn’t imagine it
would be so popular.
 In MS-DOS, the interfaces and levels of functionality are not well separated.
 In MS-DOS, application programs are able to access the basic I/O routines to write
directly to the display and disk drives.
 Such freedom leaves MS-DOS vulnerable to errant or malicious programs, causing entire
system crashes when user programs fail.

Original UNIX operating system is also have limited structuring, it was limited by its
hardware functionality.

26

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 It consists of two separable parts: Kernel and System programs.


 The kernel is is further separated into a series of interfaces and device drivers, which have
been added and expanded over the years as UNIX has evolved.

The traditional UNIX operating system is layered structured to some extent.


 Everything below the system-call interface and above the physical hardware is the kernel.
 The kernel provides the file system, CPU scheduling, memory management and other
operating-system functions through system calls and all these functionalities to be
combined into one level.
 This monolithic structure was difficult to implement and maintain.

Layered Approach
 In Layered approach the operating system is broken into a number of layers (levels).
 The bottom layer 0 is the Hardware and the highest layer N is User interface.
 A operating-system layer consists of data structures and a set of routines that can be
invoked by higher-level layers and can also invoke operations on lower-level layers.
 An operating-system layer is an implementation of an abstract object made up of data and
the operations that can manipulate those data.

Advantages of Layered Approach


The main advantage of the layered approach is simplicity of construction and debugging.
 Each layer uses functions (operations) and services of only lower-level layers.
 This approach simplifies debugging and system verification.
 The first layer can be debugged without any concern for the rest of the system because it
uses only the basic hardware to implement its functions.
 Once the first layer is debugged and functions correctly while the second layer is
debugged and so on.
 If an error is found during the debugging of a particular layer, the error must be on that
layer, because the layers below it are already debugged.
Other advantage of Layered structure is Data Hiding:
 Each layer is implemented only with operations provided by lower-level layers.

27

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 A layer does not need to know how these operations are implemented instead a layer just
knows what these operations do.
 Hence, each layer hides the existence of certain data structures, operations and hardware
from higher-level layers.
Problems with Layered Approach
Major difficulty with the layered approach involves appropriately defining the various layers.
 A layer can use only lower-level layers hence we have plan carefully which layer to be
kept in which place.
 Example: The device driver for the backing store (i.e. disk space used by virtual-memory
algorithms) must be at a lower level than the memory-management routines, because
memory management requires the ability to use the backing store.
 The backing-store driver would normally be above the CPU scheduler, because the driver
may need to wait for I/O and the CPU can be rescheduled during this time.
Other problem with layered implementations is that they tend to be less efficient.
 When a user program executes an I/O operation, it executes a system call that is trapped
to the I/O layer, which calls the memory-management layer, which in turn calls the CPU-
scheduling layer, which is then passed to the hardware.
 At each layer, the parameters may be modified, data may need to be passed and so on.
Each layer adds overhead to the system call.
 The net result is a system call that takes longer time than a non-layered system.
Microkernels
As the UNIX OS is expanded, the kernel also became large and difficult to manage.
 In the mid-1980s, researchers at Carnegie Mellon University developed an operating
system called Mach that modularized the kernel using the Microkernel approach.
 This method structures the operating system by removing all nonessential components
from the kernel and implementing them as system and user-level programs resulting a
smaller kernel (i.e.) Microkernel.
 There is little consensus regarding which services should remain in the kernel and which
service should be implemented in user space.
 Microkernels provide minimal process and memory management and also
communication facility.
 The main function of the microkernel is to provide Message Passing Communication
between the client program and the various services that are also running in user space.

28

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

Example: if the client program wishes to access a file, it must interact with the file server.
The client program and service never interact directly. Rather, they communicate indirectly
by exchanging messages with the microkernel.
Advantages of Microkernel
Microkernel approach is makes extending the operating system easier.
 All new services are added to user space and consequently do not require modification of
the kernel.
 Even-though when the kernel must have to be modified, the changes in the kernel will be
very few, because the microkernel is a smaller kernel.
 The resulting operating system is easier to port from one hardware design to another.
 The microkernel also provides more security and reliability, since most services are
running as user processes rather than kernel processes.
 If a service fails, the rest of the operating system remains untouched.
Disadvantage of Microkernel
 The performance of microkernels can suffer due to increased system-function overhead.

Modules
Loadable Kernel Modules are the current best methodology for operating-system design.
 The kernel has a set of core components and links in additional services via modules,
either at boot time or during run time.
 This type of design is common in modern implementations of UNIX such as Solaris,
Linux and Mac OS X as well as Windows.
 The idea of the design is for the kernel to provide core services while other services are
implemented dynamically as the kernel is running.
 Linking services dynamically is preferable to adding new features directly to the kernel,
which would require recompiling the kernel every time a change was made.
 Example: We might build CPU scheduling and memory management algorithms directly
into the kernel and then add support for different file systems by way of loadable
modules.
The below figure shows the Solaris operating system structure is organized around a core
kernel with seven types of loadable kernel modules:

29

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

Hybrid Systems
In practice, most of the operating systems combine different structures, resulting in hybrid
systems that address performance, security and usability issues.
Example:
1. Linux and Solaris are monolithic and modular.
2. Windows is largely monolithic and some part of it behaves as microkernel. Windows
systems also provide support for dynamically loadable kernel modules.
Operating Systems that supports the structure of Hybrid systems are:
 Mac OS X
 iOS
 Android
Mac OS X
The Apple Mac OS X operating system uses a hybrid structure and it is layered system.
 The top layers include the Aqua user interface and a set of application environments and
services.
 The Cocoa environment specifies an API for the Objective-C programming language,
which is used for writing Mac OS X applications.
 Below these layers is the Kernel Environment, which consists primarily of the Mach
microkernel and the BSD UNIX kernel.
 Mach micro kernel provides memory management, support for remote procedure calls
(RPCs) and inter-process communication (IPC) facilities including message passing, and
thread scheduling.
 The BSD component provides a BSD command-line interface, support for networking
and file systems and an implementation of POSIX APIs including Pthreads.
 The kernel environment provides an I/O kit for development of device drivers and
dynamically loadable modules.
 The BSD application environment can make use of BSD facilities directly.

iOS
iOS is a mobile operating system designed by Apple to run its iPhone and the iPad.
 Cocoa Touch is an API for Objective-C that provides several frameworks for developing
applications that run on iOS devices.
 The fundamental difference between Cocoa and Cocoa Touch is that the Cocoa Touch
provides support for hardware features unique to mobile devices such as touch screens.

30

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-1 P.VAMSHI KRISHNA

 The media services layer provides services for graphics, audio and video.
 The Core services layer provides a variety of features, including support for cloud
computing and databases.
 The bottom layer represents the core operating system, which is based on the kernel
environment.

Android
The Android operating system was developed for Android smartphones and tablet computers.
It was designed by the Open Handset Alliance led by Google.
 Android is a layered stack of software that provides a rich set of frameworks for
developing mobile applications.
 At the bottom of this software stack is the Linux kernel. Linux is used primarily for
process, memory and device-driver support for hardware and has been expanded to
include power management.

 The Android runtime environment includes a core set of libraries as well as the Dalvik
virtual machine.
 Software designers for Android devices develop applications in the Java language and
Google has designed a separate Android API for Java development.
 The Java class files are first compiled to Java byte-code and then translated into an
executable file that runs on the Dalvik virtual machine.
 The Dalvik virtual machine was designed for Android and is optimized for mobile
devices with limited memory and CPU processing capabilities.
 The set of libraries available for Android applications includes frameworks for
developing web browsers (webkit), database support (SQLite) and multimedia.
 The libc library is similar to the standard C library but is much smaller and has been
designed for the slower CPUs that characterize mobile devices.

31

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

UNIT-II
PROCESS MANAGEMENT
PROCESS CONCEPT
The process concept includes the following:
1. Process
2. Process state
3. Process Control Block
4. Threads
Process
A process can be thought of as a program in execution (or) A process is the unit of work in a
modern time-sharing system.
A process will need certain resources such as CPU time, memory, files and I/O devices to
accomplish its task.
These resources are allocated to the process either when it is created or while it is executing.
The below figure shows the structure of process in memory:

The process contains several sections: Text, Data, Heap and Stack.
 Text Section contains the program code. It also includes the current activity, as
represented by the value of the program counter and the contents of the processor’s
registers.
 Process stack contains temporary data such as function parameters, return addresses and
local variables.
 Data section contains global variables.
 Heap is memory that is dynamically allocated during process run time.
Difference between Program and Process:
 A program is a passive entity, such as a file containing a list of instructions stored on disk
often called an executable file.
 A process is an active entity with a program counter specifying the next instruction to
execute and a set of associated resources.
 A program becomes a process when an executable file is loaded into memory.
Two common techniques for loading executable files are double-clicking an icon
representing the executable file and entering the name of the executable file on the command
line as in prog.exe or a.out.
Although two processes may be associated with the same program, they are considered as
two separate execution sequences.

32

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

For instance, several users may be running different copies of the mail program or the same
user may invoke many copies of the web browser program. Each of these is considered as a
separate process.
Process State
As a process executes, it changes state. The process state defines the current activity of that
process.
A process may be in one of the following states:
 New: The process is being created.
 Ready: The process is waiting to be assigned to a processor.
 Running: Instructions are being executed.
 Waiting: The process is waiting for some event to occur such as an I/O completion or
reception of a signal.
 Terminated: The process has finished execution.
Note: Only one process can be running on any processor at any instant of time.

Process Control Block


Each process is represented in the operating system by a Process Control Block (PCB). It is
also called a Task Control Block.
PCB serves as the repository for any information that may vary from process to process.

The PCB contains information related to process such as:


 Process state: The state may be new, ready, running, waiting and terminated.
 Program counter: The counter indicates the address of the next instruction to be
executed for this process.
 CPU registers: The registers vary in number and type, depending on the computer
architecture. They include accumulators, index registers, stack pointers and general-
purpose registers etc. Along with the program counter, this state information must be
saved when an interrupt occurs, to allow the process to be continued correctly afterward.

33

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 CPU-scheduling information: This information includes a process priority, pointers to


scheduling queues and any other scheduling parameters.
 Memory-management information: This information includes the base and limit
registers values, the page tables or the segment tables depending on the memory system
used by the operating system.
 Accounting information: This information includes the amount of CPU and real time
used, time limits, account numbers, job or process numbers and so on.
 I/O status information: This information includes the list of I/O devices allocated to the
process, a list of open files and so on.
Threads
In a single processor system a process is a program that performs a single thread of
execution.
 Example: When a process is running a word-processor program, a single thread of
instructions is being executed.
 This single thread of control allows the process to perform only one task at a time.
 The user cannot simultaneously type in characters and run the spell checker within the
same process.
In multicore system or multi-processor system allows a process to run multiple threads of
execution in parallel.
On a system that supports threads, the PCB is expanded to include information for each
thread.
Process Scheduling
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 that users
can interact with each program while it is running.
To meet these objectives, the Process Scheduler selects an available process for program
execution on the CPU.
Process scheduling involves three things:
1. Scheduling Queues
2. Schedulers
3. Context Switch
Scheduling Queues
There are several queues are implemented in operating system such as Job Queue, Ready
Queue, Device Queue.
 Job Queue: It consists of all processes in the system. As processes enter the system, they
are put into a job queue.
 Ready Queue: The processes that are residing in main memory and they are ready and
waiting to execute are kept on a list called the Ready Queue. Ready queue is generally
stored as a linked list. A ready-queue header contains pointers to the first and final PCBs
in the list. Each PCB includes a pointer field that points to the next PCB in the ready
queue.

34

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 Device Queue: Each device has its own device queue. It contains the list of processes
waiting for a particular I/O device.

Consider the above Queuing Diagram:


 Two types of queues are present: the Ready Queue and a set of Device Queues. CPU
and I/O are the resources that serve the queues.
 A new process is initially put in the ready queue. It waits there until it is selected for
execution or dispatched.
Once the process is allocated the CPU and is executing, one of several events could occur:
 The process could issue an I/O request and then be placed in an I/O queue.
 The process could create a new child process and wait for the child’s termination.
 The process could be removed forcibly from the CPU, as a result of an interrupt and be
put back in the ready queue.
Schedulers
A process migrates among the various scheduling queues throughout its lifetime. For
scheduling purpose, the operating system must select processes from these queues. The
selection process is carried out by the Scheduler.
There are three types of Schedulers are used:
1. Long Term Scheduler
2. Short Term Scheduler
3. Medium Term Scheduler
Long Term Scheduler (New to ready state)
 Initially processes are spooled to a mass-storage device (i.e Hard disk), where they are
kept for later execution.
 Long-term scheduler or job scheduler selects processes from this pool and loads them into
main memory for execution. (i.e. from Hard disk to Main memory).
 The long-term scheduler executes much less frequently, there may be minutes of time
between creation of one new process to another process.
 The long-term scheduler controls the degree of multiprogramming (the number of
processes in memory).
Short Term Scheduler (Ready to Running)

35

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 Short-term scheduler or CPU scheduler selects from among the processes that are ready
to execute and allocates the CPU to one of them. (i.e. a process that resides in main
memory will be taken by CPU for execution).
 The short-term scheduler must select a new process for the CPU frequently.
 The short term scheduler must be very fast because of the short time between executions
of processes.
Midium Term Scheduler
Medium Term Scheduler does two tasks:
1. Swapping: Medium-term scheduler removes a process from main memory and stores it
into the secondary storage. After some time, the process can be reintroduced into main
memory and its execution can be continued where it left off. This procedure is called
Swapping.
2. Medium Term Scheduler moves a process from CPU to I/O waiting queue and I/O queue
to ready queue.

The processes can be described as two types:


1. I/O bound process is one that spends more of its time doing I/O than it spends doing
computations.
2. CPU Bound process using more of its time doing computations and generates I/O
requests infrequently.
The long-term scheduler selects a good process mix of I/O-bound and CPU-bound processes.
 If all processes are I/O bound, the ready queue will almost always be empty and the CPU
will remain idle for long time because I/O device processing takes a lot of time.
 If all processes are CPU bound, the I/O waiting queue will almost always be empty. I/O
devices will be idle and CPU is busy for most of the time.
 Thus if the system maintains the combination of CPU bound and I/O bound processes
then the system performance will be increased.
Note: Time-sharing systems such as UNIX and Microsoft Windows systems often have no
long-term scheduler but simply put every new process in memory for the short-term
scheduler.
Context Switching
 Switching the CPU from one process to another process requires performing a state save
of the current process and a state restore of a different process. This task is known as a
Context Switch.
 The context is represented in the PCB of the process. It includes the value of the CPU
registers, the process state and memory-management information.

36

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 When a context switch occurs, the kernel saves the context of the old process in its PCB
and loads the saved context of the new process scheduled to run.
 Context-switch time is pure overhead, because the system does no useful work while
switching. Context switch time may be in few milliseconds.
Operations on Processes
1. Process Creation
2. Process Termination
Process Creation
 During the execution of a process in its life time, a process may create several new
processes.
 The creating process is called a parent process and the new processes are called children
process.
 Each of these new processes may create other processes forming a tree of processes.
 Operating system identifies processes according to process identifier (pid).
 Pid provides an unique integer number for each process in the system.
 Pid can be used as an index to access various attributes of a process within the kernel.
The below figure shows the process tree for the Linux OS that shows the name of each
process and its pid. In Linux process is called task.

 The init process always has a pid of 1. The init process serves as the root parent process
for all user processes.
 Once the system has booted, the init process can also create various user processes, such
as a web or print server, an ssh server etc.
 kthreadd and sshd are child processes of init.
 The kthreadd process is responsible for creating additional processes that perform tasks
on behalf of the kernel.
 The sshd process is responsible for managing clients that connect to the system by using
secure shell (ssh).
ps command is used to obtain a list of processes:
ps –el

37

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

The command will list complete information for all processes currently active in the system.
 When a process creates a child process, that child process will need certain resources such
as CPU time, memory, files, I/O devices to accomplish its task.
 A child process may be able to obtain its resources directly from the operating system or
it may be constrained to a subset of the resources of the parent process.
 The parent may have to partition its resources among its children or it may be able to
share some resources such as memory or files among several of its children.
 Restricting a child process to a subset of the parent’s resources prevents any process from
overloading the system by creating too many child processes.
When a process creates a new process there exist two possibilities for execution:
1. The parent continues to execute concurrently with its children.
2. The parent waits until some or all of its children have terminated.
There are also two address-space possibilities for the new process:
1. The child process is a duplicate of the parent process (i.e) it has the same program and
data as the parent.
2. The child process has a new program loaded into it.
Process System calls in Unix/ Linux: fork( ), exec( ), wait( ), exit( )
 fork( ): In UNIX OS a new process is created by the fork( ) system call.
 The new process consists of a copy of the address space of the original process. This
mechanism allows the parent process to communicate easily with its child process.
 Both the parent and the child processes continue execution at the instruction after the
fork( ).
 For the new child process (i.e. Child Process) the return code for the fork( ) is zero.
 The nonzero process identifier of the child is returned to the parent.
 exec( ): After a fork( ) system call, one of the two processes typically uses the exec( )
system call to replace the process’s memory space with a new program.
 The exec( ) system call loads a binary file into memory and starts its execution.
 In this way, the two processes are able to communicate and then go their separate ways.
 wait( ): The parent can create more children or if the parent has nothing else to do while
the child process is running then the parent process can issue a wait( ) system call to
move itself out of the Ready Queue until the child process terminates.
 The call to exec( ) overlays the process’s address space with a new program or the call to
exec( ) does not return control unless an error occurs.

Program for Creating a separate process using the UNIX fork( ) system call
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>

38

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

int main( )
{
pid_t pid;
/* fork a child process */
pid = fork( );
if (pid < 0)
{ /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0)
{ /* child process */
execlp("/bin/ls","ls",NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait(NULL);
printf("Child Complete");
}
return 0;
}
The above C program shows the UNIX system calls fork, exec, wait. Two different processes
are running copies of the same program.
 The only difference is that the value of pid for the child process is zero, while the value of
pid for the parent is an integer value greater than zero (i.e. the actual pid of the child
process).
 The child process inherits privileges and scheduling attributes from the parent, as well as
certain resources such as open files.
 The child process then overlays its address space with the UNIX command /bin/ls (used
to get a directory listing) using the execlp( ) system call (execlp( ) is a version of the
exec( ) system call).
 The parent waits for the child process to complete with the wait( ) system call.
 When the child process completes by either implicitly or explicitly invoking exit( ), the
parent process resumes from the call to wait( ), where it completes using the exit( )
system call.
Process Termination: exit( )
 A process terminates when it finishes executing its final statement and asks the operating
system to delete it by using the exit( ) system call.
 The process may return a status value to its parent process via the wait( ) system call.
 All the resources of the process including physical and virtual memory, open files and I/O
buffers are deallocated by the operating system.
A parent may terminate the execution of one of its children for a variety of reasons such as:

39

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

1. The child has exceeded its usage of some of the resources that it has been allocated.
2. The task assigned to the child is no longer required.
3. The parent is exiting and the operating system does not allow a child to continue if its
parent terminates.
Cascading Termination
If a parent process terminates either normally or abnormally then all its children must also be
terminated is referred as Cascading Termination. It is normally initiated by operating system.
In Linux and UNIX systems, a process can be terminate by using the exit( ) system call
providing an exit status as a parameter:
/* exit with status 1 */
exit(1);
Under normal termination, exit( ) may be called either directly (i.e. exit(1)) or indirectly (i.e.
by a return statement in main( ) ).
A parent process may wait for the termination of a child process by using the wait( ) system
call. The wait( ) system call is passed a parameter that allows the parent to obtain the exit
status of the child. This system call also returns the process identifier of the terminated child
so that the parent can tell which of its children has terminated:
pid_t pid;
int status;
pid = wait(&status);
Zombie process
A process that has terminated but whose parent has not yet called wait( ) is known as a
zombie process.
 When a process terminates, its resources are deallocated by the operating system. Its entry
in the process table must remain there until the parent calls wait( ), because the process
table contains the process’s exit status.
 Once the parent calls wait( ), the process identifier of the zombie process and its entry in
the process table are released.
Orphan Processes
If a parent did not invoke wait( ) and instead terminated, thereby leaving its child processes
as orphans are called Orphan processes.
 Linux and UNIX address this scenario by assigning the init process as the new parent to
orphan processes.
 The init process periodically invokes wait( ), thereby allowing the exit status of any
orphaned process to be collected and releasing the orphan’s process identifier and
process-table entry.
CPU SCHEDULING
CPU scheduling is the basis of Multi-programmed operating systems. By switching the CPU
among processes, the operating system can make the computer more productive.
 In a single-processor system, only one process can run at a time. Others must wait until
the CPU is free and can be rescheduled.

40

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 The CPU will sit idle and waiting for a process that needs an I/O operation to complete. If
the I/O operation completes then only the CPU will start executing the process. A lot of
CPU time has been wasted with this procedure.
 The objective of multiprogramming is to have some process running at all times to
maximize CPU utilization.
 When several processes are in main memory, if one processes is waiting for I/O then the
operating system takes the CPU away from that process and gives the CPU to another
process. Hence there will be no wastage of CPU time.
Concepts of CPU Scheduling
1. CPU–I/O Burst Cycle
2. CPU Scheduler
3. Pre-emptive Scheduling
4. Dispatcher
CPU–I/O Burst Cycle
Process execution consists of a cycle of CPU execution and I/O wait.
 Process execution begins with a CPU burst. That is followed by an I/O burst. Processes
alternate between these two states.
 The final CPU burst ends with a system request to terminate execution.
 Hence the First cycle and Last cycle of execution must be CPU burst.

CPU Scheduler
Whenever the CPU becomes idle, the operating system must select one of the processes in the
ready queue to be executed. The selection process is carried out by the Short-Term
Scheduler or CPU scheduler.
Preemptive Scheduling
CPU-scheduling decisions may take place under the following four cases:
1. When a process switches from the running state to the waiting state.
Example: as the result of an I/O request or an invocation of wait( ) for the termination of a
child process.
2. When a process switches from the running state to the ready state.
Example: when an interrupt occurs
3. When a process switches from the waiting state to the ready state.
Example: at completion of I/O.
4. When a process terminates.
For situations 2 and 4 are considered as Pre-emptive scheduling situations. Mach OS X,
WINDOWS 95 and all subsequent versions of WINDOWS are using Preemptive scheduling.
41

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

Dispatcher
The dispatcher is the module that gives control of the CPU to the process selected by the
short-term scheduler. Dispatcher function involves:
1. Switching context
2. Switching to user mode
3. Jumping to the proper location in the user program to restart that program.
The dispatcher should be as fast as possible, since it is invoked during every process switch.
The time it takes for the dispatcher to stop one process and start another process running is
known as the Dispatch Latency.
SCHEDULING CRITERIA
Different CPU-scheduling algorithms have different properties and the choice of a particular
algorithm may favor one class of processes over another.
Many criteria have been suggested for comparing CPU-scheduling algorithms:
 CPU utilization: CPU must be kept as busy as possible. CPU utilization can range from
0 to 100 percent. In a real system, it should range from 40 to 90 percent.
 Throughput: The number of processes that are completed per time unit.
 Turn-Around Time: It is the interval from the time of submission of a process to the
time of completion. Turnaround time is the sum of the periods spent waiting to get into
memory, waiting in the ready queue, executing on the CPU and doing I/O.
 Waiting time: It is the amount of time that a process spends waiting in the ready queue.
 Response time: It is the time from the submission of a request until the first response is
produced. Interactive systems use response time as its measure.
Note: It is desirable to maximize CPU utilization and Throughput and to minimize Turn-
Around Time, Waiting time and Response time.
CPU SCHEDULING ALGORITHMS
CPU scheduling deals with the problem of deciding which of the processes in the ready
queue is to be allocated the CPU. Different CPU-scheduling algorithms are:
1. First-Come, First-Served Scheduling (FCFS)
2. Shortest-Job-First Scheduling (SJF)
3. Priority Scheduling
4. Round Robin Scheduling
5. Multilevel Queue Scheduling
6. Multilevel Feedback Queue Scheduling
Gantt Chart is a bar chart that is used to illustrates a particular schedule including the start
and finish times of each of the participating processes.
First-Come, First-Served Scheduling (FCFS)
In FCFS, the process that requests the CPU first is allocated the CPU first.
 FCFS scheduling algorithm is Non-preemptive.
 Once the CPU has been allocated to a process, it keeps the CPU until it releases the CPU.
 FCFS can be implemented by using FIFO queues.
 When a process enters the ready queue, its PCB is linked onto the tail of the queue.
 When the CPU is free, it is allocated to the process at the head of the queue.

42

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 The running process is then removed from the queue.


Example:1 Consider the following set of processes that arrive at time 0. The processes are
arrived in the order P1, P2, P3, with the length of the CPU burst given in milliseconds.
Process Burst Time
P1 24
P2 3
P3 3
Gantt Chart for FCFS is:

The average waiting time under the FCFS policy is often quite long.
 The waiting time is 0 milliseconds for process P1, 24 milliseconds for process P2 and 27
milliseconds for process P3.
 Thus, the average waiting time is (0 + 24 + 27)/3 = 17 milliseconds.
Convoy Effect in FCFS
Convoy effect means, when a big process is executing in CPU, all the smaller processes must
have to wait until the big process execution completes. This will effect the performance of the
system.
Example:2 Let us consider same example above but with the processes arrived in the order
P2, P3, P1.

The processes coming at P2, P3, P1 the average waiting time (6 + 0 + 3)/3 = 3 milliseconds
whereas the processes are came in the order P1, P2, P3 the average waiting time is 17
milliseconds.
Disadvantage of FCFS:
FCFS scheduling algorithm is Non-preemptive, it allows one process to keep CPU for long
time. Hence it is not suitable for time sharing systems.

Shortest-Job-First Scheduling (SJF)


SJF algorithm is defined as “when the CPU is available, it is assigned to the process that has
the smallest next CPU burst”. If the next CPU bursts of two processes are the same, FCFS
scheduling is used between two processes.
SJF is also called as Shortest-Next CPU-Burst algorithm, because scheduling depends on
the length of the next CPU burst of a process, rather than its total length.
Example: Consider the following processes and CPU burst in milliseconds:
Process Burst Time
P1 6
P2 8
P3 7
P4 3

43

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

Gantt Chart of SJF algorithm:

Waiting Time for Processes:


Process Burst Time (ms) Waiting Time
P1 6 3
P2 8 16
P3 7 9
P4 3 0
Average Waiting Time 7 ms
 By looking at the above table the average waiting time by using SJF algorithm is 7ms.
 SJF gives the minimum average waiting time for a given set of processes. SJF is optimal.
 The average waiting time decreases because moving a short process before long process
decrease the waiting time of the short process more than it increases the waiting time of
the long process.
Difficulty with SJF
The difficulty with the SJF algorithm is ―knowing the length of the next CPU request‖. With
Short-Term Scheduling, there is no way to know the length of the next CPU burst. It is not
implemented practically.
Solution for the difficulty
One approach to this problem is to try to approximate SJF scheduling.
 We may not know the length of the next CPU burst, but we may be able to predict its
value. We expect that the next CPU burst will be similar in length to the previous ones.
 By computing an approximation of the length of the next CPU burst, we can pick the
process with the shortest predicted CPU burst.
 The next CPU burst is generally predicted as an Exponential Average of the measured
lengths of previous CPU bursts.
The following formula defines the Exponential average:

tn be the length of the nth CPU burst (i.e. contains the most recent information).
stores the past history.
be our predicted value for the next CPU burst.
α controls the relative weight of recent and past history in our prediction (0 ≤ α ≤1)
 If α=0, then , recent history has no effect
 If α=1 then , only the most recent CPU burst matters.
 If α = 1/2, so recent history and past history are equally weighted.
Shortest Remaining Time First Scheduling (SRTF)
SRTF is the pre-emptive SJF algorithm.
 A new process arrives at the ready queue, while a previous process is still executing.

44

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 The next CPU burst of the newly arrived process may be shorter than the currently
executing process.
 SRTF will preempt the currently executing process and executes the shortest job.
Consider the four processes with arrival times and burst times in milliseconds:
Process Arrival time Burst Time (ms)
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Gantt Chart for SRTF

 Process P1 is started at time 0, since it is the only process in the queue.


 Process P2 arrives at time 1. The remaining time for process P1 (7 milliseconds) is larger
than the time required by process P2 (4 milliseconds), so process P1 is preempted and
process P2 is scheduled.
 The average waiting time = 26/4 = 6.5 milliseconds.
Priority Scheduling
A priority is associated with each process and the CPU is allocated to the process with the
highest priority. Equal-priority processes are scheduled in FCFS order.
 An SJF algorithm is special kind of priority scheduling algorithm where small CPU burst
will have higher priority.
 Priorities can be defined based on time limits, memory requirements, the number of open
files etc.
Example: Consider the following processes with CPU burst and Priorities. All the processes
are arrived at time t=0 in the same order. Low numbers are having higher priority.
Process Burst time (ms) Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Gantt chart for Priority Scheduling:

Process Burst time (ms) Waiting Time


P1 10 6
P2 1 0
P3 2 16
P4 1 18
P5 5 1
Average Waiting Time 8.2 ms

45

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

Priority scheduling can be either Preemptive or Non-preemptive.


A Preemptive Priority Scheduling algorithm will preempt the CPU if the priority of the
newly arrived process is higher than the priority of the currently running process.
Problem: Starvation or Indefinite Blocking
 In priority Scheduling when there is a continuous flow of higher priority processes has
come to ready queue then all the lower priority processes must have to wait for the CPU
until the all the higher priority processes execution completes.
 This leads to lower priority processes blocked from getting CPU for long period of time.
This situation is called Starvation or Indefinite blocking.
 In worst case indefinite blocking may take years to execute the process.
Solution: Aging
Aging involves gradually increasing the priority of processes that wait in the system for a
long time.
Round-Robin Scheduling (RR)
Round-Robin (RR) scheduling algorithm is designed especially for Timesharing systems.
 RR is similar to FCFS scheduling, but preemption is added to enable the system to switch
between processes.
 A small unit of time called a Time Quantum or Time Slice is defined. A time quantum is
generally from 10 to 100 milliseconds in length.
 The ready queue is treated as a Circular queue. New processes are added to the tail of
the ready queue.
 The CPU scheduler goes around the ready queue by allocating the CPU to each process
for a time interval of up to 1 time quantum and dispatches the process.
 If a process CPU burst exceeds 1 time quantum, that process is preempted and is put back
in the ready queue.
In RR scheduling one of two things will then happen.
1. The process may have a CPU burst of less than 1 time quantum. The process itself will
release the CPU voluntarily. The scheduler will then proceed to the next process in the
ready queue.
2. If the CPU burst of the currently running process is longer than 1 time quantum, the timer
will go off and will cause an interrupt to the operating system. A context switch will be
executed and the process will be put at the tail of the ready queue. The CPU scheduler
will then select the next process in the ready queue.
Consider the following set of processes that arrive at time 0 and the processes are arrived in
the order P1, P2, P3 and Time Quanta=4.
Process Burst Time
P1 24
P2 3
P3 3
Gantt chart of Round Robin Scheduling

46

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 If we use a time quantum of 4 milliseconds, then process P1 gets the first 4 milliseconds.
 Since it requires another 20 milliseconds, it is preempted after the first time quantum and
the CPU is given to the next process in the queue, process P2.
 CPU burst of Process P2 is 3, so it does not need 4 milliseconds then it quits before its
time quantum expires. The CPU is then given to the next process P3.
 Once each process has received 1 time quantum, the CPU is returned to process P1 for an
additional time quantum.
The average waiting time under the RR policy is often long.
 P1 waits for 6 milliseconds (10 - 4), P2 waits for 4 milliseconds and P3 waits for 7
milliseconds. Thus, the average waiting time is 17/3 = 5.66 milliseconds.
The performance of the RR algorithm depends on the size of the Time Quantum.
 If the time quantum is extremely large, the RR policy is the same as the FCFS policy.
 If the time quantum is extremely small (i.e. 1 millisecond) the RR approach can result in a
large number of context switches.
 The time taken for context switch value should be a small fraction of Time quanta then
the performance of the RR will be increased.
Note: A rule of thumb is that 80 percent of the CPU bursts should be shorter than the time
quantum.
Multi-Level Queue Scheduling (MLQ)
In Multilevel Queue Scheduling algorithm the processes are classified into different groups.
 A Multilevel queue scheduling partitions the ready queue into several separate queues.
 The processes are permanently assigned to one queue based on memory size, process
priority or process type. Each queue has its own scheduling algorithm.
Example: Foreground processes have highest priority over background processes and these
processes have different response times hence it needs different scheduling.

The above figure shows Multi-level queue scheduling algorithm with five queues, listed
below in order of priority:
1. System processes
2. Interactive processes
3. Interactive editing processes
4. Batch processes
5. Student processes

47

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

Each queue has absolute priority over lower-priority queues.


 No lower level queue processes will start executing unless all the processes in higher
level queue are empty.
Example: The interactive processes start executing only when all the processes in system
queue are empty.
 If a lower priority process is executing and an higher priority process entered into the
queue then lower priority process will be preempted and starts executing a higher priority
process.
Example: If a system process entered the ready queue while an interactive process was
running, the interactive process would be preempted.
Disadvantage: Starvation of Lower level queue
In multilevel queue scheduling algorithm is inflexible.
 The processes are permanently assigned to a queue when they enter the system. Process
are not allowed to move from one queue to other queue.
 There is a chance that lower level queues will be in starvation because unless the higher
level queues are empty no lower level queues will be executing.
 If at any instant of time if there is a process in higher priority queue then there is no
chance that lower level process can be executed eternally.
Multilevel Feedback Queue Scheduling is used to overcome the problem of Multi-level queue
scheduling.
Multilevel Feedback Queue Scheduling (MLFQ)
Multilevel feedback queue scheduling algorithm allows a process to move between queues.
 Processes are separated according to the characteristics of their CPU bursts.
 If a process uses too much CPU time, it will be moved to a lower-priority queue.
 A process that waits too long in a lower-priority queue moved to a higher-priority queue.
 This form of aging prevents starvation.
Consider a multilevel feedback queue scheduler with three queues: queue0, queue1, queue2.
 The scheduler first executes all processes in queue0 then queue1 and then queue2.
 Only when queue0 and queue1 is empty, scheduler will execute processes in queue2.
 A process that arrives for queue1 will preempt a process in queue2. A process in queue1
will in turn be preempted by a process arriving for queue0.

48

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 A process entering the ready queue is put in queue0. A process in queue 0 is given a time
quantum of 8ms. If it does not finish within this time, it is moved to the tail of queue 1.
 If queue 0 is empty, the process at the head of queue1 is given a quantum of 16ms. If it
does not complete, it is preempted and is put into queue2.
 Processes in queue 2 are run on an FCFS basis but are run only when queues 0 and 1 are
empty.
 This scheduling algorithm gives highest priority to any process with a CPU burst of 8ms
or less. Such a process will quickly get the CPU and finish its CPU burst and go off to its
next I/O burst.
 Processes that need more than 8ms but less than 24ms are also served quickly, although
with lower priority than shorter processes.
 Long processes automatically sink to queue2 and are served in FCFS order with any CPU
cycles left over from queues0 and queue1.
A Multi-Level Feedback queue scheduler is defined by the following parameters:
 The number of queues.
 The scheduling algorithm for each queue.
 The method used to determine when to upgrade a process to a higher priority queue.
 The method used to determine when to demote a process to a lower priority queue.
 The method used to determine which queue a process will enter when that process needs
service.
THREAD SCHEDULING
Threads can be divided into two types: Kernel level threads and User level threads.
 Kernel-level threads are being scheduled by the operating system.
 User-level threads are managed by a Thread Library and the kernel is unaware of them.
 User-level threads must be mapped to an associated kernel-level thread to run on a CPU
Contention scope
 The thread library schedules user-level threads to run on an available Light Weight
Process. This scheme is known as Process-Contention Scope (PCS). There will be a
competition for the CPU among threads belonging to the same process.
 PCS is done according to priority. The scheduler selects the runnable thread with the
highest priority to run. User-level thread priorities are set by the programmer and are not
adjusted by the thread library.
 PCS will preempt the thread currently running in favor of a higher-priority thread.
 To decide which kernel-level thread to schedule onto a CPU, the kernel uses System-
Contention Scope (SCS). Competition for the CPU with SCS scheduling takes place
among all threads in the system.
 Windows, Linux and Solaris are the systems schedule threads using only SCS.
MULTIPLE-PROCESSOR SCHEDULING
Scheduling process will become complex with multiple CPU structure but Load Sharing is
possible with multiple CPU structure.
In multiple processor system, we can use any available processor to run any process in the
queue.

49

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

 ABOVE NORMAL PRIORITY CLASS—10


 NORMAL PRIORITY CLASS—8
 BELOW NORMAL PRIORITY CLASS—6
 IDLE PRIORITY CLASS—4
When a thread’s time quantum runs out, that thread is interrupted. If the thread is in the
variable-priority class, its priority is lowered.
 The priority is never lowered below the base priority.
 Lowering the priority tends to limit the CPU consumption of compute-bound threads.
 When a variable priority thread is released from a wait operation, the dispatcher boosts
the priority.
 The amount of the boost depends on what the thread was waiting for.
Windows distinguishes between the foreground process that is currently selected on the
screen and the background processes that are not currently selected.
 When a process moves into the foreground, Windows increases the scheduling quantum
by some factor (i.e. by 3).
 This increase gives the foreground process three times longer to run before a time-sharing
preemption occurs.
Windows 7 introduced user-mode scheduling (UMS) , which allows applications can create
and schedule multiple threads without involving the Windows kernel scheduler.
 Microsoft Windows provides Concurrency Runtime (ConcRT), a concurrent
programming framework for C++ designed for task-based parallelism on multicore
processors.
 ConcRT provides a user-mode scheduler together with facilities for decomposing
programs into tasks, which can then be scheduled on the available processing cores.
THREADS
A thread is a basic unit of CPU utilization; it comprises a thread ID, a program counter, a
register set, and a stack.
 It shares with other threads belonging to the same process its code section, data section,
and other operating-system resources, such as open files and signals.
 A traditional process is called “heavyweight process” has a single thread of control.
 If a process has multiple threads of control, it can perform more than one task at a time.
 The below figure illustrates the difference between a traditional single-threaded process
and a multithreaded process.

58

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

Most operating-system kernels are now multithreaded. Several threads operate in the kernel,
and each thread performs a specific task, such as managing devices, managing memory, or
interrupt handling.
Examples:
1. A web browser might have one thread display images or text while another thread
retrieves data from the network.
2. A word processor may have a thread for displaying graphics, another thread for
responding to keystrokes from the user, and a third thread for performing spelling and
grammar checking in the background.
3. Solaris OS has a set of threads in the kernel specifically for interrupt handling.
4. Linux OS uses a kernel thread for managing the amount of free memory in the system.

Need for Multi-Threading


Consider the scenario; a web server accepts client requests for web pages, images, sound etc.
A busy web server may have thousands of clients concurrently accessing it. If the web server
ran as a traditional single-threaded process, it would be able to service only one client at a
time, and a client might have to wait a very long time for its request to be serviced.
One solution is to have the server run as a single process that accepts requests. When the
server receives a request, it creates a separate process to service that request. Process creation
is time consuming and resource intensive.
If the new process will perform the same tasks as the existing process, why incur all that
overhead?
Hence it is more efficient to use one process that contains multiple threads. If the web-server
process is multi-threaded, the server will create a separate thread that listens for client
requests. When a request is made, rather than creating another process, the server creates a
new thread to service the request and resume listening for additional requests.

Benefits of Multi-Threading
1. Responsiveness: Multithreading an interactive application may allow a program to
continue running even if part of it is blocked or is performing a lengthy operation, thereby
increasing responsiveness to the user.
2. Resource sharing. Processes can only share resources through shared memory and
message passing must be explicitly arranged by the programmer. Whereas threads share
the memory and the resources of the process. The benefit of sharing code and data is that
it allows an application to have several different threads of activity within the same
address space.
3. Economy. Allocating memory and resources for process creation is costly. Because
threads share the resources of the process to which they belong, it is more economical to
create and context-switch threads. In Solaris, creating a process is about thirty times
slower than is creating a thread, and context switching is about five times slower.
4. Scalability. The benefits of multithreading can be even greater in a multiprocessor
architecture, where threads may be running in parallel on different processing cores.
59

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

Types of Threads
There are two types of threads: 1. Kernel threads 2. User threads
 Kernel threads are supported and managed directly by the operating system.
 User threads are supported above the kernel and are managed without kernel support.
Multithreading Models
A relationship must exist between user threads and kernel threads. Three common ways of
establishing such a relationship are:
1. Many-to-One model
2. One-to-One model
3. Many-to-Many model.
Many-to-One model
 The many-to-one model maps many user-level threads to one kernel thread.
 Thread management is done by the thread library in user space, so it is efficient.
 The entire process will block if a thread makes a blocking system call.
 Only one thread can access the kernel at a time, multiple threads are unable to run in
parallel on multicore systems. Hence very few systems continue to use the model because
of its inability to take advantage of multiple processing cores.
One-to-One Model
 The one-to-one model maps each user thread to a kernel thread.
 It provides more concurrency than the many-to-one model by allowing another thread to
run when a thread makes a blocking system call.
 It also allows multiple threads to run in parallel on multiprocessors.
 The only drawback to this model is that creating a user thread requires creating the
corresponding kernel thread.
 Because the overhead of creating kernel threads can burden the performance of an
application, most implementations of this model restrict the number of threads supported
by the system.
 Linux, along with the family of Windows operating systems, implement the one-to-one
model.
Many-to-Many Model
The many-to-many model multiplexes many user-level threads to a smaller or equal number
of kernel threads. The number of kernel threads may be specific to either a particular
application or a particular machine.
Many-to-One Model One-to-One Model Many-to-Many Model

60

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


lOMoARcPSD|17594797

KMIT/CSE/II-II/OS-2 P.VAMSHI KRISHNA

Advantage of Many-to-Many Model


 The many-to-one model allows the developer to create as many user threads as they
wishes; it does not result in true concurrency, because the kernel can schedule only one
thread at a time.
 The one-to-one model allows greater concurrency, but the developer has to be careful not
to create too many threads within an application.
 The many-to-many model suffers from neither of these shortcomings: developers can
create as many user threads as necessary, and the corresponding kernel threads can run in
parallel on a multiprocessor. when a thread performs a blocking system call, the kernel
can schedule another thread for execution.

61

Downloaded by soni sharmila Kadimi (sonisharmila.kadimi@gmail.com)


Inter process communication
Inter process communication is the mechanism provided by the operating system
that allows processes to communicate with each other. This communication could
involve a process letting another process know that some event has occurred or the
transferring of data from one process to another.
A diagram that illustrates inter process communication is as follows −

Synchronization in Inter process Communication


Synchronization is a necessary part of inter process communication. It is either
provided by the inter process control mechanism or handled by the communicating
processes. Some of the methods to provide synchronization are as follows −

 Semaphore
A semaphore is a variable that controls the access to a common resource by
multiple processes. The two types of semaphores are binary semaphores and
counting semaphores.
 Mutual Exclusion
Mutual exclusion requires that only one process thread can enter the critical
section at a time. This is useful for synchronization and also prevents race
conditions.
 Barrier
A barrier does not allow individual processes to proceed until all the processes
reach it. Many parallel languages and collective routines impose barriers.
 Spinlock
This is a type of lock. The processes trying to acquire this lock wait in a loop
while checking if the lock is available or not. This is known as busy waiting
because the process is not doing any useful operation even though it is active.

Approaches to Inter process Communication


The different approaches to implement inter process communication are given as
follows −

 Pipe
A pipe is a data channel that is unidirectional. Two pipes can be used to
create a two-way data channel between two processes. This uses standard
input and output methods. Pipes are used in all POSIX systems as well as
Windows operating systems.
 Socket
The socket is the endpoint for sending or receiving data in a network. This is
true for data sent between processes on the same computer or data sent
between different computers on the same network. Most of the operating
systems use sockets for interprocess communication.
 File
A file is a data record that may be stored on a disk or acquired on demand by
a file server. Multiple processes can access a file as required. All operating
systems use files for data storage.
 Signal
Signals are useful in inter process communication in a limited way. They are
system messages that are sent from one process to another. Normally, signals
are not used to transfer data but are used for remote commands between
processes.
 Shared Memory
Shared memory is the memory that can be simultaneously accessed by
multiple processes. This is done so that the processes can communicate with
each other. All POSIX systems, as well as Windows operating systems use
shared memory.
 Message Queue
Multiple processes can read and write data to the message queue without
being connected to each other. Messages are stored in the queue until their
recipient retrieves them. Message queues are quite useful for inter process
communication and are used by most operating systems.
A diagram that demonstrates message queue and shared memory methods of inter
process communication is as follows −
Process Synchronization
Introduction of Process Synchronization:
On the basis of synchronization, processes are categorized as one of the following two
types:
 Independent Process: The execution of one process does not affect the execution of
other processes.
 Cooperative Process: A process that can affect or be affected by other processes
executing in the system.
Process synchronization problem arises in the case of Cooperative process also because
resources are shared in Cooperative processes.

Race Condition:

When more than one process is executing the same code or accessing the same memory or
any shared variable in that condition there is a possibility that the output or the value of the
shared variable is wrong so for that all the processes doing the race to say that my output is
correct this condition known as a race condition. Several processes access and process the
manipulations over the same data concurrently, then the outcome depends on the particular
order in which the access takes place. A race condition is a situation that may occur inside a
critical section. This happens when the result of multiple thread execution in the critical
section differs according to the order in which the threads execute. Race conditions in
critical sections can be avoided if the critical section is treated as an atomic instruction.
Also, proper thread synchronization using locks or atomic variables can prevent race
conditions.

Critical Section Problem :

A critical section is a code segment that can be accessed by only one process at a time. The
critical section contains shared variables that need to be synchronized to maintain the
consistency of data variables. So the critical section problem means designing a way for
cooperative processes to access shared resources without creating data inconsistencies.
In the entry section, the process requests for entry in the Critical Section.
Any solution to the critical section problem must satisfy three requirements:
 Mutual Exclusion: If a process is executing in its critical section, then no other process
is allowed to execute in the critical section.
 Progress: If no process is executing in the critical section and other processes are
waiting outside the critical section, then only those processes that are not executing in
their remainder section can participate in deciding which will enter in the critical
section next, and the selection can not be postponed indefinitely.
 Bounded Waiting: A bound must exist on the number of times that other processes are
allowed to enter their critical sections after a process has made a request to enter its
critical section and before that request is granted.

Peterson’s Solution:

Peterson’s Solution is a classical software-based solution to the critical section problem. In


Peterson’s solution, we have two shared variables:
 boolean flag[i]: Initialized to FALSE, initially no one is interested in entering the
critical section
 int turn: The process whose turn is to enter the critical section.

Peterson’s Solution preserves all three conditions:


 Mutual Exclusion is assured as only one process can access the critical section at any
time.
 Progress is also assured, as a process outside the critical section does not block other
processes from entering the critical section.
 Bounded Waiting is preserved as every process gets a fair chance.
Disadvantages of Peterson’s solution:
 It involves busy waiting.(In the Peterson’s solution, the code statement- “while(flag[j]
&& turn == j);” is responsible for this. Busy waiting is not favored because it wastes
CPU cycles that could be used to perform other tasks.)
 It is limited to 2 processes.
 Peterson’s solution cannot be used in modern CPU architectures.
Process synchronization problems occur when two processes running concurrently share
the same data or same variable. The value of that variable may not be updated correctly
before its being used by a second process. Such a condition is known as Race around
Condition. There are software as well as hardware solutions to this problem. In this article,
we will talk about the most efficient hardware solution to process synchronization problems
and its implementation.
There are three algorithms in the hardware approach of solving Process Synchronization
problem:
1. Test and Set
2. Swap
3. Unlock and Lock
Hardware instructions in many operating systems help in effective solution of critical
section problems.
Test and Set :
Here, the shared variable is lock which is initialized to false. TestAndSet(lock) algorithm works in this
way – it always returns whatever value is sent to it and sets lock to true. The first process will enter
the critical section at once as TestAndSet(lock) will return false and it’ll break out of the while loop.
The other processes cannot enter now as lock is set to true and so the while loop continues to be
true. Mutual exclusion is ensured. Once the first process gets out of the critical section, lock is
changed to false. So, now the other processes can enter one by one. Progress is also ensured.
However, after the first process any process can go in. There is no queue maintained, so any new
process that finds the lock to be false again, can enter. So bounded waiting is not ensured.
Test and Set Pseudocode –
//Shared variable lock initialized to false
boolean lock;

boolean TestAndSet (boolean &target){


boolean rv = target;
target = true;
return rv;
}

while(1){
while (TestAndSet(lock));
critical section
lock = false;
remainder section
}
2. Swap :
Swap algorithm is a lot like the TestAndSet algorithm. Instead of directly setting lock to true in the
swap function, key is set to true and then swapped with lock. So, again, when a process is in the
critical section, no other process gets to enter it as the value of lock is true. Mutual exclusion is
ensured. Again, out of the critical section, lock is changed to false, so any process finding it gets t
enter the critical section. Progress is ensured. However, again bounded waiting is not ensured for
the very same reason.
Swap Pseudocode –
// Shared variable lock initialized to false
// and individual key initialized to false;
boolean lock;
Individual key;
void swap(boolean &a, boolean &b){
boolean temp = a;
a = b;
b = temp;
}
while (1){
key = true;
while(key)
swap(lock,key);
critical section
lock = false;
remainder section
}
3. Unlock and Lock :
Unlock and Lock Algorithm uses TestAndSet to regulate the value of lock but it adds another value,
waiting[i], for each process which checks whether or not a process has been waiting. A ready queue
is maintained with respect to the process in the critical section. All the processes coming in next are
added to the ready queue with respect to their process number, not necessarily sequentially. Once
the ith process gets out of the critical section, it does not turn lock to false so that any process can
avail the critical section now, which was the problem with the previous algorithms. Instead, it checks
if there is any process waiting in the queue. The queue is taken to be a circular queue. j is considered
to be the next process in line and the while loop checks from jth process to the last process and
again from 0 to (i-1)th process if there is any process waiting to access the critical section. If there is
no process waiting then the lock value is changed to false and any process which comes next can
enter the critical section. If there is, then that process’ waiting value is turned to false, so that the
first while loop becomes false and it can enter the critical section. This ensures bounded waiting. So
the problem of process synchronization can be solved through this algorithm.
Unlock and Lock Pseudocode –
// Shared variable lock initialized to false
// and individual key initialized to false
boolean lock;
Individual key;
Individual waiting[i];
while(1){
waiting[i] = true;
key = true;
while(waiting[i] && key)
key = TestAndSet(lock);
critical section
j = (i+1) % n;
while(j != i && !waiting[j])
j = (j+1) % n;
if(j == i)
lock = false;
else
waiting[j] = false;
remainder section
}

Semaphores:

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 definitions of wait and signal are as follows −

 Wait
The wait operation decrements the value of its argument S, if it is positive. If S is
negative or zero, then no operation is performed.
wait(S)
{
while (S<=0);

S--;
}

 Signal
The signal operation increments the value of its argument S.

signal(S)

S++;
}

Types of Semaphores
There are two main types of semaphores i.e. counting semaphores and binary semaphores.
Details about these are given as follows −
 Counting Semaphores
These are integer value semaphores and have an unrestricted value domain. These
semaphores are used to coordinate the resource access, where the semaphore count is
the number of available resources. If the resources are added, semaphore count
automatically incremented and if the resources are removed, the count is decremented.
 Binary Semaphores
The binary semaphores are like counting semaphores but their value is restricted to 0
and 1. The wait operation only works when the semaphore is 1 and the signal
operation succeeds when semaphore is 0. It is sometimes easier to implement binary
semaphores than counting semaphores.

Advantages of Semaphores
Some of the advantages of semaphores are as follows −

 Semaphores allow only one process into the critical section. They follow the mutual
exclusion principle strictly and are much more efficient than some other methods of
synchronization.
 There is no resource wastage because of busy waiting in semaphores as processor time
is not wasted unnecessarily to check if a condition is fulfilled to allow a process to
access the critical section.
 Semaphores are implemented in the machine independent code of the microkernel. So
they are machine independent.
Disadvantages of Semaphores
Some of the disadvantages of semaphores are as follows −

 Semaphores are complicated so the wait and signal operations must be implemented in
the correct order to prevent deadlocks.
 Semaphores are impractical for last scale use as their use leads to loss of modularity.
This happens because the wait and signal operations prevent the creation of a
structured layout for the system.
 Semaphores may lead to a priority inversion where low priority processes may access
the critical section first and high priority processes later.
Classic problems of synchronization
The following are some classic problems of synchronization:

 The Producer–Consumer Problem (also called The Bounded Buffer Problem);


 The Readers–Writers Problem;
 The Dining Philosophers Problem.
 The Sleeping Barber Problem.
These problems are used to test nearly every newly proposed synchronization scheme or
primitive.
The Producer–Consumer Problem:
Also known as the Producer-Consumer problem. In this problem, there is a buffer of
n slots, and each buffer is capable of storing one unit of data. There are two processes
that are operating on the buffer – Producer and Consumer. The producer tries to insert
data and the consumer tries to remove data.
If the processes are run simultaneously they will not yield the expected output.
The solution to this problem is creating two semaphores, one full and the other empty
to keep a track of the concurrent processes.
The producer consumer problem is a synchronization problem. There is a fixed size buffer
and the producer produces items and enters them into the buffer. The consumer removes the
items from the buffer and consumes them.
A producer should not produce items into the buffer when the consumer is consuming an
item from the buffer and vice versa. So the buffer should only be accessed by the producer or
consumer at a time.
The producer consumer problem can be resolved using semaphores. The codes for the
producer and consumer process are given as follows −
Producer Process
The code that defines the producer process is given below −

do {
.
. PRODUCE ITEM
.
wait(empty);
wait(mutex);
.
. PUT ITEM IN BUFFER
.
signal(mutex);
signal(full);

} while(1);

In the above code, mutex, empty and full are semaphores. Here mutex is initialized to 1,
empty is initialized to n (maximum size of the buffer) and full is initialized to 0.
The mutex semaphore ensures mutual exclusion. The empty and full semaphores count the
number of empty and full spaces in the buffer.
After the item is produced, wait operation is carried out on empty. This indicates that the
empty space in the buffer has decreased by 1. Then wait operation is carried out on mutex so
that consumer process cannot interfere.
After the item is put in the buffer, signal operation is carried out on mutex and full. The
former indicates that consumer process can now act and the latter shows that the buffer is
full by 1.
Consumer Process
The code that defines the consumer process is given below:

do {

wait(full);
wait(mutex);
..
. REMOVE ITEM FROM BUFFER
.
signal(mutex);
signal(empty);
.
. CONSUME ITEM
.
} while(1);
The wait operation is carried out on full. This indicates that items in the buffer have
decreased by 1. Then wait operation is carried out on mutex so that producer process cannot
interfere.
Then the item is removed from buffer. After that, signal operation is carried out on mutex
and empty. The former indicates that consumer process can now act and the latter shows that
the empty space in the buffer has increased by 1.

Readers and Writers Problem


This problem occurs when many threads of execution try to access the same shared
resources at a time. Some threads may read, and some may write. In this scenario, we
may get faulty outputs.
The readers-writers problem relates to an object such as a file that is shared between multiple
processes. Some of these processes are readers i.e. they only want to read the data from the
object and some of the processes are writers i.e. they want to write into the object.
The readers-writers problem is used to manage synchronization so that there are no problems
with the object data. For example - If two readers access the object at the same time there is
no problem. However if two writers or a reader and writer access the object at the same time,
there may be problems.
To solve this situation, a writer should get exclusive access to an object i.e. when a writer is
accessing the object, no reader or writer may access it. However, multiple readers can access
the object at the same time.
This can be implemented using semaphores. The codes for the reader and writer process in
the reader-writer problem are given as follows −

Reader Process
The code that defines the reader process is given below −

wait (mutex);
rc ++;
if (rc == 1)
wait (wrt);
signal(mutex);
.
. READ THE OBJECT
.
wait(mutex);
rc --;
if (rc == 0)
signal (wrt);
signal(mutex);
In the above code, mutex and wrt are semaphores that are initialized to 1. Also, rc is a
variable that is initialized to 0. The mutex semaphore ensures mutual exclusion and wrt
handles the writing mechanism and is common to the reader and writer process code.
The variable rc denotes the number of readers accessing the object. As soon as rc becomes 1,
wait operation is used on wrt. This means that a writer cannot access the object anymore.
After the read operation is done, rc is decremented. When re becomes 0, signal operation is
used on wrt. So a writer can access the object now.

Writer Process
The code that defines the writer process is given below:

wait(wrt);
.
. WRITE INTO THE OBJECT
.
signal(wrt);
If a writer wants to access the object, wait operation is performed on wrt. After that no other
writer can access the object. When a writer is done writing into the object, signal operation is
performed on wrt.
Dining Philosopher’s problem
This problem states that there are K numbers of philosophers sitting around a circular
table with one chopstick placed between each pair of philosophers. The philosopher
will be able to eat if he can pick up two chopsticks that are adjacent to the
philosopher.
This problem deals with the allocation of limited resources.
The dining philosopher’s problem states that there are 5 philosophers sharing a circular table
and they eat and think alternatively. There is a bowl of rice for each of the philosophers and
5 chopsticks. A philosopher needs both their right and left chopstick to eat. A hungry
philosopher may only eat if there are both chopsticks available. Otherwise a philosopher puts
down their chopstick and begin thinking again.
The dining philosopher is a classic synchronization problem as it demonstrates a large class
of concurrency control problems.
Solution of Dining Philosophers Problem
A solution of the Dining Philosophers Problem is to use a semaphore to represent a
chopstick. A chopstick can be picked up by executing a wait operation on the semaphore and
released by executing a signal semaphore.
The structure of the chopstick is shown below −

Semaphore chopstick [5];


Initially the elements of the chopstick are initialized to 1 as the chopsticks are on the table
and not picked up by a philosopher.
The structure of a random philosopher i is given as follows −

do {
wait( chopstick[i] );
wait( chopstick[ (i+1) % 5] );
..
. EATING THE RICE
.
signal( chopstick[i] );
signal( chopstick[ (i+1) % 5] );
.
. THINKING
.
} while(1);
In the above structure, first wait operation is performed on chopstick[i] and chopstick[ (i+1)
% 5]. This means that the philosopher i have picked up the chopsticks on his sides. Then the
eating function is performed.
After that, signal operation is performed on chopstick[i] and chopstick[ (i+1) % 5]. This
means that the philosopher i has eaten and put down the chopsticks on his sides. Then the
philosopher goes back to thinking.

Difficulty with the solution


The above solution makes sure that no two neighboring philosophers can eat at the same
time. But this solution can lead to a deadlock. This may happen if all the philosophers pick
their left chopstick simultaneously. Then none of them can eat and deadlock occurs.
Some of the ways to avoid deadlock are as follows −

 There should be at most four philosophers on the table.


 An even philosopher should pick the right chopstick and then the left chopstick while
an odd philosopher should pick the left chopstick and then the right chopstick.
 A philosopher should only be allowed to pick their chopstick if both are available at
the same time.
Prerequisite – Inter Process Communication
SLEEPING BARBER PROBLEM:
Problem : The analogy is based upon a hypothetical barber shop with one barber. There is a barber
shop which has one barber, one barber chair, and n chairs for waiting for customers if there are any
to sit on the chair.
 If there is no customer, then the barber sleeps in his own chair.
 When a customer arrives, he has to wake up the barber.
 If there are many customers and the barber is cutting a customer’s hair, then the
remaining customers either wait if there are empty chairs in the waiting room or they
leave if no chairs are empty.

 Solution : The solution to this problem includes three semaphores.First is for the
customer which counts the number of customers present in the waiting room
(customer in the barber chair is not included because he is not waiting). Second, the
barber 0 or 1 is used to tell whether the barber is idle or is working, And the third
mutex is used to provide the mutual exclusion which is required for the process to
execute. In the solution, the customer has the record of the number of customers
waiting in the waiting room if the number of customers is equal to the number of
chairs in the waiting room then the upcoming customer leaves the barbershop.
 When the barber shows up in the morning, he executes the procedure barber, causing
him to block on the semaphore customers because it is initially 0. Then the barber
goes to sleep until the first customer comes up.
 When a customer arrives, he executes customer procedure the customer acquires the
mutex for entering the critical region, if another customer enters thereafter, the second
one will not be able to anything until the first one has released the mutex. The
customer then checks the chairs in the waiting room if waiting customers are less then
the number of chairs then he sits otherwise he leaves and releases the mutex.

 If the chair is available then customer sits in the waiting room and increments the
variable waiting value and also increases the customer’s semaphore this wakes up the
barber if he is sleeping.
 At this point, customer and barber are both awake and the barber is ready to give that
person a haircut. When the haircut is over, the customer exits the procedure and if
there are no customers in waiting room barber sleeps.

Monitors in Process Synchronization


The monitor is one of the ways to achieve Process synchronization. The monitor is
supported by programming languages to achieve mutual exclusion between processes. For
example Java Synchronized methods. Java provides wait() and notify() constructs.
1. It is the collection of condition variables and procedures combined together in a special
kind of module or a package.
2. The processes running outside the monitor can’t access the internal variable of the
monitor but can call procedures of the monitor.
3. Only one process at a time can execute code inside monitors.
Syntax:

Condition Variables:
Two different operations are performed on the condition variables of the monitor.
Wait signal.
let say we have 2 condition variables
condition x, y; // Declaring variable
Wait operation
x.wait() : Process performing wait operation on any condition variable are suspended. The
suspended processes are placed in block queue of that condition variable.
Note: Each condition variable has its unique block queue.
Signal operation
x.signal(): When a process performs signal operation on condition variable, one of the blocked
processes is given chance.
If (x block queue empty)
// Ignore signal
else
// Resume a process from block queue.
Advantages of Monitor:
Monitors have the advantage of making parallel programming easier and less error prone than using
techniques such as semaphore.
Disadvantages of Monitor:
Monitors have to be implemented as part of the programming language . The compiler must
generate code for them. This gives the compiler the additional burden of having to know what
operating system facilities are available to control access to critical sections in concurrent processes.
Some languages that do support monitors are Java,C#,Visual Basic,Ada and concurrent Euclid.
Please write comments if you find anything incorrect, or you want to share more
information about the topic discussed above
EE 442 Operating Systems Ch. 5 Deadlocks

Chapter 5
Deadlocks

5.1 Definition
In a multiprogramming system, processes request resources. If those resources are being
used by other processes then the process enters a waiting state. However, if other
processes are also in a waiting state, we have deadlock.

The formal definition of deadlock is as follows:

Definition: A set of processes is in a deadlock state if every process in the set is waiting for
an event (release) that can only be caused by some other process in the same set.

Example 5.1

Process-1 requests the printer, gets it


Process-2 requests the tape unit, gets it Process-1 and
Process-1 requests the tape unit, waits Process-2 are
Process-2 requests the printer, waits deadlocked!

In this chapter, we shall analyze deadlocks with the following assumptions:

• A process must request a resource before using it. It must release the resource after
using it. (request Æ use Æ release)

• A process cannot request a number more than the total number of resources available in
the system.

For the resources of the system, a resource table shall be kept, which shows whether each
process is free or if occupied, by which process it is occupied. For every resource, queues
shall be kept, indicating the names of processes waiting for that resource.

A deadlock occurs if and only if the following four conditions hold in a system
simultaneously:

1. Mutual Exclusion: At least one of the resources is non-sharable (that is; only a limited
number of processes can use it at a time and if it is requested by a process while it is
being used by another one, the requesting process has to wait until the resource is
released.).

Lecture Notes by Uğur Halıcı 47


EE 442 Operating Systems Ch. 5 Deadlocks

2. Hold and Wait: There must be at least one process that is holding at least one
resource and waiting for other resources that are being hold by other processes.

3. No Preemption: No resource can be preempted before the holding process


completes its task with that resource.

4. Circular Wait: There exists a set of processes: {P1, P2, ..., Pn} such that

P1 is waiting for a resource held by P2


P2 is waiting for a resource held by P3
...
Pn-1 is waiting for a resource held by Pn
Pn is waiting for a resource held by P1

Methods for handling deadlocks are:

• Deadlock prevention
• Deadlock avoidance
• Deadlock detection and recovery.

5.2 Resource Allocation Graphs

Resource allocation graphs are drawn in order to see the allocation relations of processes
and resources easily. In these graphs, processes are represented by circles and resources
are represented by boxes. Resource boxes have some number of dots inside indicating
available number of that resource, that is number of instances.

pi ● rj Process pi is waiting for resource rj

pi ● rj Process pi has allocated resource rj

• If the resource allocation graph contains no cycles then there is no deadlock in the
system at that instance.

• If the resource allocation graph contains a cycle then a deadlock may exist.

• If there is a cycle, and the cycle involves only resources which have a single
instance, then a deadlock has occurred.

Lecture Notes by Uğur Halıcı 48


EE 442 Operating Systems Ch. 5 Deadlocks

Example 5.2

● r1 ● r3

p2

p1
p3
● r2

There are three cycles, so a deadlock may exists. Actually p1, p2 and p3 are deadlocked

Example 5.3

p1

● r1 ● r2
● ●

p2
p3 p4

There is a cycle, however there is no deadlock. If p4 releases r2, r2 may be allocated to p3,
which breaks the cycle.

5.3 Deadlock Prevention


To prevent the system from deadlocks, one of the four discussed conditions that may create
a deadlock should be discarded. The methods for those conditions are as follows:

Mutual Exclusion:

In general, we do not have systems with all resources being sharable. Some resources like
printers, processing units are non-sharable. So it is not possible to prevent deadlocks by
denying mutual exclusion.

Hold and Wait:

One protocol to ensure that hold-and-wait condition never occurs says each process must
request and get all of its resources before it begins execution.

Another protocol is “Each process can request resources only when it does not occupies any
resources.”

Lecture Notes by Uğur Halıcı 49


EE 442 Operating Systems Ch. 5 Deadlocks

The second protocol is better. However, both protocols cause low resource utilization and
starvation. Many resources are allocated but most of them are unused for a long period of
time. A process that requests several commonly used resources causes many others to
wait indefinitely.

No Preemption:

One protocol is “If a process that is holding some resources requests another resource and
that resource cannot be allocated to it, then it must release all resources that are currently
allocated to it.”

Another protocol is “When a process requests some resources, if they are available, allocate
them. If a resource it requested is not available, then we check whether it is being used or it
is allocated to some other process waiting for other resources. If that resource is not being
used, then the OS preempts it from the waiting process and allocate it to the requesting
process. If that resource is used, the requesting process must wait.” This protocol can be
applied to resources whose states can easily be saved and restored (registers, memory
space). It cannot be applied to resources like printers.

Circular Wait:

One protocol to ensure that the circular wait condition never holds is “Impose a linear
ordering of all resource types.” Then, each process can only request resources in an
increasing order of priority.

For example, set priorities for r1 = 1, r2 = 2, r3 = 3, and r4 = 4. With these priorities, if


process P wants to use r1 and r3, it should first request r1, then r3.

Another protocol is “Whenever a process requests a resource rj, it must have released all
resources rk with priority(rk) ≥ priority (rj).

5.4 Deadlock avoidance


Given some additional information on how each process will request resources, it is possible
to construct an algorithm that will avoid deadlock states. The algorithm will dynamically
examine the resource allocation operations to ensure that there won't be a circular wait on
resources.

When a process requests a resource that is already available, the system must decide
whether that resource can immediately be allocated or not. The resource is immediately
allocated only if it leaves the system in a safe state.

A state is safe if the system can allocate resources to each process in some order avoiding
a deadlock. A deadlock state is an unsafe state.

Example 5.4

Consider a system with 12 tape drives. Assume there are three processes : p1, p2, p3.
Assume we know the maximum number of tape drives that each process may request:

p1 : 10, p2 : 4, p3 : 9

Suppose at time tnow, 9 tape drives are allocated as follows :

Lecture Notes by Uğur Halıcı 50


EE 442 Operating Systems Ch. 5 Deadlocks

p1 : 5, p2 : 2, p3 : 2

So, we have three more tape drives which are free.

This system is in a safe state because it we sequence processes as: <p2, p1, p3>, then p2
can get two more tape drives and it finishes its job, and returns four tape drives to the
system. Then the system will have 5 free tape drives. Allocate all of them to p1, it gets 10
tape drives and finishes its job. p1 then returns all 10 drives to the system. Then p3 can get
7 more tape drives and it does its job.

It is possible to go from a safe state to an unsafe state:

Example 5.5

Consider the above example. At time tnow+1, p3 requests one more tape drive and gets it.
Now, the system is in an unsafe state.

There are two free tape drives, so only p2 can be allocated all its tape drives. When it
finishes and returns all 4 tape drives, the system will have four free tape drives.

p1 is allocated 5, may request 5 more → has to wait


p3 is allocated 3, may request 6 more → has to wait

We allocated p3 one more tape drive and this caused a deadlock.

Banker's Algorithm (Dijkstra and Habermann)

It is a deadlock avoidance algorithm. The following data structures are used in the algorithm:

m = number of resources
n = number of processes

Available [m] : One dimensional array of size m. It indicates the number of available
resources of each type. For example, if Available [i] is k, there are k instances of resource ri.

Max [n,m] : Two dimensional array of size n*m. It defines the maximum demand of each
process from each resource type. For example, if Max [i,j] is k, process pi may request at
most k instances of resource type rj.

Allocation [n,m] : Two dimensional array of size n*m. It defines the number of resources of
each type currently allocated to each process.

Need [n,m] : Two dimensional array of size n*m. It indicates the remaining need of each
process, of each resource type. If Need [i,j] is k, process pi may need k more instances of
resource type rj. Note that Need [i,j] = Max [i,j] - Allocation [i,j].

Request [n,m] : Two dimensional array of size n*m. It indicates the pending requests of each
process, of each resource type.

Now, take each row vector in Allocation and Need as Allocation(i) and Need(i). (Allocation(i)
specifies the resources currently allocated to process pi. )

Lecture Notes by Uğur Halıcı 51


EE 442 Operating Systems Ch. 5 Deadlocks

Define the ≤ relation between two vectors X and Y , of equal size = n as :

X≤Y ⇔ X [ i ] ≤ Y [ i ] , i = 1,2, ..., n


X !≤ Y ⇔ X [ i ] > Y [ i ] for some i

The algorithm is as follows:

1. Process pi makes requests for resources. Let Request(i) be the corresponding request
vector. So, if pi wants k instances of resource type rj, then Request(i)[j] = k.

2. If Request(i) !≤ Need(i), there is an error.

3. Otherwise, if Request(i) !≤ Available, then pi must wait.

4. Otherwise, Modify the data structures as follows :

Available = Available - Request(i)


Allocation(i) = Allocation(i) + Request(i)
Need(i) = Need(i) - Request(i)

5. Check whether the resulting state is safe. (Use the safety algorithm presented below.)

6. If the state is safe, do the allocation. Otherwise, pi must wait for Request(i).

Safety Algorithm to perform Step 5:

Let Work and Finish be vectors of length m and n, respectively.

1. Initialize Work = Available, Finish [j] = false, for all j.

2. Find an i such that Finish [ i ] = false and Need(i) ≤ Work

If no such i is found, go to step 4.

3. If an i is found, then for that i, do :

Work = Work + Allocation(i)


Finish [i] = true

Go to step 2.

4. If Finish [j] = true for all j, then the system is in a safe state.

Banker's algorithm is O(m × (n2)).

Lecture Notes by Uğur Halıcı 52


EE 442 Operating Systems Ch. 5 Deadlocks

Example 5.6: (Banker's algorithm)

Given

Available = [1 4 1]

⎡1 3 1⎤
Max = ⎢ ⎥
⎣1 4 1⎦

⎡0 0 0 ⎤
Allocation= ⎢ ⎥
⎣0 0 0 ⎦

⎡1 3 1⎤
Need = ⎢ ⎥
⎣1 4 1⎦

⎡1 2 0⎤
Request = ⎢ ⎥
⎣0 2 1 ⎦

Request(1) is to be processed. If it is satisfied data would become:

Available = [0 2 1]

⎡1 2 0⎤
Allocation= ⎢ ⎥
⎣0 0 0 ⎦

⎡0 1 1⎤
Need = ⎢ ⎥
⎣1 4 1⎦

Now, apply the safety algorithm:

Work = [ 0 2 1 ]

⎡ false ⎤
Finish = ⎢ ⎥
⎣ false ⎦

i=1:

Need(1) = [ 0 1 1 ] ≤ Work ? Yes.


Work = Work + Allocation(1) = [ 1 4 1 ]
Finish (1) = true

i=2:

Need(2) = [ 1 4 1 ] ≤ Work ? Yes.


Work = Work + Allocation(2) = [ 1 4 1 ]
Finish (2)= true

Lecture Notes by Uğur Halıcı 53


EE 442 Operating Systems Ch. 5 Deadlocks

System is in a safe state, so do the allocation. If the algorithm is repeated for Request(2),
the system will end up in an unsafe state.

5.5 Deadlock Detection

If a system has no deadlock prevention and no deadlock avoidance scheme, then it needs a
deadlock detection scheme with recovery from deadlock capability. For this, information
should be kept on the allocation of resources to processes, and on outstanding allocation
requests. Then, an algorithm is needed which will determine whether the system has
entered a deadlock state. This algorithm must be invoked periodically.

Deadlock Detection Algorithm (Shoshani and Coffman)

Data Structure is as:

Available [m]
Allocation [n,m] as in Banker's Algorithm
Request [n,m] indicates the current requests of each process.

Let Work and Finish be vectors of length m and n, as in the safety algorithm.

The algorithm is as follows:

1. Initialize Work = Available


For i = 1 to n do
If Allocation(i) = 0 then Finish[i] = true else Finish[i] = false

2. Search an i such that

Finish[i] = false and Request(i) ≤ Work

If no such i can be found, go to step 4.

3. For that i found in step 2 do:

Work = Work + Allocation(i)


Finish[i] = true

Go to step 2.

4. If Finish[i] ≠ true for a some i then the system is in deadlock state else the system is safe

Lecture Notes by Uğur Halıcı 54


EE 442 Operating Systems Ch. 5 Deadlocks

Example 5.7

Examine whether the system whose resource allocation graph is given below is deadlocked
or not.

● r1 ● r3

p1

p3
p2

r2 ●

p4

First, let’s form the required structures:

Available = [0 0 0]

⎡1 0 0⎤
⎢0 1 0⎥⎥
Allocation = ⎢
⎢0 0 1⎥
⎢ ⎥
⎣0 0 1⎦

⎡0 1 1⎤
⎢0 0 1 ⎥⎥
Request = ⎢
⎢1 0 0⎥
⎢ ⎥
⎣0 0 0⎦

⎡ False⎤
⎢ False⎥
Finish = ⎢ ⎥
⎢ False⎥
⎢ ⎥
⎣ False⎦

Work = [0 0 0]

Request(4) ≤ Work → i = 4:

Work = Work + Allocation(4) = [0 0 0] + [0 0 1] = [0 0 1] ;


Finish[4] = True

Request(2) ≤ Work → i = 2:

Lecture Notes by Uğur Halıcı 55


EE 442 Operating Systems Ch. 5 Deadlocks

Work = Work + Allocation(2) = [0 0 1] + [0 1 0] = [0 1 1] ;


Finish[2] = True

Request(1) ≤ Work→ i = 1:

Work = Work + Allocation(1) = [0 1 1] + [1 0 0] = [1 1 1] ;


Finish[1] = True

Request(3) ≤ Work → i = 3:

Work = Work + Allocation(3) = [1 1 1] + [0 0 1] = [1 1 2] ;


Finish[3] = True

Since Finish[i] = true for all i, there is no deadlock in the system .

Recovery From Deadlock

If the system is in a deadlock state, some methods for recovering it from the deadlock state
must be applied. There are various ways for recovery:

• Allocate one resource to several processes, by violating mutual exclusion.


• Preempt some resources from some of the deadlocked processes.
• Abort one or more processes in order to break the deadlock.

If preemption is used:

1. Select a victim. (Which resource(s) is/are to be preempted from which process?)

2. Rollback: If we preempt a resource from a process, roll the process back to some safe
state and mak it continue.

Here the OS may be probably encounter the problem of starvation. How can we guarantee
that resources will not always be preempted from the same process?

In selecting a victim, important parameters are:

• Process priorities
• How long the process has occupied?
• How long will it occupy to finish its job
• How many resources of what type did the process use?
• How many more resources does the process need to finish its job?
• How many processes will be rolled back? (More than one victim may be selected.)

For rollback, the simplest solution is a total rollback. A better solution is to roll the victim
process back only as far as it’s necessary to break the deadlock. However, the OS needs to
keep more information about process states to use the second solution.

To avoid starvation, ensure that a process can be picked as a victim for only a small number
of times. So, it is a wise idea to include the number of rollbacks as a parameter.

Lecture Notes by Uğur Halıcı 56


Unit-5 Memory Management

 Swapping
 Contiguous memory allocation
 Paging
 Segmentation
 Virtual Memory
 Demand Paging
 Page-replacement algorithms
 Allocation of frames
 Thrashing

Memory Management

What do you mean by memory management?

Memory is the important part of the computer that is used to store the data. Its management is
critical to the computer system because the amount of main memory available in a computer
system is very limited. At any time, many processes are competing for it. Moreover, to
increase performance, several processes are executed simultaneously. For this, we must keep
several processes in the main memory, so it is even more important to manage them
effectively.

Memory management plays several roles in a computer system.

Following are the important roles in a computer system:


o Memory manager is used to keep track of the status of memory locations, whether it
is free or allocated. It addresses primary memory by providing abstractions so that
software perceives a large memory is allocated to it.
o Memory manager permits computers with a small amount of main memory to execute
programs larger than the size or amount of available memory. It does this by moving
information back and forth between primary memory and secondary memory by
using the concept of swapping.
o The memory manager is responsible for protecting the memory allocated to each
process from being corrupted by another process. If this is not ensured, then the
system may exhibit unpredictable behavior.
o Memory managers should enable sharing of memory space between processes.
Thus, two programs can reside at the same memory location although at different
times.

Memory management Techniques:

The Memory management Techniques can be classified into following main categories:

o Contiguous memory management schemes


o Non-Contiguous memory management schemes
Contiguous memory management schemes:

In a Contiguous memory management scheme, each program occupies a single contiguous


block of storage locations, i.e., a set of memory locations with consecutive addresses.

Single contiguous memory management schemes:

The Single contiguous memory management scheme is the simplest memory management
scheme used in the earliest generation of computer systems. In this scheme, the main
memory is divided into two contiguous areas or partitions. The operating systems reside
permanently in one partition, generally at the lower memory, and the user process is
loaded into the other partition.

Advantages of Single contiguous memory management schemes:

o Simple to implement.
o Easy to manage and design.
o In a Single contiguous memory management scheme, once a process is loaded, it is
given full processor's time, and no other processor will interrupt it.

Disadvantages of Single contiguous memory management schemes:

o Wastage of memory space due to unused memory as the process is unlikely to use all
the available memory space.
o The CPU remains idle, waiting for the disk to load the binary image into the main
memory.
o It cannot be executed if the program is too large to fit the entire available main
memory space.
o It does not support multiprogramming, i.e., it cannot handle multiple programs
simultaneously.
Multiple Partitioning:

The single Contiguous memory management scheme is inefficient as it limits computers


to execute only one program at a time resulting in wastage in memory space and CPU
time. The problem of inefficient CPU use can be overcome using multiprogramming that
allows more than one program to run concurrently. To switch between two processes, the
operating systems need to load both processes into the main memory. The operating
system needs to divide the available main memory into multiple parts to load multiple
processes into the main memory. Thus multiple processes can reside in the main memory
simultaneously.

The multiple partitioning schemes can be of two types:

o Fixed Partitioning
o Dynamic Partitioning

Fixed Partitioning

The main memory is divided into several fixed-sized partitions in a fixed partition
memory management scheme or static partitioning. These partitions can be of the same size
or different sizes. Each partition can hold a single process. The number of partitions
determines the degree of multiprogramming, i.e., the maximum number of processes in
memory. These partitions are made at the time of system generation and remain fixed after
that.

Advantages of Fixed Partitioning memory management schemes:

o Simple to implement.
o Easy to manage and design.

Disadvantages of Fixed Partitioning memory management schemes:

o This scheme suffers from internal fragmentation.


o The number of partitions is specified at the time of system generation.

Dynamic Partitioning

The dynamic partitioning was designed to overcome the problems of a fixed partitioning
scheme. In a dynamic partitioning scheme, each process occupies only as much memory as
they require when loaded for processing. Requested processes are allocated memory until the
entire physical memory is exhausted or the remaining space is insufficient to hold the
requesting process. In this scheme the partitions used are of variable size, and the number
of partitions is not defined at the system generation time.
Advantages of Dynamic Partitioning memory management schemes:

o Simple to implement.
o Easy to manage and design.

Disadvantages of Dynamic Partitioning memory management schemes:

o This scheme also suffers from internal fragmentation.


o The number of partitions is specified at the time of system segmentation.

Non-Contiguous memory management schemes:

In a Non-Contiguous memory management scheme, the program is divided into different


blocks and loaded at different portions of the memory that need not necessarily be
adjacent to one another. This scheme can be classified depending upon the size of blocks
and whether the blocks reside in the main memory or not.

What is paging?

Paging is a technique that eliminates the requirements of contiguous allocation of main


memory. In this, the main memory is divided into fixed-size blocks of physical memory
called frames. The size of a frame should be kept the same as that of a page to maximize the
main memory and avoid external fragmentation.

Advantages of paging:

o Pages reduce external fragmentation.


o Simple to implement.
o Memory efficient.
o Due to the equal size of frames, swapping becomes very easy.
o It is used for faster access of data.

What is Segmentation?

Segmentation is a technique that eliminates the requirements of contiguous allocation of main


memory. In this, the main memory is divided into variable-size blocks of physical
memory called segments. It is based on the way the programmer follows to structure their
programs. With segmented memory allocation, each job is divided into several segments of
different sizes, one for each module. Functions, subroutines, stack, array, etc., are examples
of such modules.

Non-Contiguous Memory Allocation-

 Non-contiguous memory allocation is a memory allocation technique.


 It allows to store parts of a single process in a non-contiguous fashion.
 Thus, different parts of the same process can be stored at different places in the main
memory.
Techniques-
There are two popular techniques used for non-contiguous memory allocation-

1. Paging
2. Segmentation
Paging-
 Paging is a fixed size partitioning scheme.
 In paging, secondary memory and main memory are divided into equal fixed size
partitions.
 The partitions of secondary memory are called as pages.
 The partitions of main memory are called as frames.

 Each process is divided into parts where size of each part is same as page size.
 The size of the last part may be less than the page size.
 The pages of process are stored in the frames of main memory depending upon their
availability.

Example-
Consider a process is divided into 4 pages P0, P1, P2 and P3.
 Depending upon the availability, these pages may be stored in the main memory frames in
a non-contiguous fashion as shown-

Translating Logical Address into Physical Address-

 CPU always generates a logical address.


 A physical address is needed to access the main memory.

Following steps are followed to translate logical address into physical address-
Step-01:
CPU generates a logical address consisting of two parts-
1. Page Number
2. Page Offset
 Page Number specifies the specific page of the process from which CPU wants to read the
data.
 Page Offset specifies the specific word on the page that CPU wants to read.
Step-02:
For the page number generated by the CPU,
 Page Table provides the corresponding frame number (base address of the frame) where
that page is stored in the main memory.
Step-03:
 The frame number combined with the page offset forms the required physical address.

 Frame number specifies the specific frame where the required page is stored.
 Page Offset specifies the specific word that has to be read from that page.
Diagram-
The following diagram illustrates the above steps of translating logical address into physical
address-

Advantages-
The advantages of paging are-
 It allows to store parts of a single process in a non-contiguous fashion.
 It solves the problem of external fragmentation.

Disadvantages-
The disadvantages of paging are-
 It suffers from internal fragmentation.
 There is an overhead of maintaining a page table for each process.
 The times taken to fetch the instruction increases since now two memory accesses are
required.

Fragmentation
As processes are loaded and removed from memory, the free memory space is broken into
little pieces. It happens after sometimes that processes cannot be allocated to memory blocks
considering their small size and memory blocks remains unused. This problem is known as
Fragmentation.
External fragmentation
Total memory space is enough to satisfy a request or to reside a process in it, but it is not
contiguous, so it cannot be used.
Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left unused, as it
cannot be used by another process.
External fragmentation can be reduced by compaction or shuffle memory contents to place all
free memory together in one large block. To make compaction feasible, relocation should be
dynamic.
The internal fragmentation can be reduced by effectively assigning the smallest partition but
large enough for the process.

Segmentation

In Operating Systems, Segmentation is a memory management technique in which the


memory is divided into the variable size parts. Each part is known as a segment which can be
allocated to a process.

The details about each segment are stored in a table called a segment table. Segment table is
stored in one (or many) of the segments.

Segment table contains mainly two information about segment:

1. Base: It is the base address of the segment


2. Limit: It is the length of the segment.
Why Segmentation is required?

Till now, we were using Paging as our main memory management technique. Paging is more
close to the Operating system rather than the User. It divides all the processes into the form of
pages regardless of the fact that a process can have some relative parts of functions which
need to be loaded in the same page.

Operating system doesn't care about the User's view of the process. It may divide the same
function into different pages and those pages may or may not be loaded at the same time into
the memory. It decreases the efficiency of the system.

It is better to have segmentation which divides the process into the segments. Each segment
contains the same type of functions such as the main function can be included in one segment
and the library functions can be included in the other segment.

Translation of Logical address into physical address by segment table

CPU generates a logical address which contains two parts:

1. Segment Number
2. Offset

For Example:

Suppose a 16 bit address is used with 4 bits for the segment number and 12 bits for the
segment offset so the maximum segment size is 4096 and the maximum number of segments
that can be refereed is 16.
When a program is loaded into memory, the segmentation system tries to locate space that is
large enough to hold the first segment of the process, space information is obtained from the
free list maintained by memory manager. Then it tries to locate space for other segments.
Once adequate space is located for all the segments, it loads them into their respective areas.

The operating system also generates a segment map table for each program.

With the help of segment map tables and hardware assistance, the operating system can easily
translate a logical address into physical address on execution of a program.

The Segment number is mapped to the segment table. The limit of the respective segment is
compared with the offset. If the offset is less than the limit then the address is valid otherwise
it throws an error as the address is invalid.

In the case of valid addresses, the base address of the segment is added to the offset to get the
physical address of the actual word in the main memory.

The above figure shows how address translation is done in case of segmentation.

Advantages of Segmentation

1. No internal fragmentation
2. Average Segment Size is larger than the actual page size.
3. Less overhead
4. It is easier to relocate segments than entire address space.
5. The segment table is of lesser size as compared to the page table in paging.

Disadvantages

1. It can have external fragmentation.


2. it is difficult to allocate contiguous memory to variable sized partition.
3. Costly memory management algorithms.

VIRTUAL MEMORY:

A computer can address more memory than the amount physically installed on the system.
This extra memory is actually called virtual memory and it is a section of a hard disk that's
set up to emulate the computer's RAM.
The main visible advantage of this scheme is that programs can be larger than physical
memory. Virtual memory serves two purposes. First, it allows us to extend the use of physical
memory by using disk. Second, it allows us to have memory protection, because each virtual
address is translated to a physical address.
Following are the situations, when entire program is not required to be loaded fully in main
memory.
 User written error handling routines are used only when an error occurred in the data
or computation.
 Certain options and features of a program may be used rarely.
 Many tables are assigned a fixed amount of address space even though only a small
amount of the table is actually used.
 The ability to execute a program that is only partially in memory would counter many
benefits.
 Less number of I/O would be needed to load or swap each user program into memory.
 A program would no longer be constrained by the amount of physical memory that is
available.
 Each user program could take less physical memory, more programs could be run the
same time, with a corresponding increase in CPU utilization and throughput.
Modern microprocessors intended for general-purpose use, a memory management unit, or
MMU, is built into the hardware. The MMU's job is to translate virtual addresses into
physical addresses. A basic example is given below −
Virtual memory is commonly implemented by demand paging. It can also be implemented in
a segmentation system. Demand segmentation can also be used to provide virtual memory.

Demand Paging
A demand paging system is quite similar to a paging system with swapping where processes
reside in secondary memory and pages are loaded only on demand, not in advance. When a
context switch occurs, the operating system does not copy any of the old program’s pages out
to the disk or any of the new program’s pages into the main memory Instead, it just begins
executing the new program after loading the first page and fetches that program’s pages as
they are referenced.
While executing a program, if the program references a page which is not available in the
main memory because it was swapped out a little ago, the processor treats this invalid
memory reference as a page fault and transfers control from the program to the operating
system to demand the page back into the memory.

Advantages

Following are the advantages of Demand Paging −

 Large virtual memory.


 More efficient use of memory.
 There is no limit on degree of multiprogramming.

Disadvantages

 Number of tables and the amount of processor overhead for handling page interrupts
are greater than in the case of the simple paged management techniques.
Page Replacement Algorithm

Page replacement is needed in the operating systems that use virtual memory using Demand
Paging. As we know that in Demand paging, only a set of pages of a process is loaded into
the memory. This is done so that we can have more processes in the memory at the same
time.

When a page that is residing in virtual memory is requested by a process for its execution, the
Operating System needs to decide which page will be replaced by this requested page. This
process is known as page replacement and is a vital component in virtual memory
management.

Reference String

The string of memory references is called reference string. Reference strings are generated
artificially or by tracing a given system and recording the address of each memory reference.
The latter choice produces a large number of data, where we note two things.
 For a given page size, we need to consider only the page number, not the entire
address.
 If we have a reference to a page p, then any immediately following references to
page p will never cause a page fault. Page p will be in memory after the first
reference; the immediately following references will not fault.
Page Fault:
A Page Fault occurs when a program running in CPU tries to access a page that is in the
address space of that program, but the requested page is currently not loaded into the main
physical memory, the RAM of the system.

Page Replacement Algorithms in OS

This algorithm helps to decide which pages must be swapped out from the main memory in
order to create a room for the incoming page. This Algorithm wants the lowest page-fault
rate.Various Page Replacement algorithms used in the Operating system are as follows;
1. FIFO Page Replacement Algorithm:

It is a very simple way of Page replacement and is referred to as First in First Out. This
algorithm mainly replaces the oldest page that has been present in the main memory for the
longest time.

 This algorithm is implemented by keeping the track of all the pages in the queue.

 As new pages are requested and are swapped in, they are added to the tail of a queue
and the page which is at the head becomes the victim.
 This is not an effective way of page replacement but it can be used for small systems.

Advantages

 This algorithm is simple and easy to use.


 FIFO does not cause more overhead.

Disadvantages

 This algorithm does not make the use of the frequency of last used time rather it just
replaces the Oldest Page.
 There is an increase in page faults as page frames increases.
 The performance of this algorithm is the worst.

2. LRU Page Replacement Algorithm in OS:

This algorithm stands for "Least recent used" and this algorithm helps the Operating system
to search those pages that are used over a short duration of time frame.

 The page that has not been used for the longest time in the main memory will be
selected for replacement.
 This algorithm is easy to implement.
 This algorithm makes use of the counter along with the even-page.

Advantages of LRU

 It is an efficient technique.
 With this algorithm, it becomes easy to identify the faulty pages that are not needed
for a long time.
 It helps in Full analysis.

Disadvantages of LRU

 It is expensive and has more complexity.

 There is a need for an additional data structure.

3. Optimal Page Replacement Algorithm


This algorithm mainly replaces the page that will not be used for the longest time in the
future. The practical implementation of this algorithm is not possible.

 Practical implementation is not possible because we cannot predict in advance those


pages that will not be used for the longest time in the future.
 This algorithm leads to less number of page faults and thus is the best-known
algorithm

Also, this algorithm can be used to measure the performance of other algorithms.

Advantages of OPR

 This algorithm is easy to use.


 This algorithm provides excellent efficiency and is less complex.
 For the best result, the implementation of data structures is very easy

Disadvantages of OPR

 In this algorithm future awareness of the program is needed.


 Practical Implementation is not possible because the operating system is unable to
track the future request

Page Fault in OS-


 A page fault occurs when a page referenced by the CPU is not found in the main memory.
 The required page has to be brought from the secondary memory into the main memory.
 A page has to be replaced if all the frames of main memory are already occupied.

Page Replacement-
 Page replacement is a process of swapping out an existing page from the frame of a main
memory and replacing it with the required page. All the frames of main memory are
already occupied.
 Thus, a page has to be replaced to create a room for the required page.
PRACTICE PROBLEMS BASED ON PAGE REPLACEMENT ALGORITHMS-

Problem-01:

A system uses 3 page frames for storing process pages in main memory. It uses the First in
First out (FIFO) page replacement policy. Assume that all the page frames are initially empty.
What is the total number of page faults that will occur while processing the page reference
string given below-
4 , 7, 6, 1, 7, 6, 1, 2, 7, 2
Also calculate the hit ratio and miss ratio.
Solution-

Total number of references = 10

From here,
Total number of page faults occurred = 6
Calculating Hit ratio-
Total number of page hits
= Total number of references – Total number of page misses or page faults
= 10 – 6
=4
Thus, Hit ratio
= Total number of page hits / Total number of references
= 4 / 10
= 0.4 or 40%
Calculating Miss ratio-
Total number of page misses or page faults = 6
Thus, Miss ratio
= Total number of page misses / Total number of references
= 6 / 10
= 0.6 or 60%
Alternatively,
Miss ratio
= 1 – Hit ratio
= 1 – 0.4
= 0.6 or 60%
Problem-02:
A system uses 3 page frames for storing process pages in main memory. It uses the Least
Recently Used (LRU) page replacement policy. Assume that all the page frames are initially
empty. What is the total number of page faults that will occur while processing the page
reference string given below-
4 , 7, 6, 1, 7, 6, 1, 2, 7, 2
Also calculate the hit ratio and miss ratio.

Solution-
Total number of references = 10

From here,
Total number of page faults occurred = 6
In the similar manner as above-
 Hit ratio = 0.4 or 40%
 Miss ratio = 0.6 or 60%

Problem-03:
A system uses 3 page frames for storing process pages in main memory. It uses the Optimal
page replacement policy. Assume that all the page frames are initially empty. What is the
total number of page faults that will occur while processing the page reference string given
below-
4 , 7, 6, 1, 7, 6, 1, 2, 7, 2
Also calculate the hit ratio and miss ratio.

Solution-
Total number of references = 10

From here,
Total number of page faults occurred = 5

In the similar manner as above-


 Hit ratio = 0.5 or 50%
 Miss ratio = 0.5 or 50%

Thrashing in Operating System


In case, if the page fault and swapping happens 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.
Figure: 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 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
belong 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:

Working-Set Model

This model is based on the assumption of the locality. It makes the use of the parameter ? in
order to define the working-set window. The main idea is to examine the most recent? page
reference. What locality is saying, the recently used page can be used again, and also the
pages that are nearby this page will also be used?

1. Working Set

The set of the pages in the most recent? page reference is known as the working set. If a page
is in active use, then it will be in the working set. In case if the page is no longer being used
then it will drop from the working set ? times after its last reference.

The working set mainly gives the approximation of the locality of the program.

The accuracy of the working set mainly depends on? what is chosen?

This working set model avoids thrashing while keeping the degree of multiprogramming as
high as possible.

2. Page Fault Frequency


Figure: Page fault frequency

The working-set model is successful and its knowledge can be useful in preparing but it is a
very clumpy approach in order to avoid thrashing. There is another technique that is used to
avoid thrashing and it is Page Fault Frequency(PFF) and it is a more direct approach.

The main problem is how to prevent thrashing. As thrashing has a high page fault rate and
also we want to control the page fault rate.

When the Page fault is too high, then we know that the process needs more frames.
Conversely, if the page fault-rate is too low then the process may have too many frames.

We can establish upper and lower bounds on the desired page faults. If the actual page-fault
rate exceeds the upper limit then we will allocate the process to another frame. And if the
page fault rate falls below the lower limit then we can remove the frame from the process.

Thus with this, we can directly measure and control the page fault rate in order to prevent
thrashing.

Allocation of frames in OS
The main memory of the system is divided into frames.
The OS has to allocate a sufficient number of frames for each process and to do so,
the OS uses various algorithms.
The five major ways to allocate frames are as follows:

1. Proportional frame allocation


The proportional frame allocation algorithm allocates frames based on the size that is
necessary for the execution and the number of total frames the memory has.
The only disadvantage of this algorithm is it does not allocate frames based on
priority. This situation is solved by Priority frame allocation.

2. Priority frame allocation


Priority frame allocation allocates frames based on the priority of the processes and
the number of frame allocations.
If a process is of high priority and needs more frames then the process will be
allocated that many frames. The allocation of lower priority processes occurs after it.

3. Global replacement allocation


When there is a page fault in the operating system, then the global replacement
allocation takes care of it.
The process with lower priority can give frames to the process with higher priority to
avoid page faults.

4. Local replacement allocation


In local replacement allocation, the frames of pages can be stored on the same page.
It doesn’t influence the behaviour of the process as it did in global replacement
allocation.

5. Equal frame allocation


In equal frame allocation, the processes are allocated equally among the processes in
the operating system.
The only disadvantage in equal frame allocation is that a process requires more frames
for allocation for execution and there are only a set number of frames.

What is Swapping in Operating Systems (OS)?

Let's suppose there are several processes like P1, P2, P3, and P4 that are ready to be executed
inside the ready queue, and processes P1 and P2 are very memory consuming so when the
processes start executing there may be a scenario where the memory will not be available for
the execution of the process P3 and P4 as there is a limited amount of memory available for
process execution.

Swapping in the operating system is a memory management scheme that temporarily swaps
out an idle or blocked process from the main memory to secondary memory which ensures
proper memory utilization and memory availability for those processes which are ready to be
executed.

When that memory-consuming process goes into a termination state means its execution is
over due to which the memory dedicated to their execution becomes free then the swapped-
out processes are brought back into the main memory and their execution starts.
The area of the secondary memory where swapped-out processes are stored is called swap
space. The swapping method forms a temporary queue of swapped processes in the
secondary memory.

In the case of high-priority processes, the process with low priority is swapped out of the
main memory and stored in swap space then the process with high priority is swapped into
the main memory to be executed first.

The main goals of an operating system include Maximum utilization of the CPU. This
means that there should be a process execution every time, the CPU should never stay idle
and there should not be any Process starvation or blocking.

Different process management and memory management schemes are designed to fulfill such
goals of an operating system.

Swapping in OS is done to get access to data present in secondary memory and transfer it to
the main memory so that it can be used by the application programs.

It can affect the performance of the system but it helps in running more than one process by
managing the memory. Therefore swapping in os is also known as the memory compaction
technique.

There are two important concepts in the process of swapping which are as follows:

1. Swap In
2. Swap Out

Refer to the 'Swap In and Swap out in OS' section for a detailed explanation.

Swap In and Swap Out in OS

Swap In:
The method of removing a process from secondary memory (Hard Drive) and restoring it to
the main memory (RAM ) for execution is known as the Swap In method.

Swap Out:

It is a method of bringing out a process from the main memory(RAM) and sending it to the
secondary memory(hard drive) so that the processes with higher priority or more memory
consumption will be executed is known as the Swap Out method.

Note:- Swap In and Swap Out method is done by Medium Term Scheduler(MTS).

Advantages of Swapping in OS

The advantages of the swapping method are listed as follows:

 Swapping in OS helps in achieving the goal of Maximum CPU Utilization.


 Swapping ensures proper memory availability for every process that needs to be
executed.
 Swapping helps in avoiding the problem of process starvation means a process should
not take much time for execution so that the next process should be executed.
 CPU can perform various tasks simultaneously with the help of swapping so that
processes do not have to wait much longer before execution.
 Swapping ensures proper RAM(main memory) utilization.
 Swapping creates a dedicated disk partition in the hard drive for swapped processes
which is called swap space.
 Swapping in OSis an economical process.
 Swapping method can be applied on priority-based process scheduling where a high
priority process is swapped in and a low priority process is swapped out which
improves the performance.

Disadvantages of Swapping in OS

There are some limited disadvantages of the swapping method which are listed as follows:

 If the system deals with power-cut during bulky swapping activity then the user
may lose all the information which is related to the program.
 If the swapping method uses an algorithm that is not up to the mark then the number
of page faults can be increased and therefore this decreases the complete performance.
 There may be inefficiency in a case when there is some common resource used by the
processes that are participating in the swapping process.
UNIT-6
FILE MANAGEMENT
6.1.File concept in OS
What is the file?
The file can be explained as the smallest unit of storage on a computer system. The
user can perform file operations like open, close, read, write, and modify.
File concept
The operating system can provide a logical view of the information stored in the disks,
this logical unit is known as a file. The information stored in files is not lost during
power failures.
A file helps to write data on the computer. It is a sequence of bits, bytes, or records,
the structure of which is defined by the owner and depends on the type of the file.
Different types of files are:

 Executable file
In an executable file, the binary code that is loaded in the memory for execution is
stored. It is stored in an exe type file.

 Source file
The source file has subroutines and functions that are compiled later.

 Object file
An object file is a sequence of bytes used by the linker.

 Text file
A text file is a sequence of characters.

 Image file
An image file is a sequence of visual information, for example, vector art.

File Attributes
Some of the common file attributes are:
1. Only the user can edit the name they have assigned to a file.
2. A unique number tag is given to every file. It cannot be read by the user and is used by the
file system to identify the file.
3. The time, date, and user identification are maintained to access the information about which
date the file was created, edited, or last accessed.
4. The type of the file is easily identified.
5. The size of the file in bits, bytes, or Kilobytes.
6. Access control can be defined by the user, as to who can access the files to read, write, edit or
delete the information stored in them.
File Operations in OS
The Operating system is responsible for performing the following file operations
using various system calls:
1. Read
2. Write
3. Create
4. Delete
5. Truncate files
6. Reposition

Read files: The OS needs a read pointer to read a file from a specific location in the
file.
To read files through command line, we use the type command. For huge files, we use
the more command to read files one page at a time.
Write files: The system call uses the same pointers to write a file, it helps to save
space and reduce complexity.

Create files: The user should have enough space to create a file. When a file is
created, a directory entry is made.
To create files through command line, the syntax is type nul > (filename).(filetype)

Delete files: The user can look up the file name and delete it. It will release the space
occupied by the file and remove the directory entries for the file.
The del command is used when we want to delete a file through command line.

Truncate files: The user can delete information from the file, instead of deleting it as
a whole. This changes the file length, though the other attributes remain the same.

Repositioning files: The current file-position pointer can be repositioned to a new


given value.

There are also other file operations like appending a file, creating a duplicate of the
file, and renaming a file.
Open-File Table
To avoid frequent searches in the directory the OS keeps an open file table. When a
file operation is requested, the system calls it via an index value.
If the file is not searched or accessed frequently the OS closes the file and removes its
entry from the open file table.
There can be several files open at the same time, therefore the system maintains two
file tables:
1. Per-process table
2. System-wide table.

6.2.File access methods in Operating System


Many files are stored in the memory of the computer system, when these files are required
by the application then the operating system has to read the computer memory and access the
required files.
There are several ways the operating system can access the information in the files. These
methods are also known as file access methods. The two major file access methods that
operating system support –
1. Direct Access
2. Sequential Access
3. Index Access
Each file access method has its advantages and disadvantages which you will find in this
article in greater detail.

1)Sequential access

This method is one of the simplest and easiest ways to access the information in the files. The
access of the information in the files occurs sequentially i.e. one record after the other. Due to
the simplicity of this file access method, it is used by the compilers and editors.

Sequential access file operation involves


Read next

Write next
Reset (or Rewind)

In this file access method, most of the operations are read and write operations –
The Read Operation – read next – reads the next portion of the file that is currently in
access also the read next advances the file pointer which is responsible for tracking the I/O
operations.
The Write Operation – write next – write operation will add a new node at the end of the
file and move the pointer to the new end of the file where the newly written information is
stored.
Reset (or rewind) – reset operation will bring the file read or write head at the beginning of
the file.
The sequential file access method depicts the example of how a tape drive worked, one
memory block at a time and then the next block followed.
Advantage – The sequential access method is an easy implementation method for the
software and hardware.
Disadvantage – The sequential access takes a lot of time for performing the read-write
operation.
This is due to the reason that it accesses the information in the file one record after another ,
this is dealt with in the direct access method.
The file allocation methods in operating system which is mechanism to store the files in the
memory uses both or either of direct access or sequential access method to access memory
after being allocated.

2)Direct Access (or Relative Access)

The direct access method represents the disk model of a file, as the disk allows random
access to any file block, and so does the direct access. The file is divided into fixed-length
blocks and the file is viewed as a numbered sequence of these blocks. Therefore the operating
system can perform a read-write operation on any random numbered block when provided.
For example, the operating system may read block 2, then block 7 and then write on block 13.
Also, the user always provides the relative block number to the operating system to access the
particular block, whereas the absolute block number where the block is stored is only known
to the operating system. For example, the first relative file block number is 0 and the next
block number is 1 but the absolute block number in the memory may be 21033 and 30122.
This also prevents the user from accessing the files that are not part of the required file.
Direct access file operation involves
Read n

Write n

Goto n

The ‘n’ represents the block number.


Advantages – the direct access method solves the problem of sequential access and helps to
access the information in the file immediately.
The best example of direct file access is the database system. When the database system
receives queries, it calculates which block has the desired information and then returns the
information to the user.
We can simulate the sequential access method with the direct access method but vice versa
can be inefficient and complex.

3)Index Access

The Index Access method is an improvised version of the direct access method. In this
method, an index is maintained which contains the address (or pointers) of the file blocks. So,
to access any particular record of the file the operating system will first search its address in
the index and the index will then point to the actual address of the particular block of the file
that has the desired information.
When the information is kept on adding to a particular file then the number of file blocks
increases. This growth in the file blocks also grows the index of that file. At one point in
time, the index of the file block may become too large to be kept in memory. The solution to
this problem is to create an index for the index file. The primary index file contains the
pointer (or address) to the secondary index file and the secondary index file contains the
actual address of the blocks of the file. This method can be repeated as the file size continues
to grow.
For example – To find the desired item, the operating system will perform a binary search on
the primary index. This will provide the operating system a block number for the secondary
index. The operating reaches the secondary index and again performs a binary search and the
block number is found that contains the desired result. The final block is then searched for the
result.
6.3.Directory Structure:
Several users create thousands and millions of files in a file system. To organize these files
properly file system uses directory structure. The directory structure has the entries of the
all the files related to that directory. We can consider that a directory is a file, that contains
information about the other files.
A File system contains thousands and millions of files, owned by several users. The directory
structure organizes these files by keeping entries of all the related files. The file entries have
information like file name, type, location, the mode in which the file can be accessed by other
users in the system.

The two important features that must be taken care while maintaining a directory are given
below.

1. A user must have freedom of giving the desired name to the file, without taking into
consideration that the same file names are used by other users on the system.

2. A user must be able to share the files he creates and he must also be able to access the
files, created by other users.

Directory structure provides both the above-discussed features. A directory always has
information about the group of related files. Whenever a user or a process request for a file,
the file system search for the file’s entry in the directory and when the match is found, it
obtains the file’s location from there.
Let us now study the directory structure with the help of the figure above. The field File
name, contains the name of the concerned file in the directory, Type field indicates the kind
or category of the file, Location Info field indicates the location where the file is stored.

Protection Info field contains the information whether the file can be accessed by the other
user in the system or not. Flag field contains the kind of directory entry like value D in Flag
field indicates that the file is a directory, value L indicates that the file is a link,
value M indicates that the file is a mounted file system.

The Misc info filed in the directory contains the miscellaneous information about the owner
of the file, the time of its creation, the time at which the file was modified last.

Types of Directory Structures

In this section, we will be discussing the most common types of directories, their benefits and
drawbacks.

1. Single-level directory structure

Single level directory structure has only one directory which is called the root directory.
The users are not allowed to create subdirectories under the root directory. All the files
created by the several users are present in the root directory only.

As you can see in the diagram below all the file F1, F2, F3, F4 created by the different users
are present at the root directory.

There is one drawback of Single-level directory structure, a user cannot use the same file
name used by another user in the system. Even if the file with the same name is created the
old file will get destroyed first and replaced by the new file having the same name.
2. Two-level directory structure

In Two-level directory structure, the users create directory directly inside the root directory.
But once a user creates such directory, further he cannot create any subdirectory inside that
directory. Observe the figure below, 4 users have created their separate directory inside the
root directory. But further, no subdirectory is created by the users.

This two-level structure allows each user to keep their files separately inside their own
directory. This structure allows to use the same name for the files but under different user
directories.
3. Hierarchical Directory Structure

In Hierarchical directory structure, the users can create directories under the root directory
and can also create sub-directories under this structure. As the user is free to create many sub-
directories, it can create different sub-directories for different file types.

Here, the files are accessed by their location using the path. There are two types of paths to
locate the file in this directory structure
 Absolute Path
Here, the path for the desired file is described by considering the root directory as the base
directory.

 Relative Path
Here, either the user’s directory is considered as the base directory or the desired file
directory is considered as the base directory.

4. Tree Directory Structure

In a tree directory structure, except root directory, every directory or file has only one parent
directory. So, there is a total separation between the users which provide complete naming
freedom. Here, if a user wishes to access another users file, it has to go through two or more
directories.

The tree directory structure provides an asymmetric way for the user to access the shared files
of a different user. For example, a user can access a file of its own user directory with a
shorter path than the other user.

5. Acyclic-Graph Directory Structure

This problem can be solved by the acyclic-graph directory structure. As this directory
structure allows a directory or a file to have many parent directories. So, a shared file in a
directory can be pointed by the other user directories who have access to that shared file
using the links.

In the diagram below you can see that the directory having file F7 and F8 have two parent
directories.
Operations on Directory

As discussed above, a directory contains the entries of all the related files. For organizing the
directory in the better way the user must be able to insert, delete, search, list the entries in the
directory. Below we will be discussing the operation that can be performed on the directory.

1. Searching

A directory can be searched for a particular file or for another directory. It can also be
searched to list all the files with the same name.

2. Creating

A new file can be created and inserted to the directory or new directory can be created
keeping in mind that its name must be unique under that particular directory.

3. Deleting

If a file is no longer needed by the user, it can be deleted from the directory. The entire
directory can also be deleted if it is not needed. An empty directory can also be deleted.
When a directory is empty it is resembled by dot and dotdot.

4. List a directory

List of all the files in the directory can be retrieved and also the contents of the directory
entry, for each file in a list. To read the list of all the files in the directory, it must be opened
and after reading the directory must be closed to free up the internal tablespace.

5. Renaming

The name of the file or a directory represents the content it holds and its use. The file or
directory can be renamed in case, the content inside or the use of file get changed. Renaming
the file or directory also changes its position inside the directory.

6. Link
The file can be allowed to appear in more than one directory. Here, the system call creates a
link between the file and the name specified by the path where the file is to appear.

7. Unlink

If the file is unlinked and is only present in one directory its directory entry is removed. If the
file appears in multiple directories, only the link is removed.

6.4.File System Structure

File System provide efficient access to the disk by allowing data to be stored, located and
retrieved in a convenient way. A file System must be able to store the file, locate the file and
retrieve the file.

Most of the Operating Systems use layering approach for every task including file systems.
Every layer of the file system is responsible for some activities.

The image shown below, elaborates how the file system is divided in different layers, and
also the functionality of each layer.
o When an application program asks for a file, the first request is directed to the logical
file system. The logical file system contains the Meta data of the file and directory
structure. If the application program doesn't have the required permissions of the file
then this layer will throw an error. Logical file systems also verify the path to the file.
o Generally, files are divided into various logical blocks. Files are to be stored in the
hard disk and to be retrieved from the hard disk. Hard disk is divided into various
tracks and sectors. Therefore, in order to store and retrieve the files, the logical blocks
need to be mapped to physical blocks. This mapping is done by File organization
module. It is also responsible for free space management.
o Once File organization module decided which physical block the application program
needs, it passes this information to basic file system. The basic file system is
responsible for issuing the commands to I/O control in order to fetch those blocks.
o I/O controls contain the codes by using which it can access hard disk. These codes are
known as device drivers. I/O controls are also responsible for handling interrupts.

6.5.File System Implementation

We can use the following data structures to implement file systems:


1. On-disk structures
2. In-memory structures
On-disk structures
They store information about the total number of disk blocks, their location, free disk
blocks, etc. Different on-disk structures are as follows:
Directory structure
Directory structure stores the file names and associated inode numbers.
Volume Control Block
Volume Control Block stores information about a particular partition. Examples:
block pointers, free block count, etc.
Boost Control Block
Boost Control Block is generally the first block of volume and it stores the
information needed to boot an operating system. It is also known as partition boot
sector in NTFS and boot block in UNIX.
Per-File FCB
Per-File FCB stores details about files and has a unique identifier number to associate
with the directory entry.
In-memory structures
The in-memory structure is maintained in the main memory and is helpful for file
management for caching. Different in-memory structures are:
Mount Table
Mount Table stores information about the mounted volume.
Per-process open-file table
Per-process open-file table stores information opened by the process and it maps with
the system open-file.
Directory-structure cache
Directory-structure cache stores information about the recently accessed directories.
System-wide open-file table
The system-wide open-file table stores the copy of the FCB of each open file.
Directory Implementation

 Linear List
Linear List stores a linear list of filenames with pointers to the data blocks.
Hash Table
Hash Table stores the value computed from the file name and returns a pointer to the
file. The only disadvantage of the hash table is that it is generally fixed in size.

6.6.Directory Implementation

There is the number of algorithms by using which, the directories can be implemented.
However, the selection of an appropriate directory implementation algorithm may
significantly affect the performance of the system.

The directory implementation algorithms are classified according to the data structure they
are using. There are mainly two algorithms which are used in these days.

Characterstics:

1. Linear List

In this algorithm, all the files in a directory are maintained as singly lined list. Each file
contains the pointers to the data blocks which are assigned to it and the next file in the
directory.

1. When a new file is created, then the entire list is checked whether the new file name is
matching to a existing file name or not. In case, it doesn't exist, the file can be created
at the beginning or at the end. Therefore, searching for a unique name is a big concern
because traversing the whole list takes time.
2. The list needs to be traversed in case of every operation (creation, deletion, updating,
etc) on the files therefore the systems become inefficient.

2. Hash Table

To overcome the drawbacks of singly linked list implementation of directories, there is an


alternative approach that is hash table. This approach suggests to use hash table along with
the linked lists.

A key-value pair for each file in the directory gets generated and stored in the hash table. The
key can be determined by applying the hash function on the file name while the key points to
the corresponding file stored in the directory.

Now, searching becomes efficient due to the fact that now, entire list will not be searched on
every operating. Only hash table entries are checked using the key and if an entry found then
the corresponding file will be fetched using the value.
6.7.ALLOCATION METHODS:

The File allocation methods in OS are different ways that are used for storing the file on the
hard disk. There are 5 different ways in which we can store the files on the hard disk in such
a manner that there is efficient utilization of disk space and the file can be accessed faster by
the Operating System.

What is File Allocation in OS?

Whenever a hard disk is formatted, a system has many small areas called blocks or sectors
that are used to store any kind of file. File allocation methods are different ways by which the
operating system stores information in memory blocks, thus allowing the hard drive to be
utilized effectively and the file to be accessed. Below are the types of file allocation methods
in the Operating System.

Types of File Allocation Methods in Operating System.

 Contiguous File allocation


 Linked File Allocation
 Indexed File Allocation
 File Allocation Table (FAT)
 Inode

Let's have an in-detail explanation about each of them,

Contiguous File Allocation.

First, let's understand the meaning of contiguous, here contiguous means adjacent or
touching. Now let's understand what contiguous file allocation is.

What is Contiguous File allocation?

In contiguous file allocation, the block is allocated in such a manner that all the allocated
blocks in the hard disk are adjacent.

Assuming a file needs 'n' number of blocks in the disk and the file begins with a block at
position'x', the next blocks to be assigned to it will be x+1,x+2,x+3,...,x+n-1 so that they are
in a contiguous manner.

Let's understand this diagrammatically.

Example

We have three different types of files that are stored in a contiguous manner on the hard disk.
In the above image on the left side, we have a memory diagram where we can see the blocks
of memory. At first, we have a text file named file1.txt which is allocated using contiguous
memory allocation , it starts with the memory block 0 and has a length of 4 so it takes the 4
contiguous blocks 0,1,2,3. Similarly, we have an image file and video file
named sun.jpg and mov.mp4 respectively, which you can see in the directory that they are
stored in the contiguous blocks. 5,6,7 and 9,10,11 respectively.

Here the directory has the entry of each file where it stores the address of the starting block
and the required space in terms of the block of memory.

Advantages and Disadvantages

Advantages

 It is very easy to implement.


 There is a minimum amount of seek time.
 The disk head movement is minimum.
 Memory access is faster.
 It supports sequential as well as direct access.

Disadvantages

 At the time of creation, the file size must be initialized.


 As it is pre-initialized, the size cannot increase.
 Due to its constrained allocation, it is possible that the disk would fragment internally
or externally.

Linked File Allocation.

What is Linked File Allocation?

The Linked file allocation overcomes the drawback of contiguous file allocation. Here the file
which we store on the hard disk is stored in a scattered manner according to the space
available on the hard disk. Now, you must be thinking about how the OS remembers that all
the scattered blocks belong to the same file. So as the name linked File Allocation suggests,
the pointers are used to point to the next block of the same file, therefore along with the entry
of each file each block also stores the pointer to the next block.

Let's understand this better diagrammatically by taking an example.

Example

Here we have one file which is stored using Linked File Allocation.

In the above image on the right, we have a memory diagram where we can see memory
blocks. On the left side, we have a directory where we have the information like the address
of the first memory block and the last memory block.

In this allocation, the starting block given is 0 and the ending block is 15, therefore the OS
searches the empty blocks between 0 and 15 and stores the files in available blocks, but along
with that it also stores the pointer to the next block in the present block. Hence it requires
some extra space to store that link.

Advantages and Disadvantages

Advantages
 There is no external fragmentation.
 The directory entry just needs the address of starting block.
 The memory is not needed in contiguous form, it is more flexible than contiguous file
allocation.

Disadvantages

 It does not support random access or direct access.


 If pointers are affected so the disk blocks are also affected.
 Extra space is required for pointers in the block.

Indexed File Allocation.

What is Indexed File Allocation?

The indexed file allocation is somewhat similar to linked file allocation as indexed file
allocation also uses pointers but the difference is here all the pointers are put together into
one location which is called index block. That means we will get all the locations of blocks
in one index file. The blocks and pointers were spread over the memory in the Linked
Allocation method, where retrieval was accomplished by visiting each block sequentially.
But here in indexed allocation, it becomes easier with the index block to retrieve.

Let's take an example to explain this better.

Example

As shown in the diagram below block 19 is the index block which contains all the addresses
of the file named text1. In order, the first storage block is 9, followed by 16, 1, then 10, and
25. The negative number -1 here denotes the empty index block list as the file text1 is still too
small to fill more blocks.
Advantages and Disadvantages

Advantages

 It reduces the possibilities of external fragmentation.


 Rather than accessing sequentially it has direct access to the block.

Disadvantages

 Here more pointer overhead is there.


 If we lose the index block we cannot access the complete file.
 It becomes heavy for the small files.
 It is possible that a single index block cannot keep all the pointers for some large files.

To resolve this issue, we can use the following approaches:

1. Linked scheme
2. Multilevel Index
3. Combined Scheme

1. Linked Scheme

If the file is big then more blocks are required so one index block is insufficient to store all
the pointers, therefore to store the pointers two or more index blocks are used where these
index boxes are connected using linked file allocation that is each index block stores the
pointer to the next index block.

2. Multilevel Index

In this method, the multiple indexes blocks along with the levels of these blocks. Here, the
level 1 block is used for pointing to the level 2 block which points to the blocks occupied by
the file. These index blocks can be extended to three or more levels according to the size of
the file.

3. Combined Scheme

In Combined Scheme, a special block is used to store all the information related to the file
like name, authority, size, etc. The special block is called inode(information-node). Some
space of this special block is used to store the information related to the field as mentioned
above and the remaining space is used to store the addresses of blocks that contain the actual
file. The inode is explained further in detail.

File Allocation Table (FAT).

The File Allocation Table (FAT) overcomes the drawback of Linked File allocation. The
random access of a particular block is not possible in the linked file allocation. To access a
particular block it is necessary to access all its previous blocks. Let's see how File Allocation
Table works.

Explanation
In the file allocation table, all disk block links are collected and maintained. Here the number
of head seeks is reduced by caching the file allocation table so that the head does not need to
go through all the disk blocks to access one particular block.

The whole process of randomly accessing any block using FAT is completed by reading the
desired entry of a block from the file allocation table and accessing that particular block.

The diagrammatic representation of FAT is given below -

Advantages and Disadvantages

Advantages

 Random Access to the block is possible in FAT.


 One bad/corrupted disk block cannot corrupt all the other blocks.
 It uses all the disk blocks for data as in linked file allocation it needs extra space for
pointers.

Disadvantages

 If entries increase so the FAT size also increases.


 Each entry requires the FAT entry.
 If Entries increase the FAT size increases which increases the size of a block so there
are chances of internal fragmentation.

Inode.

In Operating systems based on UNIX, every file is indexed using Inode(information-node).


The inode is the special disk block that is created with the creation of the file system. This
special block is used to store all the information related to the file like name, authority, size,
etc along with the pointers to the other blocks where the file is stored.
Explanation

In this special block, some of its space is used to store the information related to the field as
mentioned above and the remaining space is used to store the addresses of blocks that contain
the actual file.

The first few pointers in Inode point to direct blocks, i.e they contain the addresses of the
disk blocks containing the file data. A few pointers in inode point to the indirect blocks.
There are three types of indirect blocks: single indirect, double indirect, and triple indirect.

A single indirect block contains nothing but the address of the block containing the file data,
not the file itself as shown in the figure below. Furthermore, the double indirect block points
to the pointers which again point to the pointers which point to the data blocks. Further, it
goes in a similar way for triple indirect block.

The diagrammatic representation of Inode is given below -

Advantages and Disadvantages

Advantages

 Accessibility of file becomes easy as all the information like metadata and block
address is stored inside inode.
 Read-write and creation timestamps are stored inside the inode.
 Filenames do not affect inodes. In other words, a single file can be copied and
renamed without losing its address.

Disadvantages

 All new files and folders will be rejected as soon as a file system runs out of inodes.
 Upon 100% utilization of inodes system will start to notice OS restarting, data loss,
applications crashing, and more OS-related issues.
Conclusion.

 File allocation methods are different ways by which the operating system stores
information in memory blocks.
 There are 5 types of file allocation methods in OS. Contiguous File allocation, Linked
File Allocation, Indexed File Allocation, File Allocation Table (FAT), and Inode.
 In Contiguous file allocation, the block is allocated in such a manner that all the
allocated blocks in the hard disk are contiguous(adjacent).
 In Linked file allocation the pointers are used to point to the next block of the same
file.
 The Index file allocation is similar to Linked file allocation but here all the pointers
are put together into one location which is called an index block.
 Using File allocation table (FAT) we can randomly access the disk block as it
maintains the FAT for each file.
 Inode(information-node) contains some metadata about the file and stores all the
pointers to the files where it can directly or indirectly access the file.

6.8.Free Space Management in OS

What is Free Space Management in OS?

There is system software in an operating system that manipulates and keeps track of free
spaces to allocate and de-allocate memory blocks to files, this system is called a "file
management system in an operating system". There is a "free space list" in an operating
system that maintains the record of free blocks.

When a file is created, the operating system searches the free space list for the required space
allocated to save a file. While deletion a file, the file system frees the given space and adds
this to the "free space list".

Methods of Free Space Management in OS

It is not easy work for an operating system to allocate and de-allocate memory blocks
(managing free space) simultaneously. The operating system uses various methods for adding
free space and freeing up space after deleting a file. There are various methods using which a
free space list can be implemented. We are going to explain them below-
Bitmap or Bit Vector:

A bit vector is the most frequently used method to implement the free space list. A bit vector
is also known as a "Bit map". It is a series or collection of bits in which each bit represents a
disk block. The values taken by the bits are either 1 or 0. If the block bit is 1, it means the
block is empty and if the block bit is 0, it means the block is not free. It is allocated to some
files. Since all the blocks are empty initially so, each bit in the bit vector represents 0.

Let us take an example:

Given below is a diagrammatic representation of a disk in which there are 16 blocks. There
are some free and some occupied blocks present. The upper part is showing block number.
Free blocks are represented by '1' and occupied blocks are represented by '0'.

"Free block number" can be defined as that block which does not contain any value, i.e.,
they are free blocks. The formula to find a free block number is:

Advantages of Bit vector method:

1. Simple and easy to understand.


2. Consumes less memory.
3. It is efficient to find free space.

Disadvantages of Bit vector method:

1. The operating system goes through all the blocks until it finds a free block. (block
whose bit is 0).
2. It is not efficient when the disk size is large.

Linked List:

A linked list is another approach for free space management in an operating system. In it, all
the free blocks inside a disk are linked together in a "linked list". These free blocks on the
disk are linked together by a pointer. These pointers of the free block contain the address of
the next free block and the last pointer of the list points to null which indicates the end of the
linked list. This technique is not enough to traverse the list because we have to read each disk
block one by one which requires I/O time.

In the above example, block 2 is the first free block and after that block 3 is the next free
block, and then block 4 is free. Block 2 contains a pointer that indicates block 3 and
blocks 3 contains a pointer that indicates the next free block 4. This continues until the
pointer reached the last free block.

Advantage of the Linked list:

1. In this method, available space is used efficiently.


2. As there is no size limit on a linked list, a new free space can be added easily.

Disadvantages:

1. In this method, the overhead of maintaining the pointer appears.


2. The Linked list is not efficient when we need to reach every block of memory.

Grouping:

The grouping technique is also called the "modification of a linked list technique". In this
method, first, the free block of memory contains the addresses of the n-free blocks. And the
last free block of these n free blocks contains the addresses of the next n free block of
memory and this keeps going on. This technique separates the empty and occupied blocks of
space of memory.
Example:

Suppose we have a disk with some free blocks and some occupied blocks. The free block
numbers are 3, 4, 5, 6, 9, 10, 11, 12, 13, 14. And occupied block numbers are 1, 2, 7, 8,
15,1,2,7,8,15, and 16 i.e., they are allocated to some files.

When the "grouping technique" is applied, block 3 will store the addresses of blocks 4, 5,
and 6 because 'block 3' is the first free block. In the same way, block 6 will store the
addresses of blocks 9, 10, and 11 because block 6 is the first occupied block.

Advantage of the Grouping method:

1. By using this method, we can easily find addresses of a large number of free blocks
easily and quickly.

Disadvantage:

1. We need to change the entire list if one block gets occupied.


Counting:

In memory space, several files are created and deleted at the same time. For which memory
blocks are allocated and de-allocated for the files. Creation of files occupy free blocks and
deletion of file frees blocks. When there is an entry in the free space, it consists of two
parameters- "address of first free disk block (a pointer)" and " a number 'n' ".

Example:

Let us take an example where a disk has 16 blocks in which some blocks are empty and some
blocks are occupied as given below:

When the "counting technique" is applied, the block number 3 will represent block
number 4 because block 3 is the first free block. Then, the block stores the number of free
blocks i.e. - there are 4 free blocks together. In the same way, the first occupied block
number 9 will represent block number 10 and keeps the number of rest occupied blocks i.e.-
there are 6 occupied blocks as shown in the above figure.

Advantages:

1. In this method, a bunch of free blocks take place fastly.


2. The list is smaller in size.

Disadvantage:

1. In the counting method, the first free block stores the rest free blocks, so it requires
more space.

6.9.Efficiency and Performance

Efficiency depends on:

1. Disk allocation and directory algorithms

2. Type of data kept in file’s directory entry

Performance improvement techniques:


1. Disk cache

Separate section of main memory (in kernel space) for frequently used disk blocks

2. Virtual disk (RAM disk)

Dedicate a section of main memory as virtual file-system

3. Free-behind and read-ahead techniques

Optimization for sequential access

7.1.Disk Management

 Disk Management is an important functionality provided by the Operating System


which can be used to create, delete, format disk partitions, and much more.
 Disk Management enables users to view, create, delete and shrink the partitions
associated with the disk drives.
 The file system is considered a central component because of everything in UNIX
operating system.
 The file system in the UNIX operating system is a logical method of storing and
managing huge amounts of information.
 The UNIX operating system organizes its files and directories in a multi-level
hierarchal structure known as a directory tree.
 To manage the Input/Output requests on a system, the operating system uses
different Disk Scheduling Algorithms.
 Spooling is a buffer that is used to hold the tasks for a system until the system is ready
to accept another task.
 Buffering is the storing of data temporarily in the buffer so that the data transfer rate
between the sender and the receiver is matched.
 What Is Disk Management in OS?
 As we know, an operating system provides four major managements, namely -
process management, file management, and disk management, device management,
memory management.

Methods to Access Disk Management in OS

Let's learn about steps to access disk management in different operating systems.
Note: > resembles next step.

1. In Windows Operating System:


o Using Run Box: Click on Start Button > Click on
Run > Type diskmgmt.msc > Click OK. The Disk Management will open.
2. In Linux Operating System: There are several commands used to check Disk
Partitions and Disk Space on the Linux operating system.
o Some of them are mentioned below: a. fdisk b. sfdisk c. cfdisk d. parted e. df
3. In Mac Operating System:
o Using Launchpad: Click on Launchpad Icon > Type Disk Utility "> "Click on
Disk Utility Icon. The Disk Utility will open.

7.2.Disk Scheduling Algorithms

Disk Scheduling or I/O Scheduling is the process of managing the I/O requests. Disk
Scheduling Algorithms are different techniques used to manage these I/O requests. There are
mainly 6 types of disk scheduling algorithms. Let's learn about them.

FCFS Algorithm:

FCFS is one of the simplest algorithms, which stands for First Come First Serve. As the name
suggests, the I/O request that has come first will be served first. So, it serves the I/O requests
in the order of their arrival.

Advantages and Disadvantages of FCFS:

 Every I/O request gets served; hence, FCFS is a fair algorithm.


 FCFS is not an optimized algorithm as it does not consider serving the Time and
priority of the requests. Hence, it may not provide the best possible service.

Note: Seek Time is the Time taken by the hard disk controller to locate a specific piece of the
stored data.

SSTF Algorithm:

SSTF is another simple algorithm that stands for Shortest Seek Time First. As the name
suggests, the I/O requests having least seek Time are served first.

Advantages and Disadvantages of SSTF:

 Seek Time of every request is calculated in advance, and a queue is used to maintain
them as per their seek Time. Hence, SSTF has a better response time than FCFS.
 Since SSTF has a better response time, it increases the throughput (amount of work
completed in a unit of Time) of the system.
 SSTF is not the most optimized algorithm as it suffers from the overhead of
calculating the seek Time in advance.

Note: Disk arm points to a particular location in the storage.


SCAN and C-SCAN Algorithm

SCAN algorithm moves the disk arm in a particular direction and serves the I/O requests
coming in its path. The Disk then reverses its direction and serves the I/O requests present in
the path. Since the movement of the Disk is like an elevator, it is also known as
the Elevator Algorithm.

In C-SCAN or Circular-SCAN algorithm, the disk arm does not reverse its direction. It
simply goes to the other end of the Disk and starts serving the requests from there.

Advantages and Disadvantages of SCAN and C-SCAN:

 SCAN and C-SCAN provides average response time and high throughput.
 One of the major disadvantages of these algorithms is the long waiting time for the
requests for the locations that are just visited by the disk arm.

LOOK and C-LOOK Algorithm:

The LOOK scheduling algorithm works somewhat similarly to the SCAN algorithm.
In LOOK Algorithm, the disk arm reverses its direction from the last served request. Hence,
the LOOK algorithm prevents useless delay in the movement of the Disk to the last.

In C-LOOK or Circular-LOOK algorithm, the disk arm does not reverse its direction
from the last request. It simply goes to the other end's last request and starts serving the
requests from there.

Advantages and Disadvantages of LOOK and C-LOOK:

 LOOK algorithm does not cause the head to move till the end, hence saving time.
 LOOK algorithm has a better response time than the SCAN algorithm.
 One of the disadvantages of these algorithms is the overhead of finding the end
request.

Other lesser-used Disk Scheduling Algorithms are:

1. RSS: RSS stands for Random Scheduling, and as the name suggests, RSS selects a
random I/O request and serves it.
2. LIFO: LIFO stands for Last In First Out. So, the newest request is serviced before
any other request.

Spooling and Buffering

Operating System improves the performance and efficiency of the computer by using the
temporary memory space or buffer inside the main memory. We have two types of temporary
memory space, namely:

 Spooling
 Buffering
Spooling

SPOOL or Simultaneous Peripheral Operation On-line is an acronym for Spooling. Spooling


is a temporary memory space used to store the tasks for a system. The tasks are stored until
the system is ready to accept or execute new tasks. Spooling considers the Disk as a large
buffer that can store many jobs. The basic spooling can be seen in the image below:

Buffering

Buffering is the storing of data temporarily in the buffer so that the data transfer rate between
the sender and the receiver is matched. If the sender's transmission speed is slower than the
receiver's, then the buffer is created in the main memory of the receiver. On the other hand, if
the receiver's transmission speed is slower than the transmitter, then the buffer is created in
the main memory of the transmitter. The basic buffering can be seen in the image below:

7.3.What is Hard Disk ?


Hard Disk is a secondary storage device. It is a type of electro mechanical device. A hard
disk stores and retrieves digital data using magnetic storage. Disk is rigid rapidly rotating
platters coated with magnetic material.
Hard Disk Pack consist of more than one disk.

How Data is Stored in a Hard Disk ?


 Data is stored in Disk in form of tracks and sectors.
 Disk surface is divided in to tracks.
 Track is further dived in to sectors.
 Sector is the addressable unit in disk.
Basic picture for disk storage concept is given below

Disk Structure in OS
Disk structure is as shown in following figure

 Disk surfacе dividеd into tracks


 A rеad/writе hеad positionеd just abovе thе disk surfacе
 Information storеd by magnеtic rеcording on thе track undеr rеad/writе hеad
 Fixеd hеad disk
 Moving hеad disk
 Dеsignеd for largе amount of storagе
 Primary dеsign considеration cost, sizе, and spееd
Hardwarе for disk systеm
 Disk drivе, Dеvicе motor, Rеad/writе hеad, Associatеd logic
Disk controllеr
 Dеtеrminеs thе logical intеraction with thе computеr
 Can sеrvicе morе than onе drivе (ovеrlappеd sееks)
Cylindеr
 Thе samе numbеrеd tracks on all thе disk surfacеs
 Еach track contains bеtwееn 8 to 32 sеctors
Sеctor
 Smallеst unit of information that can bе rеad from/writtеn into disk
 Rangе from 32 bytеs to 4096 bytеs
Disk Performance Parameters
Some important parameters used to measure the performance of hard disk are as follow

Sееk timе
 Seek Timе is time rеquirеd by rеad/writе hеad to movе to rеquеstеd track
 Includеs thе initial startup timе and thе timе rеquirеd to travеrsе thе tracks to bе crossеd
oncе thе accеss arm is up to spееd.
Latеncy or rotational dеlay
 Timе rеquirеd for thе rеquеstеd sеctor to comе undеr thе rеad/writе hеad.
 Rotational delay is generally the half of the time taken in one rotation.
Data Transfer Rate
Data transfer rate is define as the amount of data transfer in per unit time for example 30
MB/Sec.

Data Transfer Time


Data Transfer time is the total time taken to transfer a specific amount of data from the disk.
Data Transfer time depends on the data transfer rate of the disk.

Average Access Time


Average access time is calculated as

Average Access Time = Seek Time + Rotational Latecny + Data Transfer Time

7.4.RAID STRUCTURE:

What is RAID?

Redundant Array of Independent Disks (RAID) is a storage technology that combines several
physical hard disks to create a logical drive with better performance and reliability than
individual units. It increases the speed of storing and accessing data while preventing loss of
data and downtimes.
What are RAID Levels?

A RAID level refers to the technique of distributing, organizing and managing data across
multiple disks in an array. Each level has a different fault tolerance, data redundancy, and
performance properties, and the choice depends on requirements or goals as well as cost.
Some levels provide more data protection while others offer better performance improvement
than other methods.

Generally, all RAID arrays are classified as standard, non-standard or nested levels
depending on configuration and type and level of improvements it offers.

Standard RAID Levels

Standard RAID levels are based on simple and basic hardware configurations, and are ideal
for a wide range of businesses and individuals. Typical standard level is RAID 0, 1, 2,3,4,5,
and 6. Each of these provides a unique combination of redundancy and performance.

RAID 0

A RAID 0 level uses block-striping to spread data across multiple physical disks. This has the
fastest I/O performance since it writes or copies small different parts of a file to -, or from -,
multiple disks simultaneously.

It requires a minimum of two physical drives and provides the maximum disk space, which is
the total of the individual device capacities. However, it does not offer any data redundancy
or fault tolerance, and is best for organizations looking for performance. A failure in any of
the disks in a RAID 0 array results in complete loss of data, including data saved in the good
drives.

RAID 0 level is best for applications processing non-critical data but requires high
performance.
RAID 1

RAID 1 mirrors data on two or more disks without parity. The level requires at least two
drives and total usable space equals the size of a single disk.

All the disks have identical copies of data. In case of a disk failure, the system continues to
use the existing disk or disks in good working condition.

RAID 1 level provides better data redundancy and is ideal for applications where data
availability is critical. This is a simple technology with basic fault tolerance but no
performance improvements since it must write the data twice.

This is ideal for applications where data availability and redundancy are important.
RAID 2

RAID 2 uses bit-level striping with parity compared to block striping in RAID 0.
Additionally, it uses Hamming code for error detection and therefore requires disks without
self-disk error checking option. Since most of the modern disks have this feature, the level is
rarely used. In addition, it requires an extra disk to store parity information for error detection
purposes. Effective disk capacity is n-1 where n is the number of disks.

RAID 2 works like RAID 0 but uses bit-level striping along with an error protection
mechanism to protect data loss due to corruption. This is resource extensive and not widely
used.

RAID 3

RAID 3 uses byte-level striping with parity for rebuilding data. It requires a minimum of
three drives, of which one stores the parity information. The level has high-level data transfer
rates for large files since data is accessed in parallel but slower on small files.

This level performs better for long sequential data transfers such as video but not in
applications where there are many requests such as a database. In case the disk with parity
crashes, there is no way of rebuilding data. The level is not used much and just like RAID 2,
its usable capacity is n-1.
RAID 4

RAID 4 is almost similar to RAID 3 but uses block-level striping. It combines block-level
striping across multiple disks with a dedicated parity disk. The level requires a minimum of
three disks where one is reserved for parity information. Data from each drive is accessed
independently at only one block at a time hence slow operations. In addition, writing
operations are slower since the system must write the parity information.

This is ideal for sequential data access. However, the parity disk may slow the write
applications. The level is rarely used.
RAID 5

RAID 5 has block level striping along with distributed parity. This is a cost-effective, all-
round configuration that balances between redundancy, performance, and storage capacity.

Striping improves the read I/O performance while parity is important for reconstructing data
in case of disk failure. However, it cannot survive multiple disk failures and takes longer to
rebuild data since the process involves calculating parity from each of the available drives. It
requires a minimum of three disks but has a usable space of n-1 disk.

RAID 5 level is suitable for applications and file servers with limited storage devices.

RAID 6

RAID 6 uses block striping like RAID 5 but with a dual distributed parity. The two blocks of
parity information provide additional redundancy and fault tolerance. This level can survive
two concurrent disk failures. However, it is expensive; requiring at least four drives while
giving a usable space is n-2 disks.

It is more reliable and common in SATA environments and applications such as disk-based
backups and data archives where there is a need for long data retention. It is also suitable for
environments where data availability is more important than performance.

Drawbacks of the level 6 include the additional disk for the double parity information as well
as being complex to implement compared to level 5. Due to the dual parity, the write and
restore speeds are slower.
Nested (Hybrid) RAID Levels

A nested RAID is a combination of a level that provides redundancy and a RAID 0 that
increases performance. This may use RAID arrays or individual disks. Usually, the best
combination is having RAID 0 on top of a redundant array since fewer disks will need
regenerating in case of a disk failure.

The nested levels provide better performance and higher tolerance. However, they require
complex configurations and more drives, while the effective capacity is halved the installed
disk space. They are also expensive and have limited scalability.

The common levels includes 0+1, 1+0 (10), 0+3, 3+0 (30), 0+5, 5+0 (50), and 6+0 (60)

RAID 0+1

RAID 0+1 combines RAID 0 and 1 to provide redundancy and improve performance. The
process starts by striping the data across multiple disks, which increases performance,
followed by mirroring for data redundancy.

RAID 0+1 requires a minimum of four physical hard drives and is a complex configuration
that provides high performance and fault tolerance. It can survive more than one disk failure
in the same mirrored set provided there is no concurrent failure of two mirrored disks.

This level requires disks in multiples of two but the total usable capacity is usually half the
total disk space. In addition, it is more costly and not easily scalable.
Nested RAID 01 configuration

Hybrid RAID 01 configuration

RAID 1+0

RAID 1+0 or RAID 10 starts with mirroring data before stripping it across the mirrored
arrays. The approach makes it more redundant, reliable, and efficient than RAID 0+1, and
can survive multiple drive failures. It requires a minimum of four drives and can survive
multiple concurrent disk failures as long as none of the mirrors loses all the disks.
RAID 1+0 has better fault tolerance, data redundancy and rebuild compared to RAID 0+1.
However, it is very expensive and just like the 0+1 has limited scalability. The level is ideal
for organizations looking for high performance and data security. The usable capacity is half
the total installed disk space.

You might also like