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

UNIT 1: Introduction to Operating System

Operating System Definition

An operating system, or OS, is a collection of software that manages a computer's hardware and software
resources. It acts as a bridge between the computer's hardware and the applications that run on it. The
introduction of operating systems has played a vital role in the evolution of computers, making them more
user-friendly and efficient.

The first operating system was developed in the early 1950s by a team at the Massachusetts Institute of
Technology (MIT) led by John McCarthy. The Dartmouth Time-Sharing System (DTSS) OS allowed multiple
users to access the same computer simultaneously through remote terminals. It was a significant
advancement as it allowed for more efficient use of the computer's resources.

In the 1960s, IBM developed the OS/360, one of the first operating systems to be widely adopted by
businesses. This OS was designed for IBM's mainframe computers and featured advanced memory
management and job scheduling capabilities.

The 1970s saw the introduction of personal computers and the development of operating systems
specifically designed with these smaller, less powerful machines. Microsoft's MS-DOS and Apple's Macintosh
operating systems were two of the most popular OSs of this era. These operating systems were much simpler
than their mainframe counterparts but still provided the basic functions for running personal computer
applications.

The 1980s and 1990s saw the emergence of graphical user interfaces (GUIs), which made operating systems
even more user-friendly. Microsoft's Windows and Apple's Macintosh operating systems were the most
popular of this era. Both featured a GUI that allowed users to interact with the computer using a mouse and
icons rather than typing commands.
UNIT 1: Introduction to Operating System
The introduction of the internet in the late 1990s and early 2000s led to the development of operating
systems optimized for use with the internet, such as Linux and Google's Android. These operating systems
are open-source, meaning the code is publicly available for anyone to use and modify.

Today, operating systems continue to evolve and adapt to new technologies. Mobile operating systems, such
as iOS and Android, are designed specifically for smartphones and tablets, and cloud-based operating
systems, such as Chrome OS, are designed to run on internet-connected devices.

Overall, the introduction of operating systems has played a crucial role in the evolution of computers, making
them more efficient and user-friendly. From the early days of time-sharing systems to today's modern mobile
and cloud-based operating systems, operating systems have continuously adapted to new technologies and
changing user needs.

Developments of Operating System with Time

Operating systems have come a long way since their inception in the 1950s. From the early days of time-
sharing systems to the modern, highly advanced operating systems of today, several key developments have
played a crucial role in shaping the evolution of these essential software programs.

One of the most significant developments in the history of operating systems was the introduction of
graphical user interfaces (GUIs) in the 1980s. Before this, operating systems were primarily text-based,
requiring users to input commands through a command line interface. The introduction of GUIs, such as
those found in Microsoft Windows and Apple Macintosh, made operating systems much more user-friendly,
allowing users to interact with the computer using a mouse and icons rather than typing commands.

Another important development was the introduction of multitasking. This feature allowed multiple
programs to run simultaneously on a single computer, greatly increasing the efficiency and productivity of
the machine. Early operating systems, such as MS-DOS, could only run one program at a time. Still, modern
operating systems, such as Windows and macOS, can run multiple programs in the background, allowing
users to work on various tasks simultaneously.

The advent of the internet in the late 1990s and early 2000s brought about the development of operating
systems optimized for use with the internet, such as Linux and Android. These operating systems are open-
source, meaning the code is publicly available for anyone to use and modify. It has created many different
versions of these operating systems, each tailored to specific needs and uses.

The advent of the internet in the late 1990s and early 2000s brought about the development of operating
systems optimized for use with the internet, such as Linux and Android. These operating systems are open-
source, meaning the code is publicly available for anyone to use and modify. It has created many different
versions of these operating systems, each tailored to specific needs and uses.

Another important development is the emergence of mobile operating systems, such as iOS and Android,
designed specifically for smartphones and tablets. These operating systems are optimized for touch-based
input and are designed to be lightweight and efficient, allowing them to run on devices with limited
resources.

In recent years, there has been a growing trend towards cloud-based operating systems, such as Chrome OS.
These operating systems are designed to run on internet-connected devices and rely on cloud-based services
for storage and processing rather than local hardware. It allows for increased flexibility and accessibility, as
users can access their files and programs from any device with an internet connection.
UNIT 1: Introduction to Operating System
In conclusion, the developments of operating systems over the years have greatly improved the efficiency
and user-friendliness of computers. These advancements have greatly impacted how we interact with and
use computers, from the introduction of GUIs and multitasking to the emergence of mobile and cloud-based
operating systems.

Features of the Operating System

There are many different operating systems, each with unique features. Here, we will discuss some of the
common features of operating systems.

1. Memory Management: An operating system manages the computer's memory, ensuring each
program has enough memory to run properly. It includes allocating memory to programs, freeing up
memory when a program is closed, and preventing programs from accessing memory that does not
belong to them.
2. Process Management: An operating system is responsible for running processes. It includes creating
new processes, terminating existing processes, and managing operations scheduling to ensure that
the computer's resources are used efficiently.
3. File Management: An operating system manages the file system, which stores and organizes files on
the computer's hard drive. It includes creating, deleting, and moving files and managing permissions
and access to files.
4. Security: Operating systems include security features to prevent unauthorized computer and
resource access. It may consist of user authentication, encryption, and firewalls.
5. Hardware Management: An operating system communicates with the computer's hardware, such as
the CPU, memory, and storage devices. It allows the operating system to control and manage the
computer's hardware resources.
6. Networking: Operating systems also include features for connecting to networks, such as TCP/IP
networking protocol support and support for wired and wireless networks.
7. User Interface: An operating system includes a user interface, which allows the user to interact with
the computer. It may consist of a command-line interface, a graphical user interface (GUI), or a
combination.

In conclusion, an operating system is the backbone of a computer, and it plays a crucial role in managing the
computer's hardware and software resources. The features discussed above are just a few examples of the
many features found in modern operating systems. Each operating system has unique features and
capabilities, and the choice of the operating system will depend on the user's or organization's specific needs.

Types of Operating Systems

Here, we will discuss some of the most common types of operating systems.

1. Windows: Windows is one of the world's most widely used operating systems. Microsoft developed
and distributed it, used mainly on personal computers and servers. Windows is known for its user-
friendly graphical user interface (GUI) and wide range of software compatibility.
UNIT 1: Introduction to Operating System
2. MacOS: MacOS is an operating system developed and distributed by Apple Inc. for its Macintosh line
of computers. It is known for its sleek and modern design and is often favored by creative
professionals for its advanced graphics and video editing capabilities.
3. Linux: Linux is an open-source operating system known for its stability, security, and flexibility. It is
widely used on servers and can also be used on personal computers. Linux is highly customizable and
can be modified to suit an organization's or user's needs.
4. UNIX: UNIX is a multi-user and multitasking operating system known for its stability and security. It
is primarily used on servers and workstations and is often used in enterprise and academic
environments.
5. Chrome OS: Chrome OS is a lightweight, cloud-based operating system developed by Google. It is
primarily used on Chromebooks, laptops, and tablets that run on the Chrome browser. Chrome OS is
known for its speed, security, and simplicity.
6. Mobile OS: Mobile operating systems such as iOS, Android, and Windows Phone are designed for
smartphones and tablets. They have different features and capabilities than traditional desktop
operating systems and are optimized for touchscreens and mobile usage.

In conclusion, many different operating systems are available, each with unique features and capabilities.
The choice of the operating system will depend on the user's or organization's specific needs. For example,
Windows and MacOS are popular for personal computers, while Linux and UNIX are often used on servers.
Mobile operating systems are designed for smartphones and tablets, while Chrome OS is optimized for
lightweight, cloud-based computing.

Advantages and Disadvantages of Operating System


There are several advantages and disadvantages to using an operating system.

Advantages of Operating Systems:

1. Resource management: An operating system manages the computer's resources, such as memory
and processing power, to ensure that all programs run efficiently.
2. Security: Operating systems include security features to protect the computer from unauthorized
access and viruses.
3. User interface: Operating systems provide a user-friendly interface that makes it easy for users to
navigate and perform tasks on the computer.
4. Compatibility: Operating systems are designed to work with a wide range of hardware and software,
making it easy for users to add new devices and programs to the computer.
5. Multitasking: Operating systems allow multiple programs to run simultaneously, making switching
between tasks easy.
UNIT 1: Introduction to Operating System
Disadvantages of Operating Systems:

1. Cost: Operating systems can be expensive, especially for commercial software.


2. Complexity: Operating systems are complex programs that can be difficult to learn and use.
3. Security vulnerabilities: Despite the built-in security features, operating systems are vulnerable to
viruses and other forms of malware.
4. Resource hog: Some operating systems are resource-intensive and require powerful hardware to run
efficiently.
5. Limited customization: Some operating systems are proprietary and have limited options for
customization.

In conclusion, operating systems play a vital role in managing and controlling the computer's resources and
ensuring the smooth running of applications. However, they also have disadvantages, such as cost,
complexity, and security vulnerabilities. Ultimately, the choice of an operating system will depend on the
specific needs and requirements of the user.

Social Implications of Operating System

While they may seem like a technical aspect of computing, operating systems have significant social
implications.

One of the operating systems' most significant social implications is their role in shaping how we interact
with technology. An operating system's user interface and design can significantly impact how easy or
difficult it is for people to use technology. For example, an operating system with a simple and intuitive
interface can make technology more accessible to people who may not be as tech-savvy. In contrast, a
complex and confusing interface can create barriers to access.

Another social implication of operating systems is their impact on economic inequality. The cost of operating
systems and the hardware required to run them can be a significant financial burden for some individuals
and communities. It can create a digital divide, where some people have access to the latest technology and
the benefits that come with it, while others do not.

Operating systems also have implications for privacy and security. The security features of an operating
system can protect personal information and data from unauthorized access and breaches, while a lack of
security can expose individuals to cyber threats. Operating systems' data collection and sharing policies can
also have privacy implications, affecting how and where personal information is stored and used.

In addition, the market dominance of certain operating systems can have social implications, as it can limit
competition and innovation in the software industry. For example, if a single operating system has a
dominant market share, it can limit the choices available to consumers and create a monopoly.

Operating systems are crucial in shaping how we interact with technology and have social implications for
accessibility, economic inequality, privacy, security, and competition. It's important for individuals and
communities to be aware of these implications and to make informed choices about the operating systems
they use.
UNIT 1: Introduction to Operating System
Conclusion

In conclusion, operating systems are a vital component of modern computing. They serve as the bridge
between the hardware and software of a computer, managing resources and ensuring that all programs run
efficiently. They also provide security features to protect against unauthorized access and viruses. Operating
systems have many advantages, such as a user-friendly interface, compatibility, and multitasking capabilities.
However, they also have disadvantages, such as cost, complexity, and security vulnerabilities.

Operating systems also have significant social implications, shaping how we interact with technology and
impacting accessibility, economic inequality, privacy, and competition. Individuals and communities must
know these implications and make informed choices about operating systems.

Operating systems are a crucial aspect of computing, and choosing the right one for your needs is important.
The selection of the appropriate operating system would depend on the specific needs, budget, and level of
expertise. With the right operating system, individuals and organizations can take full advantage of the
capabilities of their computer systems.

History of the Operating System


Operating System

The operating system is a system program that serves as an interface between the computing system and
the end-user. Operating systems create an environment where the user can run any programs or
communicate with software or applications in a comfortable and well-organized way.

Furthermore, an operating is a software program that manages and controls the execution of application
programs, software resources and computer hardware. It also helps manage the software/hardware
resource, such as file management, memory management, input/ output and many peripheral devices like
a disk drive, printers, etc. These are the popular operating system: Linux OS, Windows OS, Mac OS, VMS,
OS/400 etc.
UNIT 1: Introduction to Operating System
Functions of Operating System

o Processor management
o Act as a Resource Manager
o Memory Management
o File Management
o Security
o Device Management
o Input devices / Output devices
o Deadlock Prevention
o Time Management
o Coordinate with system software or hardware

Types of Operating System

1. Batch Operating System


2. Time-Sharing Operating System
3. Embedded Operating System
4. Multiprogramming Operating System
5. Network Operating System
6. Distributed Operating System
7. Multiprocessing Operating System
8. Real-Time Operating System

Batch Operating System

In Batch Operating System, there is no direct interaction between user and computer. Therefore, the user
needs to prepare jobs and save offline mode to punch card or paper tape or magnetic tape. After creating
the jobs, hand it over to the computer operator; then the operator sort or creates the similar types of batches
like B2, B3, and B4. Now, the computer operator submits batches into the CPU to execute the jobs one by
one. After that, CPUs start executing jobs, and when all jobs are finished, the computer operator provides
the output to the user.

Time-Sharing Operating System

It is the type of operating system that allows us to connect many people located at different locations to
share and use a specific system at a single time. The time-sharing operating system is the logical extension
of the multiprogramming through which users can run multiple tasks concurrently. Furthermore, it provides
each user his terminal for input or output that impacts the program or processor currently running on the
system. It represents the CPU's time is shared between many user processes. Or, the processor's time that
is shared between multiple users simultaneously termed as time-sharing.
UNIT 1: Introduction to Operating System

Embedded Operating System

The Embedded operating system is the specific purpose operating system used in the computer system's
embedded hardware configuration. These operating systems are designed to work on dedicated devices like
automated teller machines (ATMs), airplane systems, digital home assistants, and the internet of things (IoT)
devices.
UNIT 1: Introduction to Operating System
Multiprogramming Operating System

Due to the CPU's underutilization and the waiting for I/O resource till that CPU remains idle. It shows the
improper use of system resources. Hence, the operating system introduces a new concept that is known as
multiprogramming. A multiprogramming operating system refers to the concepts wherein two or more
processes or programs activate simultaneously to execute the processes one after another by the same
computer system. When a program is in run mode and uses CPU, another program or file uses I/O resources
at the same time or waiting for another system resources to become available. It improves the use of system
resources, thereby increasing system throughput. Such a system is known as a multiprogramming operating
system.

Network Operating System

A network operating system is an important category of the operating system that operates on a server using
network devices like a switch, router, or firewall to handle data, applications and other network resources.
It provides connectivity among the autonomous operating system, called as a network operating system.
The network operating system is also useful to share data, files, hardware devices and printer resources
among multiple computers to communicate with each other.
UNIT 1: Introduction to Operating System
Types of network operating system

o Peer-to-peer network operating system: The type of network operating system allows users to share
files, resources between two or more computer machines using a LAN.

o Client-Server network operating system: It is the type of network operating system that allows the
users to access resources, functions, and applications through a common server or center hub of the
resources. The client workstation can access all resources that exist in the central hub of the network.
Multiple clients can access and share different types of the resource over the network from different
locations.
UNIT 1: Introduction to Operating System
Distributed Operating system

A distributed operating system provides an environment in which multiple independent CPU or processor
communicates with each other through physically separate computational nodes. Each node contains
specific software that communicates with the global aggregate operating system. With the ease of a
distributed system, the programmer or developer can easily access any operating system and resource to
execute the computational tasks and achieve a common goal. It is the extension of a network operating
system that facilitates a high degree of connectivity to communicate with other users over the network.

Multiprocessing Operating System

It is the type of operating system that refers to using two or more central processing units (CPU) in a single
computer system. However, these multiprocessor systems or parallel operating systems are used to increase
the computer system's efficiency. With the use of a multiprocessor system, they share computer bus, clock,
memory and input or output device for concurrent execution of process or program and resource
management in the CPU.

Real-Time Operating System

A real-time operating system is an important type of operating system used to provide services and data
processing resources for applications in which the time interval required to process & respond to
input/output should be so small without any delay real-time system. For example, real-life situations
governing an automatic car, traffic signal, nuclear reactor or an aircraft require an immediate response to
complete tasks within a specified time delay. Hence, a real-time operating system must be fast and
responsive for an embedded system, weapon system, robots, scientific research & experiments and various
real-time objects.
UNIT 1: Introduction to Operating System
Types of the real-time operating system:

o Hard-Real-Time-System
These types of OS are used with those required to complete critical tasks within the defined time
limit. If the response time is high, it is not accepted by the system or may face serious issues like a
system failure. In a hard real-time system, the secondary storage is either limited or missing, so these
system stored data in the ROM.
o Soft-Real-Time-System
A soft real-time system is a less restrictive system that can accept software and hardware resources
delays by the operating system. In a soft real-time system, a critical task prioritizes less important
tasks, and that priority retains active until completion of the task. Also, a time limit is set for a specific
job, which enables short time delays for further tasks that are acceptable. For example, computer
audio or video, virtual reality, reservation system, projects like undersea, etc.

Generations of Operating System

The First Generation (1940 to early 1950s)

When the first electronic computer was developed in 1940, it was created without any operating system. In
early times, users have full access to the computer machine and write a program for each task in absolute
machine language. The programmer can perform and solve only simple mathematical calculations during
the computer generation, and this calculation does not require an operating system.

The Second Generation (1955 - 1965)

The first operating system (OS) was created in the early 1950s and was known as GMOS. General Motors has
developed OS for the IBM computer. The second-generation operating system was based on a single stream
batch processing system because it collects all similar jobs in groups or batches and then submits the jobs to
the operating system using a punch card to complete all jobs in a machine. At each completion of jobs (either
normally or abnormally), control transfer to the operating system that is cleaned after completing one job
and then continues to read and initiates the next job in a punch card. After that, new machines were called
mainframes, which were very big and used by professional operators.

The Third Generation (1965 - 1980)

During the late 1960s, operating system designers were very capable of developing a new operating system
that could simultaneously perform multiple tasks in a single computer program called multiprogramming.
The introduction of multiprogramming plays a very important role in developing operating systems that
allow a CPU to be busy every time by performing different tasks on a computer at the same time. During the
third generation, there was a new development of minicomputer's phenomenal growth starting in 1961 with
the DEC PDP-1. These PDP's leads to the creation of personal computers in the fourth generation.

The Fourth Generation (1980 - Present Day)

The fourth generation of operating systems is related to the development of the personal computer.
However, the personal computer is very similar to the minicomputers that were developed in the third
generation. The cost of a personal computer was very high at that time; there were small fractions of
minicomputers costs. A major factor related to creating personal computers was the birth of Microsoft and
UNIT 1: Introduction to Operating System
the Windows operating system. Microsoft created the first window operating system in 1975. After
introducing the Microsoft Windows OS, Bill Gates and Paul Allen had the vision to take personal computers
to the next level. Therefore, they introduced the MS-DOS in 1981; however, it was very difficult for the
person to understand its cryptic commands. Today, Windows has become the most popular and most
commonly used operating system technology. And then, Windows released various operating systems such
as Windows 95, Windows 98, Windows XP and the latest operating system, Windows 7. Currently, most
Windows users use the Windows 10 operating system. Besides the Windows operating system, Apple is
another popular operating system built in the 1980s, and this operating system was developed by Steve Jobs,
a co-founder of Apple. They named the operating system Macintosh OS or Mac OS.

Advantages of Operating System

o It is helpful to monitor and regulate resources.


o It can easily operate since it has a basic graphical user interface to communicate with your device.
o It is used to create interaction between the users and the computer application or hardware.
o The performance of the computer system is based on the CPU.
o The response time and throughput time of any process or program are fast.
o It can share different resources like fax, printer, etc.
o It also offers a forum for various types of applications like system and web application.

Disadvantage of the Operating System

o It allows only a few tasks that can run at the same time.
o It any error occurred in the operating system; the stored data can be destroyed.
o It is a very difficult task or works for the OS to provide entire security from the viruses because any
threat or virus can occur at any time in a system.
o An unknown user can easily use any system without the permission of the original user.
o The cost of operating system costs is very high.

Operating System Structure

Overview

An operating system is a design that enables user application programs to communicate with the hardware
of the machine. The operating system should be built with the utmost care because it is such a complicated
structure and should be simple to use and modify. Partially developing the operating system is a simple
approach to accomplish this. Each of these components needs to have distinct inputs, outputs, and
functionalities.

This article discusses many sorts of structures that implement operating systems, as listed below, as well as
how and why they work. It also defines the operating system structure.

o Simple Structure
o Monolithic Structure
UNIT 1: Introduction to Operating System
o Layered Approach Structure
o Micro-Kernel Structure
o Exo-Kernel Structure
o Virtual Machines

What is an operating System Structure?

We want a clear structure to let us apply an operating system to our particular needs because operating
systems have complex structures. It is easier to create an operating system in pieces, much as we break
down larger issues into smaller, more manageable subproblems. Every segment is also a part of the
operating system. Operating system structure can be thought of as the strategy for connecting and
incorporating various operating system components within the kernel. Operating systems are implemented
using many types of structures, as will be discussed below:

SIMPLE STRUCTURE

It is the most straightforward operating system structure, but it lacks definition and is only appropriate for
usage with tiny and restricted systems. Since the interfaces and degrees of functionality in this structure are
clearly defined, programs are able to access I/O routines, which may result in unauthorized access to I/O
procedures.

This organizational structure is used by the MS-DOS operating system:

o There are four layers that make up the MS-DOS operating system, and each has its own set of
features.
o These layers include ROM BIOS device drivers, MS-DOS device drivers, application programs, and
system programs.
o The MS-DOS operating system benefits from layering because each level can be defined
independently and, when necessary, can interact with one another.
o If the system is built in layers, it will be simpler to design, manage, and update. Because of this, simple
structures can be used to build constrained systems that are less complex.
o When a user program fails, the operating system as whole crashes.
o Because MS-DOS systems have a low level of abstraction, programs and I/O procedures are visible to
end users, giving them the potential for unwanted access.

The following figure illustrates layering in simple structure:


UNIT 1: Introduction to Operating System

Advantages of Simple Structure:

o Because there are only a few interfaces and levels, it is simple to develop.
o Because there are fewer layers between the hardware and the applications, it offers superior
performance.

Disadvantages of Simple Structure:

o The entire operating system breaks if just one user program malfunctions.
o Since the layers are interconnected, and in communication with one another, there is no abstraction
or data hiding.
o The operating system's operations are accessible to layers, which can result in data tampering and
system failure.

MONOLITHIC STRUCTURE

The monolithic operating system controls all aspects of the operating system's operation, including file
management, memory management, device management, and operational operations.

The core of an operating system for computers is called the kernel (OS). All other System components are
provided with fundamental services by the kernel. The operating system and the hardware use it as their
UNIT 1: Introduction to Operating System
main interface. When an operating system is built into a single piece of hardware, such as a keyboard or
mouse, the kernel can directly access all of its resources.

The monolithic operating system is often referred to as the monolithic kernel. Multiple programming
techniques such as batch processing and time-sharing increase a processor's usability. Working on top of the
operating system and under complete command of all hardware, the monolithic kernel performs the role of
a virtual computer. This is an old operating system that was used in banks to carry out simple tasks like batch
processing and time-sharing, which allows numerous users at different terminals to access the Operating
System.

The following diagram represents the monolithic structure:

Advantages of Monolithic Structure:

o Because layering is unnecessary and the kernel alone is responsible for managing all operations, it is
easy to design and execute.
o Due to the fact that functions like memory management, file management, process scheduling, etc.,
are implemented in the same address area, the monolithic kernel runs rather quickly when compared
to other systems. Utilizing the same address speeds up and reduces the time required for address
allocation for new processes.
o
UNIT 1: Introduction to Operating System
Disadvantages of Monolithic Structure:

o The monolithic kernel's services are interconnected in address space and have an impact on one
another, so if any of them malfunctions, the entire system does as well.
o It is not adaptable. Therefore, launching a new service is difficult.

LAYERED STRUCTURE

The OS is separated into layers or levels in this kind of arrangement. Layer 0 (the lowest layer) contains the
hardware, and layer 1 (the highest layer) contains the user interface (layer N). These layers are organized
hierarchically, with the top-level layers making use of the capabilities of the lower-level ones.

The functionalities of each layer are separated in this method, and abstraction is also an option. Because
layered structures are hierarchical, debugging is simpler, therefore all lower-level layers are debugged
before the upper layer is examined. As a result, the present layer alone has to be reviewed since all the lower
layers have already been examined.

The image below shows how OS is organized into layers:

Advantages of Layered Structure:

o Work duties are separated since each layer has its own functionality, and there is some amount of
abstraction.
o Debugging is simpler because the lower layers are examined first, followed by the top layers.
UNIT 1: Introduction to Operating System
Disadvantages of Layered Structure:

o Performance is compromised in layered structures due to layering.


o Construction of the layers requires careful design because upper layers only make use of lower layers'
capabilities.

MICRO-KERNEL STRUCTURE

The operating system is created using a micro-kernel framework that strips the kernel of any unnecessary
parts. Systems and user applications are used to implement these optional kernel components. So, Micro-
Kernels is the name given to these systems that have been developed.

Each Micro-Kernel is created separately and is kept apart from the others. As a result, the system is now
more trustworthy and secure. If one Micro-Kernel malfunctions, the remaining operating system is
unaffected and continues to function normally.

The image below shows Micro-Kernel Operating System Structure:

Advantages of Micro-Kernel Structure:

o It enables portability of the operating system across platforms.


o Due to the isolation of each Micro-Kernel, it is reliable and secure.
o The reduced size of Micro-Kernels allows for successful testing.
o The remaining operating system remains unaffected and keeps running properly even if a component
or Micro-Kernel fails.
UNIT 1: Introduction to Operating System
Disadvantages of Micro-Kernel Structure:

o The performance of the system is decreased by increased inter-module communication.


o The construction of a system is complicated.

EXOKERNEL

An operating system called Exokernel was created at MIT with the goal of offering application-level
management of hardware resources. The exokernel architecture's goal is to enable application-specific
customization by separating resource management from protection. Exokernel size tends to be minimal due
to its limited operability.

Because the OS sits between the programs and the actual hardware, it will always have an effect on the
functionality, performance, and breadth of the apps that are developed on it. By rejecting the idea that an
operating system must offer abstractions upon which to base applications, the exokernel operating system
makes an effort to solve this issue. The goal is to give developers as few restriction on the use of abstractions
as possible while yet allowing them the freedom to do so when necessary. Because of the way the exokernel
architecture is designed, a single tiny kernel is responsible for moving all hardware abstractions into
unreliable libraries known as library operating systems. Exokernels differ from micro- and monolithic kernels
in that their primary objective is to prevent forced abstraction.

Exokernel operating systems have a number of features, including:

o Enhanced application control support.


o Splits management and security apart.
o A secure transfer of abstractions is made to an unreliable library operating system.
o Brings up a low-level interface.
o Operating systems for libraries provide compatibility and portability.

Advantages of Exokernel Structure:

o Application performance is enhanced by it.


o Accurate resource allocation and revocation enable more effective utilisation of hardware resources.
o New operating systems can be tested and developed more easily.
o Every user-space program is permitted to utilise its own customised memory management.

Disadvantages of Exokernel Structure:

o A decline in consistency
o Exokernel interfaces have a complex architecture.
UNIT 1: Introduction to Operating System
VIRTUAL MACHINES (VMs)

The hardware of our personal computer, including the CPU, disc drives, RAM, and NIC (Network Interface
Card), is abstracted by a virtual machine into a variety of various execution contexts based on our needs,
giving us the impression that each execution environment is a separate computer. A virtual box is an example
of it.

Using CPU scheduling and virtual memory techniques, an operating system allows us to execute multiple
processes simultaneously while giving the impression that each one is using a separate processor and virtual
memory. System calls and a file system are examples of extra functionalities that a process can have that the
hardware is unable to give. Instead of offering these extra features, the virtual machine method just offers
an interface that is similar to that of the most fundamental hardware. A virtual duplicate of the computer
system underneath is made available to each process.

We can develop a virtual machine for a variety of reasons, all of which are fundamentally connected to the
capacity to share the same underlying hardware while concurrently supporting various execution
environments, i.e., various operating systems.

Disk systems are the fundamental problem with the virtual machine technique. If the actual machine only
has three-disc drives but needs to host seven virtual machines, let's imagine that. It is obvious that it is
impossible to assign a disc drive to every virtual machine because the program that creates virtual machines
would require a sizable amount of disc space in order to offer virtual memory and spooling. The provision of
virtual discs is the solution.

The result is that users get their own virtual machines. They can then use any of the operating systems or
software programs that are installed on the machine below. Virtual machine software is concerned with
programming numerous virtual machines simultaneously into a physical machine; it is not required to take
into account any user-support software. With this configuration, it may be possible to break the challenge
of building an interactive system for several users into two manageable chunks.

Advantages of Virtual Machines:

o Due to total isolation between each virtual machine and every other virtual machine, there are no
issues with security.
o A virtual machine may offer an architecture for the instruction set that is different from that of actual
computers.
o Simple availability, accessibility, and recovery convenience.

Disadvantages of Virtual Machines:

o Depending on the workload, operating numerous virtual machines simultaneously on a host


computer may have an adverse effect on one of them.
o When it comes to hardware access, virtual computers are less effective than physical ones.
UNIT 1: Introduction to Operating System
CONCLUSION

o The operating system makes it possible for the user to communicate with the hardware of the
computer. The operating system is used as the foundation for installing and using system software.
o The interconnections between the various operating system components can be defined as the
operating system structure.
o The operating system is divided into various different structural types: simple structure, monolithic
approach, layered approach, micro-kernels, exokernels, and virtual machines.
o Each time one of these methods or structures changed, the OS became progressively better.

What is Kernel?

In computer science, Kernel is a computer program that is a core or heart of an operating system. Before
discussing kernel in detail, let's first understand its basic, i.e., Operating system in a computer.

Operating System

An operating system or OS is system software that works as an interface between hardware components
and end-user. It enables other programs to run. Each computer system, whether it is desktop, laptop, tablet,
or smartphone, all must have an OS to provide basic functionalities for the device. Some widely used
operating systems are Windows, Linux, MacOS, Android, iOS, etc.

What is Kernel in Operating System?

o As discussed above, Kernel is the core part of an OS(Operating system); hence it has full control over
everything in the system. Each operation of hardware and software is managed and administrated
by the kernel.
UNIT 1: Introduction to Operating System
o It acts as a bridge between applications and data processing done at the hardware level. It is the
central component of an OS.
o It is the part of the OS that always resides in computer memory and enables the communication
between software and hardware components.
o It is the computer program that first loaded on start-up the system (After the bootloader). Once it is
loaded, it manages the remaining start-ups. It also manages memory, peripheral, and I/O requests
from software. Moreover, it translates all I/O requests into data processing instructions for the CPU.
It manages other tasks also such as memory management, task management, and disk
management.
o A kernel is kept and usually loaded into separate memory space, known as protected Kernel space. It
is protected from being accessed by application programs or less important parts of OS.
o Other application programs such as browser, word processor, audio & video player use separate
memory space known as user-space.
o Due to these two separate spaces, user data and kernel data don't interfere with each other and do
not cause any instability and slowness.

Functions of a Kernel

A kernel of an OS is responsible for performing various functions and has control over the system. Some
main responsibilities of Kernel are given below:

o Device-Management
To perform various actions, processes require access to peripheral devices such as a mouse,
keyboard, etc., that are connected to the computer. A kernel is responsible for controlling these
devices using device drivers. Here, a device driver is a computer program that helps or enables the
OS to communicate with any hardware device.
A kernel maintains a list of all the available devices, and this list may be already known, configured
by the user, or detected by OS at runtime.
o Memory Management
The kernel has full control for accessing the computer's memory. Each process requires some
memory to work, and the kernel enables the processes to safely access the memory. To allocate the
memory, the first step is known as virtual addressing, which is done by paging or
segmentation. Virtual addressing is a process of providing virtual address spaces to the processes.
This prevents the application from crashing into each other.
o Resource Management
One of the important functionalities of Kernel is to share the resources between various processes.
It must share the resources in a way that each process uniformly accesses the resource.
The kernel also provides a way for synchronization and inter-process communication (IPC). It is
responsible for context switching between processes.
UNIT 1: Introduction to Operating System
o Accessing-Computer-Resources
A kernel is responsible for accessing computer resources such as RAM and I/O devices. RAM or
Random-Access Memory is used to contain both data and instructions. Each program needs to access
the memory to execute and mostly wants more memory than the available. For such a case, Kernel
plays its role and decides which memory each process will use and what to do if the required memory
is not available.
The kernel also allocates the request from applications to use I/O devices such as keyboards,
microphones, printers, etc.

Types of Kernel

There are mainly five types of Kernel, which are given below:

1. Monolithic Kernels

In a monolithic kernel, the same memory space is used to implement user services and kernel services.
UNIT 1: Introduction to Operating System
It means, in this type of kernel, there is no different memory used for user services and kernel services.

As it uses the same memory space, the size of the kernel increases, increasing the overall size of the OS.

The execution of processes is also faster than other kernel types as it does not use separate user and kernel
space.

Examples of Monolithic Kernels are Unix, Linux, Open VMS, XTS-400, etc.

Advantages:

o The execution of processes is also faster as there is no separate user space and kernel space and less
software involved.
o As it is a single piece of software hence, it's both sources and compiled forms are smaller.

Disadvantages:

o If any service generates any error, it may crash down the whole system.
o These kernels are not portable, which means for each new architecture, they must be rewritten.
o Large in size and hence become difficult to manage.
o To add a new service, the complete operating system needs to be modified.

2. Microkernel

A microkernel is also referred to as μK, and it is different from a traditional kernel or Monolithic Kernel. In
this, user services and kernel services are implemented into two different address spaces: user space and
kernel space. Since it uses different spaces for both the services, so, the size of the microkernel is decreased,
and which also reduces the size of the OS.

Microkernels are easier to manage and maintain as compared to monolithic kernels. Still, if there will be a
greater number of system calls and context switching, then it might reduce the performance of the system
by making it slow.

These kernels use a message passing system for handling the request from one server to another server.
UNIT 1: Introduction to Operating System
Only some essential services are provided by microkernels, such as defining memory address spaces,
IPC(Interprocess Communication), and process management. Other services such as networking are not
provided by Kernel and handled by a user-space program known as servers.

One of the main disadvantages of monolithic kernels that an error in the kernel can crash the whole system,
can be removed in the microkernel. As in a microkernel, if a kernel process crashes, the crashing of the whole
system can still be prevented by restarting the error-caused services.

Examples of Microkernel are L4, AmigaOS, Minix, K42, etc.

Advantages

o Microkernels can be managed easily.


o A new service can be easily added without modifying the whole OS.
o In a microkernel, if a kernel process crashes, it is still possible to prevent the whole system from
crashing.

Disadvantages

o There is more requirement of software for interfacing, which reduces the system performance.
o Process management is very complicated.
o The messaging bugs are difficult to fix.

3. Hybrid Kernel

Hybrid kernels are also known as modular kernels, and it is the combination of both Monolithic and
Microkernels. It takes advantage of the speed of monolithic kernels and the modularity of microkernels.

A hybrid kernel can be understood as the extended version of a microkernel with additional properties of
a monolithic kernel. These kernels are widely used in commercial OS, such as different versions of MS
Windows.

It is much similar to a microkernel, but it also includes some additional code in kernel space to enhance the
performance of the system.
UNIT 1: Introduction to Operating System
Hybrid kernels allow to run some services such as network stack in kernel space to reduce the performance
compared to a traditional microkernel, but it still allows to run kernel code (such as device drivers) as servers
in user-space.

Examples of Hybrid Kernel are Windows NT, Netware, BeOS, etc.

Advantages:

o There is no requirement for a reboot for testing.


o Third-party technology can be integrated rapidly.

Disadvantages:

o There is a possibility of more bugs with more interfaces to pass through.


o It can be a confusing task to maintain the modules for some administrators, especially when dealing
with issues such as symbol differences.

4. Nanokernel

As the name suggests, in Nanokernel, the complete code of the kernel is very small, which means the code
executing in the privileged mode of the hardware is very small. Here the term nano defines a kernel that
supports a nanosecond clock resolution.

Examples of Nanokernel are EROS etc.

Advantages

o It provides hardware abstractions even with a very small size.

Disadvantages

o Nanokernel lacks system services.

5. Exokernel

Exokernel is still developing and is the experimental approach for designing OS.

This type of kernel is different from other kernels as in this; resource protection is kept separated from
management, which allows us to perform application-specific customization.

Advantages:

o The exokernel-based system can incorporate multiple library operating systems. Each library exports
a different API, such as one can be used for high-level UI development, and the other can be used for
real-time control.
UNIT 1: Introduction to Operating System
Disadvantages:

o The design of the exokernel is very complex.

What is Kernel Panics?

As we have already discussed, that kernel controls over entire computer system; hence if it crashes, it can
take down the whole system. In MacOS and Linux, such an undesirable event is known as "Kernel Panic." To
recover from kernel Panic, we need to restart the system.

Usually, these kernel panics are caused by hardware communication issues. Hence, if repeated kernel panics
are occurring, then try to unplug the less required or unnecessary devices and check if the problem is get
resolved or not.

System Calls in Operating System (OS)

A system call is a way for a user program to interface with the operating system. The program requests
several services, and the OS responds by invoking a series of system calls to satisfy the request. A system call
can be written in assembly language or a high-level language like C or Pascal. System calls are predefined
functions that the operating system may directly invoke if a high-level language is used.

In this article, you will learn about the system calls in the operating system and discuss their types and many
other things.

What is a System Call?

A system call is a method for a computer program to request a service from the kernel of the operating
system on which it is running. A system call is a method of interacting with the operating system via
programs. A system call is a request from computer software to an operating system's kernel.

The Application Program Interface (API) connects the operating system's functions to user programs. It acts
as a link between the operating system and a process, allowing user-level programs to request operating
system services. The kernel system can only be accessed using system calls. System calls are required for any
programs that use resources.

How are system calls made?

When a computer software needs to access the operating system's kernel, it makes a system call. The system
call uses an API to expose the operating system's services to user programs. It is the only method to access
the kernel system. All programs or processes that require resources for execution must use system calls, as
they serve as an interface between the operating system and user programs.

Below are some examples of how a system call varies from a user function.

1. A system call function may create and use kernel processes to execute the asynchronous processing.
2. A system call has greater authority than a standard subroutine. A system call with kernel-mode
privilege executes in the kernel protection domain.
3. System calls are not permitted to use shared libraries or any symbols that are not present in the
kernel protection domain.
UNIT 1: Introduction to Operating System
4. The code and data for system calls are stored in global kernel memory.

Why do you need system calls in Operating System?

There are various situations where you must require system calls in the operating system. Following of the
situations are as follows:

1. It is must require when a file system wants to create or delete a file.


2. Network connections require the system calls to sending and receiving data packets.
3. If you want to read or write a file, you need to system calls.
4. If you want to access hardware devices, including a printer, scanner, you need a system call.
5. System calls are used to create and manage new processes.

How System Calls Work

The Applications run in an area of memory known as user space. A system call connects to the operating
system's kernel, which executes in kernel space. When an application creates a system call, it must first
obtain permission from the kernel. It achieves this using an interrupt request, which pauses the current
process and transfers control to the kernel.

If the request is permitted, the kernel performs the requested action, like creating or deleting a file. As input,
the application receives the kernel's output. The application resumes the procedure after the input is
received. When the operation is finished, the kernel returns the results to the application and then moves
data from kernel space to user space in memory.

A simple system call may take few nanoseconds to provide the result, like retrieving the system date and
time. A more complicated system call, such as connecting to a network device, may take a few seconds. Most
operating systems launch a distinct kernel thread for each system call to avoid bottlenecks. Modern
operating systems are multi-threaded, which means they can handle various system calls at the same time.

Types of System Calls

There are commonly five types of system calls. These are as follows:
UNIT 1: Introduction to Operating System
1. Process Control
2. File Management
3. Device Management
4. Information Maintenance
5. Communication

Now, you will learn about all the different types of system calls one-by-one.

Process Control

Process control is the system call that is used to direct the processes. Some process control examples include
creating, load, abort, end, execute, process, terminate the process, etc.

File Management

File management is a system call that is used to handle the files. Some file management examples include
creating files, delete files, open, close, read, write, etc.

Device Management

Device management is a system call that is used to deal with devices. Some examples of device management
include read, device, write, get device attributes, release device, etc.

Information Maintenance

Information maintenance is a system call that is used to maintain information. There are some examples of
information maintenance, including getting system data, set time or date, get time or date, set system data,
etc.

Communication

Communication is a system call that is used for communication. There are some examples of communication,
including create, delete communication connections, send, receive messages, etc.

Examples of Windows and Unix system calls


UNIT 1: Introduction to Operating System
There are various examples of Windows and Unix system calls. These are as listed below in the table:

Process Windows Unix

Process Control CreateProcess() Fork()


ExitProcess() Exit()
WaitForSingleObject() Wait()

File Manipulation CreateFile() Open()


ReadFile() Read()
WriteFile() Write()
CloseHandle() Close()

Device Management SetConsoleMode() Ioctl()


ReadConsole() Read()
WriteConsole() Write()

Information Maintenance GetCurrentProcessID() Getpid()


SetTimer() Alarm()
Sleep() Sleep()

Communication CreatePipe() Pipe()


CreateFileMapping() Shmget()
MapViewOfFile() Mmap()

Protection SetFileSecurity() Chmod()


InitializeSecurityDescriptor() Umask()
SetSecurityDescriptorgroup() Chown()

Here, you will learn about some methods briefly:

open()

The open() system call allows you to access a file on a file system. It allocates resources to the file and
provides a handle that the process may refer to. Many processes can open a file at once or by a single process
only. It's all based on the file system and structure.

read()

It is used to obtain data from a file on the file system. It accepts three arguments in general:

o A file descriptor.
o A buffer to store read data.
o The number of bytes to read from the file.

The file descriptor of the file to be read could be used to identify it and open it using open() before reading.
UNIT 1: Introduction to Operating System
wait()

In some systems, a process may have to wait for another process to complete its execution before
proceeding. When a parent process makes a child process, the parent process execution is suspended until
the child process is finished. The wait() system call is used to suspend the parent process. Once the child
process has completed its execution, control is returned to the parent process.

write()

It is used to write data from a user buffer to a device like a file. This system call is one way for a program to
generate data. It takes three arguments in general:

o A file descriptor.
o A pointer to the buffer in which data is saved.
o The number of bytes to be written from the buffer.

fork()

Processes generate clones of themselves using the fork() system call. It is one of the most common ways to
create processes in operating systems. When a parent process spawns a child process, execution of the
parent process is interrupted until the child process completes. Once the child process has completed its
execution, control is returned to the parent process.

close()

It is used to end file system access. When this system call is invoked, it signifies that the program no longer
requires the file, and the buffers are flushed, the file information is altered, and the file resources are de-
allocated as a result.

exec()

When an executable file replaces an earlier executable file in an already executing process, this system
function is invoked. As a new process is not built, the old process identification stays, but the new process
replaces data, stack, data, head, etc.

exit()

The exit() is a system call that is used to end program execution. This call indicates that the thread execution
is complete, which is especially useful in multi-threaded environments. The operating system reclaims
resources spent by the process following the use of the exit() system function.

What is System Program?

System programming may be defined as the act of creating System Software by using the System
Programming Languages. A system program offers an environment in which programs may be developed
and run. In simple terms, the system programs serve as a link between the user interface (UI) and system
calls. Some system programs are only user interfaces, and others are complex. For instance, a compiler is
complicated system software.
UNIT 1: Introduction to Operating System
The system program is a component of the OS, and it typically lies between the user interface (UI) and
system calls. The system user view is defined by the system programs, not the system call, because the
user view interacts with system programs and is closer to the user interface.

Types of the System Program

There are mainly six types of system programs. These are classified as follows:

1. File Management
2. Status Information
3. File Modification
4. Programming-Language support
5. Program Loading and Execution
6. Communication

Now, you will learn all these different types of system programs one by one.

File Management

It is a collection of specific information saved in a computer system's memory. File management is


described as manipulating files in a computer system, including the creation, modification, and deletion of
files.

Status Information

Status information is information about the input, output process, storage, and CPU utilization time, how
the process will be computed in how much memory is necessary to execute a task.

File Modification

These system programs are utilized to change files on hard drives or other storage media. Besides
modification, these programs are also utilized to search for content within a file or to change content
within a file.

Programming-Language Support

The OS includes certain standard system programs that allow programming languages such as C, Visual
Basic, C++, Java, and Pearl. There are various system programs, including compilers, debuggers,
assemblers, interpreters, etc.

Program Loading and Execution

After Assembling and Compiling, the program must be loaded into the memory for execution. A loader is a
component of an operating system responsible for loading programs and libraries, and it is one of the most
important steps to starting a program. The system includes linkage editors, relocatable loaders, Overlay
loaders, and loaders.
UNIT 1: Introduction to Operating System
Communication

System program offers virtual links between processes, people, and computer systems. Users may browse
websites, log in remotely, communicate messages to other users via their screens, send emails, and
transfer files from one user to another.

Key differences between System Call and System Program in Operating System

There are various key differences between the System Call and System Program in the operating system.
Some main differences between the System Call and System Program are as follows:

1. A user may request access to the operating system's services by using the system call. In contrast,
the system program fulfils a common user request and provides a compatible environment for a
program to create and run effectively.
2. The programmer creates system calls using high-level languages like C and C++. Assembly level
language is used to create the calls that directly interact with the system's hardware. On the other
hand, a programmer solely uses a high-level language to create system programs.
3. System call defines the interface between the services and the user process provided by the OS. In
contrast, the system program defines the operating system's user interface.
4. The system program satisfies the user program's high-level request. It converts the request into a
series of low-level requests. In contrast, the system call fulfils the low-level requests of the user
program.
5. The user process requests an OS service using a system call. In contrast, the system program
transforms the user request into a set of system calls needed to fulfil the requirement.
6. The system call may be categorized into file manipulation, device manipulation, communication,
process control, information maintenance, and protection. On the other hand, a System program
may be categorized into file management, program loading and execution, programming-language
support, status information, communication, and file modification.

Head-to-head comparison between the System Call and System Program in Operating
System
UNIT 1: Introduction to Operating System
The OS has various head-to-head comparisons between System Call and System Program. Some
comparisons of the System Call and System Program are as follows:

Features System Call System Program

Definition It is a technique in which a computer It offers an environment for a program to


system program requests a service from create and run.
the OS kernel.

Request It fulfils the low-level requests of the user It fulfils the high-level request or requirement
program. of the user program.

Programming It is usually written in C and C++ It is commonly written in high-level


Languages programming languages. Assemble-level programming languages only.
language is used in system calls where
direct hardware access is required.

User View It defines the interface between the It defines the user interface (UI) of the OS.
services and the user process provided by
the OS.

Action The user process requests an OS service It transforms the user request into a set of
using a system call. system calls needed to fulfil the requirement.

Classification It may be categorized into file It may be categorized into file management,
manipulation, device manipulation, program loading and execution,
communication, process control, programming-language support, status
information maintenance, and information, file modification, and
protection. communication.
UNIT 1: Introduction to Operating System
Conclusion

Each OS has a unique system call set that specifies what it can and cannot perform. These system calls
invoke system services that the user program has requested. In contrast, the system program satisfies the
usual requests that are requested by the user programs.
UNIT 2: Process Management and Concurrency Control
Process States

State Diagram

The process, from its creation to completion, passes through various states. The minimum number of states
is five.

The names of the states are not standardized although the process may be in one of the following states
during execution.

1. New

A program which is going to be picked up by the OS into the main memory is called a new process.

2. Ready

Whenever a process is created, it directly enters in the ready state, in which, it waits for the CPU to be
assigned. The OS picks the new processes from the secondary memory and put all of them in the main
memory.

The processes which are ready for the execution and reside in the main memory are called ready state
processes. There can be many processes present in the ready state.
UNIT 2: Process Management and Concurrency Control
3. Running

One of the processes from the ready state will be chosen by the OS depending upon the scheduling
algorithm. Hence, if we have only one CPU in our system, the number of running processes for a particular
time will always be one. If we have n processors in the system then we can have n processes running
simultaneously.

4. Block or wait

From the Running state, a process can make the transition to the block or wait state depending upon the
scheduling algorithm or the intrinsic behavior of the process.

When a process waits for a certain resource to be assigned or for the input from the user then the OS move
this process to the block or wait state and assigns the CPU to the other processes.

5. Completion or termination

When a process finishes its execution, it comes in the termination state. All the context of the process
(Process Control Block) will also be deleted the process will be terminated by the Operating system.

6. Suspend ready

A process in the ready state, which is moved to secondary memory from the main memory due to lack of
the resources (mainly primary memory) is called in the suspend ready state.

If the main memory is full and a higher priority process comes for the execution then the OS have to make
the room for the process in the main memory by throwing the lower priority process out into the secondary
memory. The suspend ready processes remain in the secondary memory until the main memory gets
available.

7. Suspend wait

Instead of removing the process from the ready queue, it's better to remove the blocked process which is
waiting for some resources in the main memory. Since it is already waiting for some resource to get available
hence it is better if it waits in the secondary memory and make room for the higher priority process. These
processes complete their execution once the main memory gets available and their wait is finished.

Operations on the Process


1. Creation

Once the process is created, it will be ready and come into the ready queue (main memory) and will be ready
for the execution.

2. Scheduling

Out of the many processes present in the ready queue, the Operating system chooses one process and start
executing it. Selecting the process which is to be executed next, is known as scheduling.
UNIT 2: Process Management and Concurrency Control
3. Execution

Once the process is scheduled for the execution, the processor starts executing it. Process may come to the
blocked or wait state during the execution then in that case the processor starts executing the other
processes.

4. Deletion/killing

Once the purpose of the process gets over then the OS will kill the process. The Context of the process (PCB)
will be deleted and the process gets terminated by the Operating system.

What is Thread?

A thread is the subset of a process and is also known as the lightweight process. A process can have more
than one thread, and these threads are managed independently by the scheduler. All the threads within one
process are interrelated to each other. Threads have some common information, such as data segment,
code segment, files, etc., that is shared to their peer threads. But contains its own registers, stack, and
counter.

How does thread work?

As we have discussed that a thread is a subprocess or an execution unit within a process. A process can
contain a single thread to multiple threads. A thread works as follows:

o When a process starts, OS assigns the memory and resources to it. Each thread within a process
shares the memory and resources of that process only.
o Threads are mainly used to improve the processing of an application. In reality, only a single thread
is executed at a time, but due to fast context switching between threads gives an illusion that threads
are running parallelly.
o If a single thread executes in a process, it is known as a single-threaded And if multiple threads
execute simultaneously, then it is known as multithreading.
UNIT 2: Process Management and Concurrency Control
Types of Threads

There are two types of threads, which are:

1. User Level Thread

As the name suggests, the user-level threads are only managed by users, and the kernel does not have its
information.

These are faster, easy to create and manage.

The kernel takes all these threads as a single process and handles them as one process only.

The user-level threads are implemented by user-level libraries, not by the system calls.

2. Kernel-Level Thread

The kernel-level threads are handled by the Operating system and managed by its kernel. These threads are
slower than user-level threads because context information is managed by the kernel. To create and
implement a kernel-level thread, we need to make a system call.

Features of Thread

o Threads share data, memory, resources, files, etc., with their peer threads within a process.
o One system call is capable of creating more than one thread.
o Each thread has its own stack and register.
o Threads can directly communicate with each other as they share the same address space.
o Threads need to be synchronized in order to avoid unexpected scenarios.

Key Differences Between Process and Thread

o A process is independent and does not contained within another process, whereas all threads are
logically contained within a process.
o Processes are heavily weighted, whereas threads are light-weighted.
o A process can exist individually as it contains its own memory and other resources, whereas a thread
cannot have its individual existence.
o A proper synchronization between processes is not required. In contrast, threads need to be
synchronized in order to avoid unexpected scenarios.
o Processes can communicate with each other using inter-process communication only; in contrast,
threads can directly communicate with each other as they share the same address space.

Difference Table Between Process and Thread


UNIT 2: Process Management and Concurrency Control
Process Thread

A process is an instance of a program that is Thread is a segment of a process or a lightweight process


being executed or processed. that is managed by the scheduler independently.

Processes are independent of each other and Threads are interdependent and share memory.
hence don't share a memory or other
resources.

Each process is treated as a new process by the The operating system takes all the user-level threads as
operating system. a single process.

If one process gets blocked by the operating If any user-level thread gets blocked, all of its peer
system, then the other process can continue threads also get blocked because OS takes all of them as
the execution. a single process.

Context switching between two processes Context switching between the threads is fast because
takes much time as they are heavy compared they are very lightweight.
to thread.

The data segment and code segment of each Threads share data segment and code segment with
process are independent of the other. their peer threads; hence are the same for other threads
also.

The operating system takes more time to Threads can be terminated in very little time.
terminate a process.

New process creation is more time taking as A thread needs less time for creation.
each new process takes all the resources.
UNIT 2: Process Management and Concurrency Control
CPU Scheduling Algorithms in Operating Systems

In this tutorial, we will be learning about the CPU Scheduling Algorithms in Operating Systems. These are
algorithms are very important topic in Operating Systems. This is because this CPU Scheduling Algorithms
forms a base and foundation for the Operating Systems subject.

There are many processes which are going on in the Operating System. A task is a group of processes. Every
task is executed by the Operating System. The Operating System divides the task into many processes. The
final goal of the Operating System is completion of the task.

But there are some certain conditions which must be followed by the task. The conditions are that the Task
must be finished in the quickest possible time with the limited resources which the Operating System have.
This is the main motive of CPU Scheduling Algorithms.

CPU Scheduling

The CPU Scheduling is the process by which a process is executed by the using the resources of the CPU. The
process also can wait due to the absence or unavailability of the resources. These processes make the
complete use of Central Processing Unit.

The operating system must choose one of the processes in the list of ready-to-launch processes whenever
the CPU gets idle. A temporary (CPU) scheduler does the selection. The Scheduler choose one of the ready-
to-start memory processes to get the CPU.

Before, going to the Types of CPU Scheduling Algorithms, we are going to learn about the Basic Terminologies
which are to be followed and used in the CPU Scheduling Algorithms by us.

1. Process ID

The Process ID is the first Thing is to be written while solving the problem. The Process ID acts like the name
of the process. It is usually represented with numbers or P letter with numbers

Example:

1. 0, 1, 2, 3, . . . . . . . . . .
2. P0, P1, P2, P3 . . . . . . . .

Usually, we start the naming of the process from zero. We can also start the numbering from number 1 also.
It is our interest

1. Arrival Time

The time which is required for the Process to enter the ready queue or the time when the Process is ready
to be executed by the CPU. This Arrival Time can be represented as AT in short form. The Arrival Times is
always positive or also zero.

2. Burst Time

The Time Slot which the Process requires to complete the Process is known as the Burst Time. The Burst
Time can be represented as BT in short form. The Burst Times of a process is always greater than zero.
UNIT 2: Process Management and Concurrency Control
3. Completion Time

The Total Time required by the CPU to complete the process is known as Completion Time. The Completion
Time can be represented as CT in short form. The Completion will always be greater than zero.

4. Turn Around Time

The time taken by the CPU since the Process has been ready to execute or since the process is in Ready
Queue is known as Turn Around Time. The Turn Around Time can be calculated with the help of Completion
Time and Arrival Time. The Turn Around Time can be represented as TAT in short form.

The Turn Around Time is the difference of Completion Time and Arrival Time.

Formula

1. TAT = CT - AT

Here, CT is Completion Time and AT is Arrival Time.

5. Waiting Time

The time the Process has been waiting to complete its process since the assignment of process for
completion is known as Waiting Time. The Waiting Time can be represented as WT in short form. The Waiting
Time can be calculated with the help of Turn Around Time and Burst Time.

The Waiting Time is the difference between Turn Around Time and Burst Time

Formula

1. WT = TAT - BT

6. Ready Queue

The Queue where all the processes are stored until the execution of the previous process. This ready queue
is very important because there would be confusion in CPU when two same kinds of processes are being
executed at the same time.

Then, in these kinds of conditions the ready queue comes into place and then, the its duty is fulfilled.

7. Gantt Chart

It is the place where all the already executed processes are stored. This is very useful for calculating Waiting
Time, Completion Time, Turn Around Time.

Modes in CPU Scheduling Algorithms

There are two modes in CPU Scheduling Algorithms. They are:

1. Pre-emptive Approach
2. Non Pre-emptive Approach
UNIT 2: Process Management and Concurrency Control
In Pre Emptive-Approach the process once starts its execution then the CPU is allotted to the same process
until the completion of process. There would be no shift of Processes by the Central Processing Unit. The
complete CPU is allocated to the Process and there would be no change of CPU allocation until the process
is complete.

In Non-Pre Emptive-Approach the process once stars its execution, then the CPU is not allotted to the same
process until the completion of process. There is a shift of Processes by the Central Processing Unit. The
complete CPU is allocated to the Process when only certain required conditions are achieved and there will
be change of CPU allocation if there is break or False occurrence in the required conditions.

Types of CPU Scheduling Algorithms

o First Come First Serve


o Shortest Job First
o Priority Scheduling
o Round Robin Scheduling

First Come First Serve Scheduling Algorithm

This is the first type of CPU Scheduling Algorithms. Here, in this CPU Scheduling Algorithm we are going to
learn how CPU is going to allot resources to the certain process.

Here, in the First Come First Serve CPU Scheduling Algorithm, the CPU allots the resources to the process in
a certain order. The order is serial way. The CPU is allotted to the process in which it has occurred.

We can also say that First Come First Serve CPU Scheduling Algorithm follows First In First Out in Ready
Queue.

First Come First Serve can be called as FCFS in short form.

Characteristics of FCFS (First Come First Serve):

o First Come First Serve can follow or can be executed in Pre emptive Approach or Non-Pre emptive
Approach
o The Process which enters the Ready Queue is executed First. So, we say that FCFS follows First in First
Out Approach.
o First Come First Come First Serve is only executed when the Arrival Time (AT) is greater than or equal
to the Time which is at present.

Advantages

o Very easy to perform by the CPU


o Follows FIFO Queue Approach
UNIT 2: Process Management and Concurrency Control
Disadvantages

o First Come First Serve is not very efficient.


o First Come First Serve suffers because of Convoy Effect.

Examples

1. Process ID Process Name Arrival Time Burst Time


2. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _______
3. P 1 A 0 6
4. P 2 B 2 2
5. P 3 C 3 1
6. P 4 D 4 9
7. P 5 E 5 8

Now, we are going to apply FCFS (First Come First Serve) CPU Scheduling Algorithm for the above problem.

In FCFS, there is an exception that Arrival Times are not removed from the Completion Time.

Here, in First Come First Serve the basic formulas do not work. Only the basic formulas work.

Process Arrival Burst Completion Turn Waiting


ID Time Time Time Around Time
Time

P1 0 6 6 6 0

P2 2 2 8 8 6

P3 3 1 9 9 8

P4 4 9 18 18 9

P5 5 8 26 26 18

Gantt Chart

Average Completion Time = The Total Sum of Completion Times which is divided by the total number of
processes is known as Average Completion Time.

Average Completion Time =( CT1 + CT2 + CT3 + . . . . . . . . . . . + CTn ) / n


UNIT 2: Process Management and Concurrency Control
Average Completion Time

1. Average CT = ( 6 + 8 +9 + 18 + 26 ) / 5
2. Average CT = 67 / 5
3. Average CT = 13. 4

Average Turn Around Time = The Total Sum of Turn Around Times which is divided by the total number of
processes is known as Average Turn Around Time.

Average Turn Around Time = (TAT1 + TAT2 + TAT3 + . . . . . . . . . . . + TATn ) / n

Average Turn Around Time

1. Average TAT = ( 6 + 8 + 9 +18 +26 ) / 5


2. Average TAT = 13.4

Average Waiting Time = The Total Sum of Waiting Times which is divided by the total number of processes
is known as Average Waiting Time.

Average Waiting Time = (WT1 + WT2 + WT3 + . . . . . . . . . . . + WTn ) / n

Average Waiting Time

1. Average WT = ( 0 + 6 + 8 + 9 + 18 ) / 5
2. Average WT = 41 / 5
3. Average WT = 8.2

Convoy effect

Examples:

1. S. No ProcessID Process Name Arrival Time Burst Time


2. _ _ _ _ _ _ _ _ _ _______ _______ _______
3. 1 P1 A 1 79
4. 2 P2 B 0 2
5. 3 P3 C 1 3
6. 4 P4 D 0 1
7. 5 P5 E 2 25
UNIT 2: Process Management and Concurrency Control
S. Process Process Arrival Burst Completion Turn Waiting Response
No Id Name Time ( Time ( Time ( CT ) Around Time ( Time ( RT
AT ) BT ) Time ( WT ) )
TAT )

1 P1 A 1 79 79 78 0 0

2 P2 B 0 2 81 81 79 79

3 P3 C 1 3 84 83 81 81

4 P4 D 0 1 85 85 84 84

5 P5 E 2 25 110 108 85 85

6 P6 F 3 3 113 110 110 110

The Average Completion Time is:

Average CT = ( 79 + 81 + 84 + 85 + 110 + 113 ) / 6

Average CT = 92

The Average Waiting Time is:

Average WT = ( 0 + 79 + 81 + 84 + 85 + 110 ) /6

Average WT = 73.1666667

The Average Turn Around Time is:

Average TAT = ( 78 + 81 + 83 + 85 + 108 +110 ) / 6

Average TAT = 90.833334

The biggest problem in this is higher Completion Time, higher Waiting Time, higher Turn Around Time, lower
efficiency.

The problem which we found in the above solution can be resolved by using a new CPU Scheduling
Techniques named Shortest Job First (SJF).

Shortest Job First CPU Scheduling Algorithm

This is another type of CPU Scheduling Algorithms. Here, in this CPU Scheduling Algorithm we are going to
learn how CPU is going to allot resources to the certain process.

The Shortest Job is heavily dependent on the Burst Times. Every CPU Scheduling Algorithm is basically
dependent on the Arrival Times. Here, in this Shortest Job First CPU Scheduling Algorithm, the CPU allots its
resources to the process which is in ready queue and the process which has least Burst Time.
UNIT 2: Process Management and Concurrency Control
If we face a condition where two processes are present in the Ready Queue and their Burst Times are same,
we can choose any process for execution. In actual Operating Systems, if we face the same problem then
sequential allocation of resources takes place.

Shortest Job First can be called as SJF in short form.

Characteristics:

o SJF (Shortest Job First) has the least average waiting time. This is because all the heavy processes are
executed at the last. So, because of this reason all the very small, small processes are executed first
and prevent starvation of small processes.
o It is used as a measure of time to do each activity.
o If shorter processes continue to be produced, hunger might result. The idea of aging can be used to
overcome this issue.
o Shortest Job can be executed in Pre emptive and also non pre emptive way also.

Advantages

o SJF is used because it has the least average waiting time than the other CPU Scheduling Algorithms
o SJF can be termed or can be called as long term CPU scheduling algorithm.

Disadvantages

o Starvation is one of the negative traits Shortest Job First CPU Scheduling Algorithm exhibits.
o Often, it becomes difficult to forecast how long the next CPU request will take

Examples for Shortest Job First

1. Process ID Arrival Time Burst Time


2. _ _ _ _ _ _ _______ _______
3. P0 1 3
4. P1 2 6
5. P2 1 2
6. P3 3 7
7. P4 2 4
8. P5 5 5

Now, we are going to solve this problem in both pre emptive and non pre emptive way

We will first solve the problem in non pre emptive way.

In Non pre emptive way, the process is executed until it is completed.


UNIT 2: Process Management and Concurrency Control
Non Pre Emptive Shortest Job First CPU Scheduling

Process Arrival Burst Completion Turn Waiting


ID Time Time Time Around Time WT
Time TAT = CT - BT
= CT - AT

P0 1 3 5 4 1

P1 2 6 20 18 12

P2 0 2 2 2 0

P3 3 7 27 24 17

P4 2 4 9 7 4

P5 5 5 14 10 5

Gantt Chart:

Now let us find out Average Completion Time, Average Turn Around Time, Average Waiting Time.

Average Completion Time:

1. Average Completion Time = ( 5 + 20 + 2 + 27 + 9 + 14 ) / 6


2. Average Completion Time = 77/6
3. Average Completion Time = 12.833

Average Waiting Time:

1. Average Waiting Time = ( 1 + 12 + 17 + 0 + 5 + 4 ) / 6


2. Average Waiting Time = 37 / 6
3. Average Waiting Time = 6.666

Average Turn Around Time:

1. Average Turn Around Time = ( 4 +18 + 2 +24 + 7 + 10 ) / 6


2. Average Turn Around Time = 65 / 6
3. Average Turn Around Time = 6.166
UNIT 2: Process Management and Concurrency Control
Pre Emptive Approach

In Pre emptive way, the process is executed when the best possible solution is found.

Process Arrival Burst Completion Turn Waiting


ID Time Time Time Around Time WT
Time TAT = CT - BT
= CT - AT

P0 1 3 5 4 1

P1 2 6 17 15 9

P2 0 2 2 2 0

P3 3 7 24 21 14

P4 2 4 11 9 5

P5 6 2 8 2 0

Gantt chart:

After P4 P5 is executed just because of the Pre Emptive Condition.

Now let us find out Average Completion Time, Average Turn Around Time, Average Waiting Time.

Average Completion Time

1. Average Completion Time = ( 5 + 17 + 2 + 24 + 11 +8 ) / 6


2. Average Completion Time = 67 / 6
3. Average Completion = 11.166

Average Turn Around Time

1. Average Turn Around Time = ( 4 +15 + 2 + 21 + 9 + 2 ) / 6


2. Average Turn Around Time = 53 / 6
3. Average Turn Around Time = 8.833

Average Waiting Time

1. Average Waiting Time = ( 1 + 9 + 0 + 14 + 5 + 0 ) /6


2. Average Waiting Time = 29 / 6
3. Average Waiting Time = 4.833
UNIT 2: Process Management and Concurrency Control
Priority CPU Scheduling

This is another type of CPU Scheduling Algorithms. Here, in this CPU Scheduling Algorithm we are going to
learn how CPU is going to allot resources to the certain process.

The Priority CPU Scheduling is different from the remaining CPU Scheduling Algorithms. Here, each and every
process has a certain Priority number.

There are two types of Priority Values.

o Highest Number is considered as Highest Priority Value


o Lowest Number is considered as Lowest Priority Value

Priority for Prevention The priority of a process determines how the CPU Scheduling Algorithm operates,
which is a preemptive strategy. Since the editor has assigned equal importance to each function in this
method, the most crucial steps must come first. The most significant CPU planning algorithm relies on the
FCFS (First Come First Serve) approach when there is a conflict, that is, when there are many processors with
equal value.

Characteristics

o Priority CPU scheduling organizes tasks according to importance.


o When a task with a lower priority is being performed while a task with a higher priority arrives, the
task with the lower priority is replaced by the task with the higher priority, and the latter is stopped
until the execution is finished.
o A process's priority level rises as the allocated number decreases.

Advantages

o The typical or average waiting time for Priority CPU Scheduling is shorter than First Come First Serve
(FCFS).
o It is easier to handle Priority CPU scheduling
o It is less complex

Disadvantages

o The Starvation Problem is one of the Pre emptive Priority CPU Scheduling Algorithm's most prevalent
flaws. Because of this issue, a process must wait a longer period of time to be scheduled into the
CPU. The hunger problem or the starvation problem is the name given to this issue.

Examples:

Now, let us explain this problem with the help of an example of Priority Scheduling

1. S. No Process ID Arrival Time Burst Time Priority


2. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
UNIT 2: Process Management and Concurrency Control
3. 1 P1 0 5 5
4. 2 P2 1 6 4
5. 3 P3 2 2 0
6. 4 P4 3 1 2
7. 5 P5 4 7 1
8. 6 P6 4 6 3

Here, in this problem the priority number with highest number is least prioritized.

This means 5 has the least priority and 0 has the highest priority.

Solution:

S. Process Arrival Burst Priority Completion Waiting


No Id Time Time Time Turn Time WT
Around Time = TAT -
TAT = CT - AT BT

1 PP 1 P0 P5 P5 P5 P5 P0

2 PP 2 P1 P6 P4 P27 P26 P20

3 PP 3 P2 P2 P0 P7 P5 P3

4 PP 4 P3 P1 P2 P15 P12 P11

5 PP 5 P4 P7 P1 P14 P10 P3

6 P6 P4 P6 P3 P21 P17 P11

Gantt Chart:

Average Completion Time

1. Average Completion Time = ( 5 +27 +7 +15 +14 + 21 ) / 6


2. Average Completion Time = 89 / 6
3. Average Completion Time = 14.8333

Average Waiting Time

1. Average Waiting Time = ( 0 + 20 + 3 + 11 + 3 + 11 ) / 6


2. Average Waiting Time = 48 / 6
3. Average Waiting Time = 7
UNIT 2: Process Management and Concurrency Control
Average Turn Around Time

1. Average Turn Around Time = ( 5 + 26 + 5 + 11 + 10 + 17 ) / 6


2. Average Turn Around Time = 74 / 6
3. Average Turn Around Time = 12.333

Round Robin CPU Scheduling

Round Robin is a CPU scheduling mechanism those cycles around assigning each task a specific time slot. It
is the First come, First served CPU Scheduling technique with preemptive mode. The Round Robin CPU
algorithm frequently emphasizes the Time-Sharing method.

Round Robin CPU Scheduling Algorithm characteristics include:

o Because all processes receive a balanced CPU allocation, it is straightforward, simple to use, and
starvation-free.
o One of the most used techniques for CPU core scheduling. Because the processes are only allowed
access to the CPU for a brief period of time, it is seen as preemptive.

The benefits of round robin CPU Scheduling:

o Every process receives an equal amount of CPU time, therefore round robin appears to be equitable.
o To the end of the ready queue is added the newly formed process.

Examples:

Problem

Process ID Arrival Time Burst Time

P0 1 3

P1 0 5

P2 3 2

P3 4 3

P4 2 1

Solution:

Process Arrival Burst Completion Turn Waiting


ID Time Time Time Around Time
Time
UNIT 2: Process Management and Concurrency Control
P0 1 3 5 4 1

P1 0 5 14 14 9

P2 3 2 7 4 2

P3 4 3 10 6 3

P4 2 1 3 1 0

Gantt Chart:

Average Completion Time = 7.8

Average Turn Around Time = 4.8

Average Waiting Time = 3

This is all about the CPU Scheduling Algorithms in Operating System.

Difference between Preemptive and Non-Preemptive Scheduling

In this article, you will learn the difference between preemptive and non-preemptive scheduling. But before
discussing the differences, you need to know about preemptive and non-preemptive scheduling.

What is Preemptive Scheduling?

Preemptive scheduling is a method that may be used when a process switches from a running state to a
ready state or from a waiting state to a ready state. The resources are assigned to the process for a particular
time and then removed. If the resources still have the remaining CPU burst time, the process is placed back
in the ready queue. The process remains in the ready queue until it is given a chance to execute again.

When a high-priority process comes in the ready queue, it doesn't have to wait for the running process to
finish its burst time. However, the running process is interrupted in the middle of its execution and placed
in the ready queue until the high-priority process uses the resources. As a result, each process gets some
CPU time in the ready queue. It improves the overhead of switching a process from running to ready state
and vice versa, increasing preemptive scheduling flexibility. It may or may not include SJF and Priority
scheduling.

For example:

Let us take the example of Preemptive Scheduling. We have taken P0, P1, P2, and P3 are the four processes.

Process Arrival Time CPU Burst time (in millisec.)


UNIT 2: Process Management and Concurrency Control
P0 3 2

P1 2 4

P2 0 6

P3 1 4

o Firstly, the process P2 comes at time 0. So, the CPU is assigned to process P2.
o When process P2 was running, process P3 arrived at time 1, and the remaining time for process P2
(5 ms) is greater than the time needed by process P3 (4 ms). So, the processor is assigned to P3.
o When process P3 was running, process P1 came at time 2, and the remaining time for process P3 (3
ms) is less than the time needed by processes P1 (4 ms) and P2 (5 ms). As a result, P3 continues the
execution.
o When process P3 continues the process, process P0 arrives at time 3. P3's remaining time (2 ms) is
equal to P0's necessary time (2 ms). So, process P3 continues the execution.
o When process P3 finishes, the CPU is assigned to P0, which has a shorter burst time than the other
processes.
o After process P0 completes, the CPU is assigned to process P1 and then to process P2.

Advantages and disadvantages of Preemptive Scheduling

There are various advantages and disadvantages of Preemptive scheduling. The advantages and
disadvantages of non-preemptive scheduling are as follows:

Advantages

1. It is a more robust method because a process may not monopolize the processor.
2. Each event causes an interruption in the execution of ongoing tasks.
3. It improves the average response time.
4. It is more beneficial when you use this method in a multi-programming environment.
5. The operating system ensures that all running processes use the same amount of CPU.
UNIT 2: Process Management and Concurrency Control
Disadvantages

1. It requires the use of limited computational resources.


2. It takes more time suspending the executing process, switching the context, and dispatching the new
incoming process.
3. If several high-priority processes arrive at the same time, the low-priority process would have to wait
longer.

What is Non-Preemptive Scheduling?

Non-preemptive scheduling is a method that may be used when a process terminates or switches from a
running to a waiting state. When processors are assigned to a process, they keep the process until it is
eliminated or reaches a waiting state. When the processor starts the process execution, it must complete it
before executing the other process, and it may not be interrupted in the middle.

When a non-preemptive process with a high CPU burst time is running, the other process would have to wait
for a long time, and that increases the process average waiting time in the ready queue. However, there is
no overhead in transferring processes from the ready queue to the CPU under non-preemptive scheduling.
The scheduling is strict because the execution process is not even preempted for a higher priority process.

For example:

Let's take the above preemptive scheduling example and solve it in a non-preemptive manner.

o The process P2 comes at 0, so the processor is assigned to process P2 and takes (6 ms) to execute.
o All of the processes, P0, P1, and P3, arrive in the ready queue in between. But all processes wait till
process P2 finishes its CPU burst time.
o After that, the process that comes after process P2, i.e., P3, is assigned to the CPU until it finishes its
burst time.
o When process P1 completes its execution, the CPU is given to process P0.

Advantages and disadvantages of Non-preemptive Scheduling

There are various advantages and disadvantages of non-preemptive scheduling. The advantages and
disadvantages of non-preemptive scheduling are as follows:
UNIT 2: Process Management and Concurrency Control
Advantages

1. It provides a low scheduling overhead.


2. It is a very simple method.
3. It uses less computational resources.
4. It offers high throughput.

Disadvantages

1. It has a poor response time for the process.


2. A machine can freeze up due to bugs.

Main Differences between the Preemptive and Non-Preemptive Scheduling

Here, you will learn the main differences between Preemptive and Non-Preemptive Scheduling. Various
differences between the Preemptive and Non-Preemptive Scheduling are as follows:

1. In preemptive scheduling, the CPU is assigned to the processes for a particular time period. In
contrast, the CPU is assigned to the process until it removes and switches to the waiting state.
2. When a process with a high priority appears in the ready queue frequently in preemptive scheduling,
the process with a low priority must wait for a long period and can starve. In contrast, when the CPU
is assigned to the process with the high burst time, the processes with the shorter burst time can
starve in non-preemptive scheduling.
3. When a higher priority process comes in the CPU, the running process in preemptive scheduling is
halted in the middle of its execution. On the other hand, the running process in non-preemptive
scheduling doesn't interrupt in the middle of its execution and waits until it is completed.
4. Preemptive scheduling is flexible in processing. On the other side, non-preemptive is strict.
5. Preemptive scheduling is quite flexible because critical processes are allowed to access the CPU
because they come in the ready queue and no matter which process is currently running. Non-
UNIT 2: Process Management and Concurrency Control
preemptive scheduling is tough because if an essential process is assigned to the ready queue, the
CPU process is not be interrupted.
6. In preemptive scheduling, CPU utilization is more effective than non-preemptive scheduling. On the
other side, in non-preemptive scheduling, the CPU utilization is not effective as preemptive
scheduling.
7. Preemptive scheduling is very cost-effective because it ensures the integrity of shared data. In
contrast, it is not in the situation of non-preemptive scheduling.

Head-to-head Comparison between the Preemptive and Non-Preemptive Scheduling

Here, you will learn the head-to-head comparison between preemptive and non-preemptive scheduling. The
main differences between preemptive and non-preemptive scheduling are as follows:

Preemptive Scheduling Non-Preemptive Scheduling

The resources are assigned to a process for Once resources are assigned to a process, they are held until
a long time period. it completes its burst period or changes to the waiting state.

Its process may be paused in the middle of When the processor starts the process execution, it must
the execution. complete it before executing the other process, and it may
not be interrupted in the middle.

When a high-priority process continuously When a high burst time process uses a CPU, another process
comes in the ready queue, a low-priority with a shorter burst time can starve.
process can starve.

It is flexible. It is rigid.

It is cost associated. It does not cost associated.

It has overheads associated with process It doesn't have overhead.


scheduling.

It affects the design of the operating system It doesn't affect the design of the OS kernel.
kernel.

Its CPU utilization is very high. Its CPU utilization is very low.

Examples: Round Robin and Shortest FCFS and SJF are examples of non-preemptive scheduling.
Remaining Time First
UNIT 2: Process Management and Concurrency Control
1. Shortest Job First (SJF):
Description: SJF scheduling algorithm selects the process with the shortest burst time first.
Criteria:It minimizes the total processing time and improves system throughput.
Advantages:
- Provides optimal average waiting time for processes.
- Efficient for minimizing turnaround time.
Disadvantages:
- Difficult to predict the exact burst time, especially for long-term predictions.
- It may lead to a situation known as "starvation" for longer processes.
2. Round Robin (RR):
Description: RR is a pre-emptive scheduling algorithm where each process is assigned a fixed time slot or
quantum, and they are scheduled in a circular order.
Criteria: Fairness and prevention of starvation.
Advantages:
- Fair distribution of CPU time among all processes.
- Simple and easy to understand.
Disadvantages:
- May have higher turnaround time compared to SJF for certain scenarios.
- The choice of time quantum is crucial; too short may lead to high context-switching overhead, while
too long may reduce responsiveness.
3. Priority Scheduling:
Description: Priority scheduling assigns priority levels to processes, and the process with the highest
priority is scheduled first.
Criteria: Priority can be based on factors like burst time, waiting time, or any other relevant parameter.
Advantages:
- Allows for the execution of high-priority tasks first.
- Can be customized to reflect the importance of different processes.
Disadvantages:
- May result in starvation for lower-priority processes.
- If not managed properly, high-priority processes can monopolize the CPU, leading to a lack of fairness.
UNIT 2: Process Management and Concurrency Control
Thread Scheduling
Each scheduling algorithm has its strengths and weaknesses, and the choice of which to use depends on
the specific requirements and characteristics of the system. Some operating systems also use a
combination of these algorithms to achieve a balance between fairness, efficiency, and responsiveness.
There is a component in Java that basically decides which thread should execute or get a resource in the
operating system.
Scheduling of threads involves two boundary scheduling.
1. Scheduling of user-level threads (ULT) to kernel-level threads (KLT) via lightweight process (LWP) by
the application developer.
2. Scheduling of kernel-level threads by the system scheduler to perform different unique OS
functions.
Lightweight Process (LWP)
Light-weight process are threads in the user space that acts as an interface for the ULT to access the
physical CPU resources. Thread library schedules which thread of a process to run on which LWP and how
long. The number of LWPs created by the thread library depends on the type of application. In the case of
an I/O bound application, the number of LWPs depends on the number of user-level threads. This is
because when an LWP is blocked on an I/O operation, then to invoke the other ULT the thread library
needs to create and schedule another LWP. Thus, in an I/O bound application, the number of LWP is equal
to the number of the ULT. In the case of a CPU-bound application, it depends only on the application. Each
LWP is attached to a separate kernel-level thread.
UNIT 2: Process Management and Concurrency Control
In real-time, the first boundary of thread scheduling is beyond specifying the scheduling policy and the
priority. It requires two controls to be specified for the User level threads: Contention scope, and
Allocation domain. These are explained as following below.
Contention Scope
The word contention here refers to the competition or fight among the User level threads to access the
kernel resources. Thus, this control defines the extent to which contention takes place. It is defined by the
application developer using the thread library.
Depending upon the extent of contention it is classified as-
 Process Contention Scope (PCS) :
The contention takes place among threads within a same process. The thread library schedules the
high-prioritized PCS thread to access the resources via available LWPs (priority as specified by the
application developer during thread creation).
 System Contention Scope (SCS) :
The contention takes place among all threads in the system. In this case, every SCS thread is
associated to each LWP by the thread library and are scheduled by the system scheduler to access
the kernel resources.
In LINUX and UNIX operating systems, the POSIX Pthread library provides a
function Pthread_attr_setscope to define the type of contention scope for a thread during its creation.
int Pthread_attr_setscope(pthread_attr_t *attr, int scope)
The first parameter denotes to which thread within the process the scope is defined.
The second parameter defines the scope of contention for the thread pointed. It takes two values.

PTHREAD_SCOPE_SYSTEM
PTHREAD_SCOPE_PROCESS
If the scope value specified is not supported by the system, then the function returns ENOTSUP.
Allocation Domain
The allocation domain is a set of one or more resources for which a thread is competing. In a multicore
system, there may be one or more allocation domains where each consists of one or more cores. One ULT
can be a part of one or more allocation domain. Due to this high complexity in dealing with hardware and
software architectural interfaces, this control is not specified. But by default, the multicore system will
have an interface that affects the allocation domain of a thread.
Consider a scenario, an operating system with three process P1, P2, P3 and 10 user level threads (T1 to
T10) with a single allocation domain. 100% of CPU resources will be distributed among all the three
processes. The amount of CPU resources allocated to each process and to each thread depends on the
contention scope, scheduling policy and priority of each thread defined by the application developer using
thread library and also depends on the system scheduler. These User level threads are of a different
contention scope.
UNIT 2: Process Management and Concurrency Control

In this case, the contention for allocation domain takes place as follows:
Process P1
All PCS threads T1, T2, T3 of Process P1 will compete among themselves. The PCS threads of the same
process can share one or more LWP. T1 and T2 share an LWP and T3 are allocated to a separate LWP.
Between T1 and T2 allocation of kernel resources via LWP is based on preemptive priority scheduling by
the thread library. A Thread with a high priority will preempt low priority threads. Whereas, thread T1 of
process p1 cannot preempt thread T3 of process p3 even if the priority of T1 is greater than the priority of
T3. If the priority is equal, then the allocation of ULT to available LWPs is based on the scheduling policy of
threads by the system scheduler(not by thread library, in this case).

Process P2
Both SCS threads T4 and T5 of process P2 will compete with processes P1 as a whole and with SCS threads
T8, T9, T10 of process P3. The system scheduler will schedule the kernel resources among P1, T4, T5, T8,
UNIT 2: Process Management and Concurrency Control
T9, T10, and PCS threads (T6, T7) of process P3 considering each as a separate process. Here, the Thread
library has no control of scheduling the ULT to the kernel resources.

Process P3
Combination of PCS and SCS threads. Consider if the system scheduler allocates 50% of CPU resources to
process P3, then 25% of resources is for process scoped threads and the remaining 25% for system scoped
threads. The PCS threads T6 and T7 will be allocated to access the 25% resources based on the priority by
the thread library. The SCS threads T8, T9, T10 will divide the 25% resources among themselves and access
the kernel resources via separate LWP and KLT. The SCS scheduling is by the system scheduler.

Note:
For every system call to access the kernel resources, a Kernel Level thread is created
and associated to separate LWP by the system scheduler.
Number of Kernel Level Threads = Total Number of LWP
Total Number of LWP = Number of LWP for SCS + Number of LWP for PCS
Number of LWP for SCS = Number of SCS threads
Number of LWP for PCS = Depends on application developer
Here,
Number of SCS threads = 5
Number of LWP for PCS = 3
Number of SCS threads = 5
Number of LWP for SCS = 5
Total Number of LWP = 8 (=5+3)
Number of Kernel Level Threads = 8
Advantages of PCS over SCS
 If all threads are PCS, then context switching, synchronization, scheduling everything takes place
within the userspace. This reduces system calls and achieves better performance.
 PCS is cheaper than SCS.
 PCS threads share one or more available LWPs. For every SCS thread, a separate LWP is
associated.For every system call, a separate KLT is created.
 The number of KLT and LWPs created highly depends on the number of SCS threads created. This
increases the kernel complexity of handling scheduling and synchronization. Thereby, results in a
limitation over SCS thread creation, stating that, the number of SCS threads to be smaller than the
number of PCS threads.
UNIT 2: Process Management and Concurrency Control
 If the system has more than one allocation domain, then scheduling and synchronization of
resources becomes more tedious. Issues arise when an SCS thread is a part of more than one
allocation domain, the system has to handle n number of interfaces.
The second boundary of thread scheduling involves CPU scheduling by the system scheduler. The scheduler
considers each kernel-level thread as a separate process and provides access to the kernel resources.
Scheduling in Real Time Systems
Real-time systems are systems that carry real-time tasks. These tasks need to be performed immediately
with a certain degree of urgency. In particular, these tasks are related to control of certain events (or)
reacting to them. Real-time tasks can be classified as hard real-time tasks and soft real-time tasks.
A hard real-time task must be performed at a specified time which could otherwise lead to huge losses. In
soft real-time tasks, a specified deadline can be missed. This is because the task can be rescheduled (or)
can be completed after the specified time,
In real-time systems, the scheduler is considered as the most important component which is typically a
short-term task scheduler. The main focus of this scheduler is to reduce the response time associated with
each of the associated processes instead of handling the deadline.
If a preemptive scheduler is used, the real-time task needs to wait until its corresponding tasks time slice
completes. In the case of a non-preemptive scheduler, even if the highest priority is allocated to the task, it
needs to wait until the completion of the current task. This task can be slow (or) of the lower priority and
can lead to a longer wait.
A better approach is designed by combining both preemptive and non-preemptive scheduling. This can be
done by introducing time-based interrupts in priority based systems which means the currently running
process is interrupted on a time-based interval and if a higher priority process is present in a ready queue,
it is executed by preempting the current process.
Based on schedulability, implementation (static or dynamic), and the result (self or dependent) of analysis,
the scheduling algorithm are classified as follows.

1. Static table-driven approaches:


These algorithms usually perform a static analysis associated with scheduling and capture the
schedules that are advantageous. This helps in providing a schedule that can point out a task with
which the execution must be started at run time.

2. Static priority-driven preemptive approaches:


Similar to the first approach, these type of algorithms also uses static analysis of scheduling. The
difference is that instead of selecting a particular schedule, it provides a useful way of assigning
priorities among various tasks in preemptive scheduling.

3. Dynamic planning-based approaches:


Here, the feasible schedules are identified dynamically (at run time). It carries a certain fixed time
interval and a process is executed if and only if satisfies the time constraint.
UNIT 2: Process Management and Concurrency Control
4. Dynamic best effort approaches:
These types of approaches consider deadlines instead of feasible schedules. Therefore the task is
aborted if its deadline is reached. This approach is used widely is most of the real-time systems.

Advantages of Scheduling in Real-Time Systems:


 Meeting Timing Constraints: Scheduling ensures that real-time tasks are executed within their
specified timing constraints. It guarantees that critical tasks are completed on time, preventing
potential system failures or losses.
 Resource Optimization: Scheduling algorithms allocate system resources effectively, ensuring
efficient utilization of processor time, memory, and other resources. This helps maximize system
throughput and performance.
 Priority-Based Execution: Scheduling allows for priority-based execution, where higher-priority
tasks are given precedence over lower-priority tasks. This ensures that time-critical tasks are
promptly executed, leading to improved system responsiveness and reliability.
 Predictability and Determinism: Real-time scheduling provides predictability and determinism in
task execution. It enables developers to analyze and guarantee the worst-case execution time and
response time of tasks, ensuring that critical deadlines are met.
 Control Over Task Execution: Scheduling algorithms allow developers to have fine-grained control
over how tasks are executed, such as specifying task priorities, deadlines, and inter-task
dependencies. This control facilitates the design and implementation of complex real-time systems.
Disadvantages of Scheduling in Real-Time Systems:
 Increased Complexity: Real-time scheduling introduces additional complexity to system design and
implementation. Developers need to carefully analyze task requirements, define priorities, and
select suitable scheduling algorithms. This complexity can lead to increased development time and
effort.
 Overhead: Scheduling introduces some overhead in terms of context switching, task prioritization,
and scheduling decisions. This overhead can impact system performance, especially in cases where
frequent context switches or complex scheduling algorithms are employed.
 Limited Resources: Real-time systems often operate under resource-constrained environments.
Scheduling tasks within these limitations can be challenging, as the available resources may not be
sufficient to meet all timing constraints or execute all tasks simultaneously.
 Verification and Validation: Validating the correctness of real-time schedules and ensuring that all
tasks meet their deadlines require rigorous testing and verification techniques. Verifying timing
constraints and guaranteeing the absence of timing errors can be a complex and time-consuming
process.
 Scalability: Scheduling algorithms that work well for smaller systems may not scale effectively to
larger, more complex real-time systems. As the number of tasks and system complexity increases,
scheduling decisions become more challenging and may require more advanced algorithms or
approaches.
UNIT 2: Process Management and Concurrency Control
Inter Process Communication (IPC)
A process can be of two types:
 Independent process.
 Co-operating process.
An independent process is not affected by the execution of other processes while a co-operating process
can be affected by other executing processes. Though one can think that those processes, which are
running independently, will execute very efficiently, in reality, there are many situations when co-
operative nature can be utilized for increasing computational speed, convenience, and modularity. Inter-
process communication (IPC) is a mechanism that allows processes to communicate with each other and
synchronize their actions. The communication between these processes can be seen as a method of co-
operation between them. Processes can communicate with each other through both:

1. Shared Memory
2. Message passing
Figure 1 below shows a basic structure of communication between processes via the shared memory
method and via the message passing method.

An operating system can implement both methods of communication. First, we will discuss the shared
memory methods of communication and then message passing. Communication between processes using
shared memory requires processes to share some variable, and it completely depends on how the
programmer will implement it. One way of communication using shared memory can be imagined like this:
Suppose process1 and process2 are executing simultaneously, and they share some resources or use some
information from another process. Process1 generates information about certain computations or
resources being used and keeps it as a record in shared memory. When process2 needs to use the shared
information, it will check in the record stored in shared memory and take note of the information
generated by process1 and act accordingly. Processes can use shared memory for extracting information as
a record from another process as well as for delivering any specific information to other processes.
Let’s discuss an example of communication between processes using the shared memory method.
UNIT 2: Process Management and Concurrency Control

i) Shared Memory Method


Ex: Producer-Consumer problem
There are two processes: Producer and Consumer. The producer produces some items and the Consumer
consumes that item. The two processes share a common space or memory location known as a buffer
where the item produced by the Producer is stored and from which the Consumer consumes the item if
needed. There are two versions of this problem: the first one is known as the unbounded buffer problem in
which the Producer can keep on producing items and there is no limit on the size of the buffer, the second
one is known as the bounded buffer problem in which the Producer can produce up to a certain number of
items before it starts waiting for Consumer to consume it. We will discuss the bounded buffer problem.
First, the Producer and the Consumer will share some common memory, then the producer will start
producing items. If the total produced item is equal to the size of the buffer, the producer will wait to get it
consumed by the Consumer. Similarly, the consumer will first check for the availability of the item. If no
item is available, the Consumer will wait for the Producer to produce it. If there are items available,
Consumer will consume them. The pseudo-code to demonstrate is provided below:
Shared Data between the two Processes
 C
UNIT 2: Process Management and Concurrency Control
#define buff_max 25
#define mod %

struct item{

// different member of the produced data


// or consumed data
---------
}

// An array is needed for holding the items.


// This is the shared place which will be
// access by both process
// item shared_buff [ buff_max ];

// Two variables which will keep track of


// the indexes of the items produced by producer
// and consumer The free index points to
// the next free index. The full index points to
// the first full index.
int free_index = 0;
int full_index = 0;

Producer Process Code


 C
UNIT 2: Process Management and Concurrency Control
item nextProduced;

while(1){

// check if there is no space


// for production.
// if so keep waiting.
while((free_index+1) mod buff_max == full_index);

shared_buff[free_index] = nextProduced;
free_index = (free_index + 1) mod buff_max;
}

Consumer Process Code


 C

item nextConsumed;

while(1){

// check if there is an available


// item for consumption.
// if not keep on waiting for
// get them produced.
while((free_index == full_index);

nextConsumed = shared_buff[full_index];
full_index = (full_index + 1) mod buff_max;
}

In the above code, the Producer will start producing again when the (free_index+1) mod buff max will be
free because if it is not free, this implies that there are still items that can be consumed by the Consumer
UNIT 2: Process Management and Concurrency Control
so there is no need to produce more. Similarly, if free index and full index point to the same index, this
implies that there are no items to consume.
Overall C++ Implementation:
 C++

#include <iostream>
#include <mutex>
#include <thread>
#include <vector>

#define buff_max 25
#define mod %

struct item {
// different member of the produced data
// or consumed data
// ---------
};

// An array is needed for holding the items.


// This is the shared place which will be
// access by both process
// item shared_buff[buff_max];

// Two variables which will keep track of


// the indexes of the items produced by producer
// and consumer The free index points to
// the next free index. The full index points to
// the first full index.
std::atomic<int> free_index(0);
std::atomic<int> full_index(0);
UNIT 2: Process Management and Concurrency Control
std::mutex mtx;

void producer() {
item new_item;
while (true) {
// Produce the item
// ...
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Add the item to the buffer
while (((free_index + 1) mod buff_max) == full_index) {
// Buffer is full, wait for consumer
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
mtx.lock();
// Add the item to the buffer
// shared_buff[free_index] = new_item;
free_index = (free_index + 1) mod buff_max;
mtx.unlock();
}
}

void consumer() {
item consumed_item;
while (true) {
while (free_index == full_index) {
// Buffer is empty, wait for producer
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
mtx.lock();
// Consume the item from the buffer
UNIT 2: Process Management and Concurrency Control
// consumed_item = shared_buff[full_index];
full_index = (full_index + 1) mod buff_max;
mtx.unlock();
// Consume the item
// ...
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}

int main() {
// Create producer and consumer threads
std::vector<std::thread> threads;
threads.emplace_back(producer);
threads.emplace_back(consumer);

// Wait for threads to finish


for (auto& thread : threads) {
thread.join();
}

return 0;
}

Note that the atomic class is used to make sure that the shared variables free_index and full_index are
updated atomically. The mutex is used to protect the critical section where the shared buffer is accessed.
The sleep_for function is used to simulate the production and consumption of items.
ii) Messaging Passing Method
Now, We will start our discussion of the communication between processes via message passing. In this
method, processes communicate with each other without using any kind of shared memory. If two
processes p1 and p2 want to communicate with each other, they proceed as follows:

 Establish a communication link (if a link already exists, no need to establish it again.)
 Start exchanging messages using basic primitives.
We need at least two primitives:
UNIT 2: Process Management and Concurrency Control
– send(message, destination) or send(message)
– receive(message, host) or receive(message)

The message size can be of fixed size or of variable size. If it is of fixed size, it is easy for an OS designer but
complicated for a programmer and if it is of variable size then it is easy for a programmer but complicated
for the OS designer. A standard message can have two parts: header and body.
The header part is used for storing message type, destination id, source id, message length, and control
information. The control information contains information like what to do if runs out of buffer space,
sequence number, priority. Generally, message is sent using FIFO style.

Message Passing through Communication Link.


Direct and Indirect Communication link
Now, We will start our discussion about the methods of implementing communication links. While
implementing the link, there are some questions that need to be kept in mind like :

1. How are links established?


2. Can a link be associated with more than two processes?
3. How many links can there be between every pair of communicating processes?
4. What is the capacity of a link? Is the size of a message that the link can accommodate fixed or
variable?
5. Is a link unidirectional or bi-directional?
A link has some capacity that determines the number of messages that can reside in it temporarily for
which every link has a queue associated with it which can be of zero capacity, bounded capacity, or
unbounded capacity. In zero capacity, the sender waits until the receiver informs the sender that it has
received the message. In non-zero capacity cases, a process does not know whether a message has been
received or not after the send operation. For this, the sender must communicate with the receiver
explicitly. Implementation of the link depends on the situation, it can be either a direct communication link
or an in-directed communication link.
UNIT 2: Process Management and Concurrency Control
Direct Communication links are implemented when the processes use a specific process identifier for the
communication, but it is hard to identify the sender ahead of time.
For example the print server.
In-direct Communication is done via a shared mailbox (port), which consists of a queue of messages. The
sender keeps the message in mailbox and the receiver picks them up.

Message Passing through Exchanging the Messages.


Synchronous and Asynchronous Message Passing:
A process that is blocked is one that is waiting for some event, such as a resource becoming available or
the completion of an I/O operation. IPC is possible between the processes on same computer as well as on
the processes running on different computer i.e. in networked/distributed system. In both cases, the
process may or may not be blocked while sending a message or attempting to receive a message so
message passing may be blocking or non-blocking. Blocking is considered synchronous and blocking
send means the sender will be blocked until the message is received by receiver. Similarly, blocking
receive has the receiver block until a message is available. Non-blocking is considered asynchronous and
Non-blocking send has the sender sends the message and continue. Similarly, Non-blocking receive has the
receiver receive a valid message or null. After a careful analysis, we can come to a conclusion that for a
sender it is more natural to be non-blocking after message passing as there may be a need to send the
message to different processes. However, the sender expects acknowledgment from the receiver in case
the send fails. Similarly, it is more natural for a receiver to be blocking after issuing the receive as the
information from the received message may be used for further execution. At the same time, if the
message send keep on failing, the receiver will have to wait indefinitely. That is why we also consider the
other possibility of message passing. There are basically three preferred combinations:

 Blocking send and blocking receive


 Non-blocking send and Non-blocking receive
 Non-blocking send and Blocking receive (Mostly used)
In Direct message passing, The process which wants to communicate must explicitly name the recipient or
sender of the communication.
e.g. send(p1, message) means send the message to p1.
Similarly, receive(p2, message) means to receive the message from p2.
In this method of communication, the communication link gets established automatically, which can be
either unidirectional or bidirectional, but one link can be used between one pair of the sender and receiver
and one pair of sender and receiver should not possess more than one pair of links. Symmetry and
asymmetry between sending and receiving can also be implemented i.e. either both processes will name
each other for sending and receiving the messages or only the sender will name the receiver for sending
the message and there is no need for the receiver for naming the sender for receiving the message. The
problem with this method of communication is that if the name of one process changes, this method will
not work.
In Indirect message passing, processes use mailboxes (also referred to as ports) for sending and receiving
messages. Each mailbox has a unique id and processes can communicate only if they share a mailbox. Link
established only if processes share a common mailbox and a single link can be associated with many
processes. Each pair of processes can share several communication links and these links may be
unidirectional or bi-directional. Suppose two processes want to communicate through Indirect message
UNIT 2: Process Management and Concurrency Control
passing, the required operations are: create a mailbox, use this mailbox for sending and receiving
messages, then destroy the mailbox. The standard primitives used are: send(A, message) which means
send the message to mailbox A. The primitive for the receiving the message also works in the same way
e.g. received (A, message). There is a problem with this mailbox implementation. Suppose there are more
than two processes sharing the same mailbox and suppose the process p1 sends a message to the mailbox,
which process will be the receiver? This can be solved by either enforcing that only two processes can
share a single mailbox or enforcing that only one process is allowed to execute the receive at a given time
or select any process randomly and notify the sender about the receiver. A mailbox can be made private to
a single sender/receiver pair and can also be shared between multiple sender/receiver pairs. Port is an
implementation of such mailbox that can have multiple senders and a single receiver. It is used in
client/server applications (in this case the server is the receiver). The port is owned by the receiving
process and created by OS on the request of the receiver process and can be destroyed either on request
of the same receiver processor when the receiver terminates itself. Enforcing that only one process is
allowed to execute the receive can be done using the concept of mutual exclusion. Mutex mailbox is
created which is shared by n process. The sender is non-blocking and sends the message. The first process
which executes the receive will enter in the critical section and all other processes will be blocking and will
wait.
Now, let’s discuss the Producer-Consumer problem using the message passing concept. The producer
places items (inside messages) in the mailbox and the consumer can consume an item when at least one
message present in the mailbox. The code is given below:
Producer Code

 C

void Producer(void){

int item;
Message m;

while(1){

receive(Consumer, &m);
item = produce();
build_message(&m , item ) ;
send(Consumer, &m);
}
}
UNIT 2: Process Management and Concurrency Control
Consumer Code

 C

void Consumer(void){

int item;
Message m;

while(1){

receive(Producer, &m);
item = extracted_item();
send(Producer, &m);
consume_item(item);
}
}

Examples of IPC systems

1. Posix : uses shared memory method.


2. Mach : uses message passing
3. Windows XP : uses message passing using local procedural calls
Communication in client/server Architecture:
There are various mechanism:

 Pipe
 Socket
 Remote Procedural calls (RPCs)
The above three methods will be discussed in later articles as all of them are quite conceptual and deserve
their own separate articles.
References:

1. Operating System Concepts by Galvin et al.


2. Lecture notes/ppt of Ariel J. Frank, Bar-Ilan University
UNIT 2: Process Management and Concurrency Control
Inter-process communication (IPC) is the mechanism through which processes or threads can
communicate and exchange data with each other on a computer or across a network. IPC is an important
aspect of modern operating systems, as it enables different processes to work together and share
resources, leading to increased efficiency and flexibility.
Advantages of IPC:
1. Enables processes to communicate with each other and share resources, leading to increased
efficiency and flexibility.
2. Facilitates coordination between multiple processes, leading to better overall system performance.
3. Allows for the creation of distributed systems that can span multiple computers or networks.
4. Can be used to implement various synchronization and communication protocols, such as
semaphores, pipes, and sockets.
Disadvantages of IPC:
1. Increases system complexity, making it harder to design, implement, and debug.
2. Can introduce security vulnerabilities, as processes may be able to access or modify data belonging
to other processes.
3. Requires careful management of system resources, such as memory and CPU time, to ensure that
IPC operations do not degrade overall system performance.
Can lead to data inconsistencies if multiple processes try to access or modify the same data at the
same time.
4. Overall, the advantages of IPC outweigh the disadvantages, as it is a necessary mechanism for
modern operating systems and enables processes to work together and share resources in a flexible
and efficient manner. However, care must be taken to design and implement IPC systems carefully,
in order to avoid potential security vulnerabilities and performance issues.
Concurrency in Operating System
Concurrency is the execution of multiple instruction sequences at the same time. It happens in the
operating system when there are several process threads running in parallel. The running process threads
always communicate with each other through shared memory or message passing. Concurrency results in
the sharing of resources resulting in problems like deadlocks and resource starvation.
It helps in techniques like coordinating the execution of processes, memory allocation, and execution
scheduling for maximizing throughput.
There are several motivations for allowing concurrent execution
 Physical resource Sharing: Multiuser environment since hardware resources are limited
 Logical resource Sharing: Shared file (same piece of information)
 Computation Speedup: Parallel execution
 Modularity: Divide system functions into separation processes
Relationship Between Processes of Operating System
The Processes executing in the operating system is one of the following two types:
UNIT 2: Process Management and Concurrency Control
 Independent Processes
 Cooperating Processes
Independent Processes
Its state is not shared with any other process.
 The result of execution depends only on the input state.
 The result of the execution will always be the same for the same input.
 The termination of the independent process will not terminate any other.
Cooperating System
Its state is shared along other processes.
 The result of the execution depends on relative execution sequence and cannot be predicted in
advanced(Non-deterministic).
 The result of the execution will not always be the same for the same input.
 The termination of the cooperating process may affect other process.
Process Operation in Operating System
Most systems support at least two types of operations that can be invoked on a process creation and
process deletion.
Process Creation
A parent process and then children of that process can be created. When more than one process is created
several possible implementations exist.
 Parent and child can execute concurrently.
 The Parents waits until all of its children have terminated.
 The parent and children share all resources in common.
 The children share only a subset of their parent’s resources.
 The parent and children share no resources in common.
Process Termination
A child process can be terminated in the following ways:
 A parent may terminate the execution of one of its children for a following reasons:
1. The child has exceeded its allocation resource usage.
2. The task assigned to its child is no longer required.
 If a parent has terminated than its children must be terminated.
UNIT 2: Process Management and Concurrency Control
Principles of Concurrency
Both interleaved and overlapped processes can be viewed as examples of concurrent processes, they both
present the same problems.
The relative speed of execution cannot be predicted. It depends on the following:
 The activities of other processes
 The way operating system handles interrupts
 The scheduling policies of the operating system
Problems in Concurrency
 Sharing global resources: Sharing of global resources safely is difficult. If two processes both make
use of a global variable and both perform read and write on that variable, then the order in which
various read and write are executed is critical.
 Optimal allocation of resources: It is difficult for the operating system to manage the allocation of
resources optimally.
 Locating programming errors: It is very difficult to locate a programming error because reports are
usually not reproducible.
 Locking the channel: It may be inefficient for the operating system to simply lock the channel and
prevents its use by other processes.
Advantages of Concurrency
 Running of multiple applications: It enable to run multiple applications at the same time.
 Better resource utilization: It enables that the resources that are unused by one application can be
used for other applications.
 Better average response time: Without concurrency, each application has to be run to completion
before the next one can be run.
 Better performance: It enables the better performance by the operating system. When one
application uses only the processor and another application uses only the disk drive then the time
to run both applications concurrently to completion will be shorter than the time to run each
application consecutively.
Drawbacks of Concurrency
 It is required to protect multiple applications from one another.
 It is required to coordinate multiple applications through additional mechanisms.
 Additional performance overheads and complexities in operating systems are required for
switching among applications.
 Sometimes running too many applications concurrently leads to severely degraded performance.
Issues of Concurrency
 Non-atomic: Operations that are non-atomic but interruptible by multiple processes can cause
problems.
UNIT 2: Process Management and Concurrency Control
 Race conditions: A race condition occurs of the outcome depends on which of several processes
gets to a point first.
 Blocking: Processes can block waiting for resources. A process could be blocked for long period of
time waiting for input from a terminal. If the process is required to periodically update some data,
this would be very undesirable.
 Starvation: It occurs when a process does not obtain service to progress.
 Deadlock: It occurs when two processes are blocked and hence neither can proceed to execute.
Classical Problems of Synchronization with Semaphore Solution

In this article, we will see a number of classical problems of synchronization as examples of a large class of
concurrency-control problems. In our solutions to the problems, we use semaphores for synchronization,
since that is the traditional way to present such solutions. However, actual implementations of these
solutions could use mutex locks instead of binary semaphores.
Synchronization Problems
These problems are used for testing nearly every newly proposed synchronization scheme. The following
problems of synchronization are considered as classical problems:
1. Bounded-buffer (or Producer-Consumer) Problem,
2. Dining-Philosophers Problem,
3. Readers and Writers Problem,
4. Sleeping Barber Problem
These are summarized, for detailed explanation, you can view the linked articles for each.
Bounded-Buffer (or Producer-Consumer) Problem
The Bounded Buffer problem is also called the producer-consumer problem. This problem is generalized in
terms of the Producer-Consumer problem. The solution to this problem is, to create two counting
semaphores “full” and “empty” to keep track of the current number of full and empty buffers respectively.
Producers produce a product and consumers consume the product, but both use of one of the containers
each time.
Dining-Philosophers Problem
The Dining Philosopher Problem states that K philosophers seated around a circular table with one
chopstick between each pair of philosophers. There is one chopstick between each philosopher. A
philosopher may eat if he can pickup the two chopsticks adjacent to him. One chopstick may be picked up
by any one of its adjacent followers but not both. This problem involves the allocation of limited resources
to a group of processes in a deadlock-free and starvation-free manner.
UNIT 2: Process Management and Concurrency Control

Readers and Writers Problem


Suppose that a database is to be shared among several concurrent processes. Some of these processes
may want only to read the database, whereas others may want to update (that is, to read and write) the
database. We distinguish between these two types of processes by referring to the former as readers and
to the latter as writers. Precisely in OS we call this situation as the readers-writers problem. Problem
parameters:
 One set of data is shared among a number of processes.
 Once a writer is ready, it performs its write. Only one writer may write at a time.
 If a process is writing, no other process can read it.
 If at least one reader is reading, no other process can write.
 Readers may not write and only read.
Sleeping Barber Problem
 Barber shop with one barber, one barber chair and N chairs to wait in. When no customers the
barber goes to sleep in barber chair and must be woken when a customer comes in. When barber is
cutting hair new customers take empty seats to wait, or leave if no vacancy. This is basically
the Sleeping Barber Problem.

Deadlock Prevention And Avoidance


UNIT 2: Process Management and Concurrency Control

When two or more processes try to access the critical section at the same time and they fail to access
simultaneously or stuck while accessing the critical section then this condition is known as Deadlock.
1. Every process needs a few resources to finish running.
2. The procedure makes a resource request. If the resource is available, the OS will grant it; otherwise,
the process will wait.
3. When the process is finished, it is released.
Deadlock Characteristics
The deadlock has the following characteristics:
1. Mutual Exclusion
2. Hold and Wait
3. No preemption
4. Circular wait
Deadlock Prevention
We can prevent a Deadlock by eliminating any of the above four conditions.
Eliminate Mutual Exclusion: It is not possible to dis-satisfy the mutual exclusion because some resources,
such as the tape drive and printer, are inherently non-shareable.
Eliminate Hold and wait: Allocate all required resources to the process before the start of its execution,
this way hold and wait condition is eliminated but it will lead to low device utilization. for example, if a
process requires a printer at a later time and we have allocated a printer before the start of its execution
printer will remain blocked till it has completed its execution. The process will make a new request for
resources after releasing the current set of resources. This solution may lead to starvation.

Eliminate No Preemption : Preempt resources from the process when resources are required by other
high-priority processes.
Eliminate Circular Wait : Each resource will be assigned a numerical number. A process can request the
resources to increase/decrease. order of numbering. For Example, if the P1 process is allocated R5
resources, now next time if P1 asks for R4, R3 lesser than R5 such a request will not be granted, only a
request for resources more than R5 will be granted.
UNIT 2: Process Management and Concurrency Control
Detection and Recovery: Another approach to dealing with deadlocks is to detect and recover from them
when they occur. This can involve killing one or more of the processes involved in the deadlock or releasing
some of the resources they hold.
Deadlock Avoidance
A deadlock avoidance policy grants a resource request only if it can establish that granting the request
cannot lead to a deadlock either immediately or in the future. The kernal lacks detailed knowledge about
future behavior of processes, so it cannot accurately predict deadlocks. To facilitate deadlock avoidance
under these conditions, it uses the following conservative approach: Each process declares the maximum
number of resource units of each class that it may require. The kernal permits a process to request these
resource units in stages- i.e. a few resource units at a time- subject to the maximum number declared by it
and uses a worst case analysis technique to check for the possibility of future deadlocks. A request is
granted only if there is no possibility of deadlocks; otherwise, it remains pending until it can be granted.
This approach is conservative because a process may complete its operation without requiring the
maximum number of units declared by it.
Resource Allocation Graph
The resource allocation graph (RAG) is used to visualize the system’s current state as a graph. The Graph
includes all processes, the resources that are assigned to them, as well as the resources that each Process
requests. Sometimes, if there are fewer processes, we can quickly spot a deadlock in the system by looking
at the graph rather than the tables we use in Banker’s algorithm. Deadlock avoidance can also be done
with Banker’s Algorithm.
Banker’s Algorithm
Bankers’s Algorithm is a resource allocation and deadlock avoidance algorithm which test all the request
made by processes for resources, it checks for the safe state, and after granting a request system remains
in the safe state it allows the request, and if there is no safe state it doesn’t allow the request made by the
process.
Inputs to Banker’s Algorithm
1. Max needs of resources by each process.
2. Currently, allocated resources by each process.
3. Max free available resources in the system.
The request will only be granted under the below condition
1. If the request made by the process is less than equal to the max needed for that process.
2. If the request made by the process is less than equal to the freely available resource in the system.
Timeouts: To avoid deadlocks caused by indefinite waiting, a timeout mechanism can be used to limit the
amount of time a process can wait for a resource. If the help is unavailable within the timeout period, the
process can be forced to release its current resources and try again later.
Example:
Total resources in system:
ABCD
6576
UNIT 2: Process Management and Concurrency Control

The total number of resources are


Available system resources are:
ABCD
3112

Available resources are


Processes (currently allocated resources):
ABCD
P1 1 2 2 1
P2 1 0 3 3
P3 1 2 1 0

Maximum resources we have for a process


Processes (maximum resources):
ABCD
P1 3 3 2 2
P2 1 2 3 4
P3 1 3 5 0

Need = Maximum Resources Requirement – Currently Allocated Resources.


Need = maximum resources - currently allocated resources.
Processes (need resources):
ABCD
P1 2 1 0 1
P2 0 2 0 1
P3 0 1 4 0
UNIT 3: Memory management
Requirements of Memory Management System

Memory management keeps track of the status of each memory location, whether it is allocated or free. It allocates
the memory dynamically to the programs at their request and frees it for reuse when it is no longer needed.
Memory management meant to satisfy some requirements that we should keep in mind.

These Requirements of memory management are:

1. Relocation – The available memory is generally shared among a number of processes in a multiprogramming
system, so it is not possible to know in advance which other programs will be resident in main memory at
the time of execution of this program. Swapping the active processes in and out of the main memory
enables the operating system to have a larger pool of ready-to-execute process.

When a program gets swapped out to a disk memory, then it is not always possible that when it is swapped
back into main memory then it occupies the previous memory location, since the location may still be
occupied by another process. We may need to relocate the process to a different area of memory. Thus
there is a possibility that program may be moved in main memory due to swapping.

The figure depicts a process image. The process image is occupying a continuous region of main memory. The
operating system will need to know many things including the location of process control information, the execution
stack, and the code entry. Within a program, there are memory references in various instructions and these are
called logical addresses.

After loading of the program into main memory, the processor and the operating system must be able to translate
logical addresses into physical addresses. Branch instructions contain the address of the next instruction to be
executed. Data reference instructions contain the address of byte or word of data referenced.

2. Protection – There is always a danger when we have multiple programs at the same time as one program
may write to the address space of another program. So every process must be protected against unwanted
interference when other process tries to write in a process whether accidental or incidental. Between
relocation and protection requirement a trade-off occurs as the satisfaction of relocation requirement
increases the difficulty of satisfying the protection requirement.
UNIT 3: Memory management
Prediction of the location of a program in main memory is not possible, that’s why it is impossible to check
the absolute address at compile time to assure protection. Most of the programming language allows the
dynamic calculation of address at run time. The memory protection requirement must be satisfied by the
processor rather than the operating system because the operating system can hardly control a process when
it occupies the processor. Thus it is possible to check the validity of memory references.

3. Sharing – A protection mechanism must have to allow several processes to access the same portion of main
memory. Allowing each processes access to the same copy of the program rather than have their own
separate copy has an advantage.

For example, multiple processes may use the same system file and it is natural to load one copy of the file in
main memory and let it shared by those processes. It is the task of Memory management to allow controlled
access to the shared areas of memory without compromising the protection. Mechanisms are used to
support relocation supported sharing capabilities.

4. Logical organization – Main memory is organized as linear or it can be a one-dimensional address space
which consists of a sequence of bytes or words. Most of the programs can be organized into modules, some
of those are unmodifiable (read-only, execute only) and some of those contain data that can be modified. To
effectively deal with a user program, the operating system and computer hardware must support a basic
module to provide the required protection and sharing. It has the following advantages:

 Modules are written and compiled independently and all the references from one module to
another module are resolved by `the system at run time.

 Different modules are provided with different degrees of protection.

 There are mechanisms by which modules can be shared among processes. Sharing can be provided
on a module level that lets the user specify the sharing that is desired.

5. Physical organization – The structure of computer memory has two levels referred to as main memory and
secondary memory. Main memory is relatively very fast and costly as compared to the secondary memory.
Main memory is volatile. Thus secondary memory is provided for storage of data on a long-term basis while
the main memory holds currently used programs. The major system concern between main memory and
secondary memory is the flow of information and it is impractical for programmers to understand this for
two reasons:

 The programmer may engage in a practice known as overlaying when the main memory available for
a program and its data may be insufficient. It allows different modules to be assigned to the same
region of memory. One disadvantage is that it is time-consuming for the programmer.

 In a multiprogramming environment, the programmer does not know how much space will be
available at the time of coding and where that space will be located inside the memory.

Fixed (or static) Partitioning in Operating System

Fixed partitioning, also known as static partitioning, is a memory allocation technique used in operating systems to
divide the physical memory into fixed-size partitions or regions, each assigned to a specific process or user. Each
partition is typically allocated at system boot time and remains dedicated to a specific process until it terminates or
releases the partition.

1. In fixed partitioning, the memory is divided into fixed-size chunks, with each chunk being reserved for a
specific process. When a process requests memory, the operating system assigns it to the appropriate
partition. Each partition is of the same size, and the memory allocation is done at system boot time.
UNIT 3: Memory management
2. Fixed partitioning has several advantages over other memory allocation techniques. First, it is simple and
easy to implement. Second, it is predictable, meaning the operating system can ensure a minimum amount
of memory for each process. Third, it can prevent processes from interfering with each other’s memory
space, improving the security and stability of the system.

3. However, fixed partitioning also has some disadvantages. It can lead to internal fragmentation, where
memory in a partition remains unused. This can happen when the process’s memory requirements are
smaller than the partition size, leaving some memory unused. Additionally, fixed partitioning limits the
number of processes that can run concurrently, as each process requires a dedicated partition.

Overall, fixed partitioning is a useful memory allocation technique in situations where the number of
processes is fixed, and the memory requirements for each process are known in advance. It is
commonly used in embedded systems, real-time systems, and systems with limited memory
resources.

In operating systems, Memory Management is the function responsible for allocating and managing
a computer’s main memory. Memory Management function keeps track of the status of each
memory location, either allocated or free to ensure effective and efficient use of Primary Memory.

There are two Memory Management Techniques:

1. Contiguous

2. Non-Contiguous

In Contiguous Technique, executing process must be loaded entirely in the main memory.

Contiguous Technique can be divided into:

 Fixed (or static) partitioning

 Variable (or dynamic) partitioning

Fixed Partitioning:
This is the oldest and simplest technique used to put more than one process in the main memory. In this
partitioning, the number of partitions (non-overlapping) in RAM is fixed but the size of each partition may or may
not be the same. As it is a contiguous allocation, hence no spanning is allowed. Here partitions are made before
execution or during system configure.
UNIT 3: Memory management
As illustrated in above figure, first process is only consuming 1MB out of 4MB in the main memory.
Hence, Internal Fragmentation in first block is (4-1) = 3MB.
Sum of Internal Fragmentation in every block = (4-1)+(8-7)+(8-7)+(16-14)= 3+1+1+2 = 7MB.

Suppose process P5 of size 7MB comes. But this process cannot be accommodated in spite of available free space
because of contiguous allocation (as spanning is not allowed). Hence, 7MB becomes part of External Fragmentation.

There are some advantages and disadvantages of fixed partitioning.

Advantages of Fixed Partitioning –

 Easy to implement: The algorithms needed to implement Fixed Partitioning are straightforward and easy to
implement.

 Low overhead: Fixed Partitioning requires minimal overhead, which makes it ideal for systems with limited
resources.

 Predictable: Fixed Partitioning ensures a predictable amount of memory for each process.

 No external fragmentation: Fixed Partitioning eliminates the problem of external fragmentation.

 Suitable for systems with a fixed number of processes: Fixed Partitioning is well-suited for systems with a
fixed number of processes and known memory requirements.

 Prevents processes from interfering with each other: Fixed Partitioning ensures that processes do not
interfere with each other’s memory space.

 Efficient use of memory: Fixed Partitioning ensures that memory is used efficiently by allocating it to fixed-
sized partitions.

 Good for batch processing: Fixed Partitioning is ideal for batch processing environments where the number
of processes is fixed.

 Better control over memory allocation: Fixed Partitioning gives the operating system better control over the
allocation of memory.

 Easy to debug: Fixed Partitioning is easy to debug since the size and location of each process are
predetermined.

Disadvantages of Fixed Partitioning –

1. Internal Fragmentation:
Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This can
cause internal fragmentation.

2. External Fragmentation:
The total unused space (as stated above) of various partitions cannot be used to load the processes even
though there is space available but not in the contiguous form (as spanning is not allowed).

3. Limit process size:


Process of size greater than the size of the partition in Main Memory cannot be accommodated. The
partition size cannot be varied according to the size of the incoming process size. Hence, the process size of
32MB in the above-stated example is invalid.
UNIT 3: Memory management
4. Limitation on Degree of Multiprogramming:
Partitions in Main Memory are made before execution or during system configure. Main Memory is divided
into a fixed number of partitions. Suppose if there are partitions in RAM and are the number of
processes, then condition must be fulfilled. Number of processes greater than the number of partitions in
RAM is invalid in Fixed Partitioning.

First-Fit Allocation in Operating Systems

INTRODUCTION:

First-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In
First-Fit, the operating system searches through the list of free blocks of memory, starting from the beginning of the
list, until it finds a block that is large enough to accommodate the memory request from the process. Once a suitable
block is found, the operating system splits the block into two parts: the portion that will be allocated to the process,
and the remaining free block.

Advantages of First-Fit Allocation include its simplicity and efficiency, as the search for a suitable block of memory
can be performed quickly and easily. Additionally, First-Fit can also help to minimize memory fragmentation, as it
tends to allocate memory in larger blocks.

Disadvantages of First-Fit Allocation include poor performance in situations where the memory is highly fragmented,
as the search for a suitable block of memory can become time-consuming and inefficient. Additionally, First-Fit can
also lead to poor memory utilization, as it may allocate larger blocks of memory than are actually needed by a
process.

Overall, First-Fit Allocation is a widely used memory allocation technique in operating systems, but its effectiveness
may vary depending on the specifics of the system and the workload being executed.

For both fixed and dynamic memory allocation schemes, the operating system must keep list of each memory
location noting which are free and which are busy. Then as new jobs come into the system, the free partitions must
be allocated. These partitions may be allocated by 4 ways:

1. First-Fit Memory Allocation

2. Best-Fit Memory Allocation

3. Worst-Fit Memory Allocation

4. Next-Fit Memory Allocation

These are Contiguous memory allocation techniques. First-Fit Memory Allocation: This method keeps the free/busy
list of jobs organized by memory location, low-ordered to high-ordered memory. In this method, first job claims the
first available memory with space more than or equal to it’s size. The operating system doesn’t search for
UNIT 3: Memory management
appropriate partition but just allocate the job to the nearest memory partition available with sufficient size.

As illustrated above, the system assigns J1 the nearest partition in the memory. As a result, there is no partition with
sufficient space is available for J3 and it is placed in the waiting list.The processor ignores if the size of partition
allocated to the job is very large as compared to the size of job or not. It just allocates the memory. As a result, a lot
of memory is wasted and many jobs may not get space in the memory, and would have to wait for another job to
complete.

ADVANTAGES OR DISADVANTAGES:

Advantages of First-Fit Allocation in Operating Systems:

1. Simple and efficient search algorithm

2. Minimizes memory fragmentation

3. Fast allocation of memory

Disadvantages of First-Fit Allocation in Operating Systems:

1. Poor performance in highly fragmented memory

2. May lead to poor memory utilization

3. May allocate larger blocks of memory than required.

Worst-Fit Allocation in Operating Systems


For both fixed and dynamic memory allocation schemes, the operating system must keep a list of each memory
location noting which are free and which are busy. Then as new jobs come into the system, the free partitions must
be allocated.
UNIT 3: Memory management
These partitions may be allocated in 4 ways:

1. First-Fit Memory Allocation

2. Best-Fit Memory Allocation

3. Worst-Fit Memory Allocation

4. Next-Fit Memory Allocation

These are Contiguous memory allocation techniques.

Worst-Fit Memory Allocation :


In this allocation technique, the process traverses the whole memory and always search for the largest
hole/partition, and then the process is placed in that hole/partition. It is a slow process because it has to traverse the
entire memory to search the largest hole.

Here is an example to understand Worst Fit-Allocation –

Here Process P1=30K is allocated with the Worst Fit-Allocation technique, so it traverses the entire memory and
selects memory size 400K which is the largest, and hence there is an internal fragmentation of 370K which is very
large and so many other processes can also utilize this leftover space.

Advantages of Worst-Fit Allocation :


Since this process chooses the largest hole/partition, therefore there will be large internal fragmentation. Now, this
internal fragmentation will be quite big so that other small processes can also be placed in that leftover partition.

Disadvantages of Worst-Fit Allocation :


It is a slow process because it traverses all the partitions in the memory and then selects the largest partition among
all the partitions, which is a time-consuming process.

Introduction to Fragmentation

Fragmentation is an important function of network layer. It is technique in which gateways break up or divide larger
packets into smaller ones called fragments. Each fragment is then sent as a separate internal packet. Each fragment
has its separate header and trailer.

Sometimes, a fragmented datagram can also get fragmented further when it encounters a network that handles
smaller fragments. Thus, a datagram can be fragmented several times before it reaches final destination. Reverse
process of the fragmentation is difficult. Reassembling of fragments is usually done by the destination host because
each fragment has become an independent datagram.

For the reference of example of fragmentation you can refer : Fragmentation Example

There are two different strategies for the recombination or we can say reassembly of fragments : Transparent
Fragmentation, and Non-Transparent Fragmentation.

1. Transparent Fragmentation:
This fragmentation is done by one network is made transparent to all other subsequent networks through which
packet will pass. Whenever a large packet arrives at a gateway, it breaks the packet into smaller fragments as shown
in the following figure i.e the gateway G1 breaks a packet into smaller fragments.
UNIT 3: Memory management

Figure – Transparent Fragmentation


After this, each fragment is going to address to same exit gateway. Exit gateway of a network reassembles or
recombines all fragments as shown in above figure. The exit gateway, G2 of network 1 recombines all fragments
created by G1 before passing them to network 2. Thus, subsequent network is not aware that fragmentation has
occurred. This type of strategy is used by ATM networks . These networks use special hardware that provides
transparent fragmentation of packets.

There are some disadvantages of transparency strategy which are as follows :

 Exit fragment that recombines fragments in a network must known when it has received all fragments.

 Some fragments chooses different gateways for exit that results in poor performance.

 It adds considerable overhead in repeatedly fragmenting and reassembling large packet.

2. Non-Transparent Fragmentation:
This fragmentation is done by one network is non-transparent to the subsequent networks through which a packet
passes. Packet fragmented by a gateway of a network is not recombined by exit gateway of same network as shown
in the below figure.

Figure – Non-transparent Fragmentation


Once a packet is fragmented, each fragment is treated as original packet. All fragments of a packet are passed
through exit gateway and recombination of these fragments is done at the destination host.
UNIT 3: Memory management
Advantages of Non-Transparent Fragmentation is as follows :
 We can use multiple exit gateways and can improve the network performance.

 It has a higher throughput.

Disadvantages of Non-Transparent Fragmentation is as follows :


 Every host has capability of reassembling fragments.

 When a packet is fragmented, fragments should be numbered in such a way that the original data stream
can be reconstructed.

 Total overhead increases due to fragmentation as each fragment must have its own header.

Swapping in Operating System

To increase CPU utilization in multiprogramming, a memory management scheme known as swapping can be used.
Swapping is the process of bringing a process into memory and then temporarily copying it to the disc after it has run
for a while. The purpose of swapping in an operating system is to access data on a hard disc and move it to RAM so
that application programs can use it. It’s important to remember that swapping is only used when data isn’t available
in RAM. Although the swapping process degrades system performance, it allows larger and multiple processes to run
concurrently. Because of this, swapping is also known as memory compaction. The CPU scheduler determines which
processes are swapped in and which are swapped out. Consider a multiprogramming environment that employs a
priority-based scheduling algorithm. When a high-priority process enters the input queue, a low-priority process is
swapped out so the high-priority process can be loaded and executed. When this process terminates, the low
priority process is swapped back into memory to continue its execution. Below figure shows the swapping process in
operating system:
UNIT 3: Memory management
Swapping has been subdivided into two concepts: swap-in and swap-out.

 Swap-out is a technique for moving a process from RAM to the hard disc.

 Swap-in is a method of transferring a program from a hard disc to main memory, or RAM.

Advantages

 If there is low main memory so some processes may has to wait for much long but by using swapping
process do not have to wait long for execution on CPU.

 It utilize the main memory.

 Using only single main memory, multiple process can be run by CPU using swap partition.

 The concept of virtual memory start from here and it utilize it in better way.

 This concept can be useful in priority based scheduling to optimize the swapping process.

Disadvantages

 If there is low main memory resource and user is executing too many processes and suddenly the power of
system goes off there might be a scenario where data get erase of the processes which are took parts in
swapping.

 Chances of number of page faults occur

 Low processing performance

Only one process occupies the user program area of memory in a single tasking operating system and remains in
memory until the process is completed.
When all of the active processes in a multitasking operating system cannot coordinate in main memory, a process is
swapped out of main memory so that other processes can enter it.

What is Demand Paging in Operating System?


The concept of query navigation in the operating system. This concept says that we should not load any pages into
the main memory until we need them, or keep all pages in secondary memory until we need them.

Demand Paging

Demand paging can be described as a memory management technique that is used in operating systems to improve
memory usage and system performance. Demand paging is a technique used in virtual memory systems where
pages enter main memory only when requested or needed by the CPU.

In demand paging, the operating system loads only the necessary pages of a program into memory at runtime,
instead of loading the entire program into memory at the start.

A page fault occurred when the program needed to access a page that is not currently in memory. The operating
system then loads the required pages from the disk into memory and updates the page tables accordingly. This
process is transparent to the running program and it continues to run as if the page had always been in memory.

Pure Demand Paging

Pure demand paging is a specific implementation of demand paging. The operating system only loads pages into
memory when the program needs them. In on-demand paging only, no pages are initially loaded into memory when
the program starts, and all pages are initially marked as being on disk.

Benefits of the Demand Paging

So in the Demand Paging technique, there are some benefits that provide efficiency of the operating system.
UNIT 3: Memory management
 Efficient use of physical memory: Query paging allows for more efficient use because only the necessary
pages are loaded into memory at any given time.

 Support for larger programs: Programs can be larger than the physical memory available on the system
because only the necessary pages will be loaded into memory.

 Faster program start: Because only part of a program is initially loaded into memory, programs can start
faster than if the entire program were loaded at once.

 Reduce memory usage: Query paging can help reduce the amount of memory a program needs, which can
improve system performance by reducing the amount of disk I/O required.

Drawbacks of the Demand Paging

 Page Fault Overload: The process of swapping pages between memory and disk can cause a performance
overhead, especially if the program frequently accesses pages that are not currently in memory.

 Degraded performance: If a program frequently accesses pages that are not currently in memory, the
system spends a lot of time swapping out pages, which degrades performance.

 Fragmentation: Query paging can cause physical memory fragmentation, degrading system performance
over time.

 Complexity: Implementing query paging in an operating system can be complex, requiring complex
algorithms and data structures to manage page tables and swap space.

Working Process of Demand Paging

So, let’s understand this with the help of an example. Suppose we want to run a process P which has four pages P0,
P1, P2, and P3. Currently, in the page table, we have pages P1 and P3.

Demand Paging

So there are some steps that are followed in the working process of the demand paging in the operating system.

 Program Execution: When a program starts, the operating system creates a process for the program and
allocates a portion of memory to the process.

 Creating page tables: The operating system creates page tables for processes, which track which program
pages are currently in memory and which are on disk.

 Page fault handling: A page fault occurred when the program attempted to access a page that is not
currently in memory. The operating system interrupts the program and checks the page tables to see if the
required page is on disk.

 Page Fetch: If the required page is on disk, the operating system fetches the page from the disk and loads it
into memory.
The page table is then updated to reflect the page’s new location in memory.

 Resuming the program: Once the required pages have been loaded into memory, the operating system
resumes execution of the program where it left off. The program continues to run as if the page had always
been in memory.

 Page replacement: If there is not enough free memory to hold all the pages a program needs, the operating
system may need to replace one or more pages currently in memory with pages currently in memory. on the
disk. The page replacement algorithm used by the operating system determines which pages are selected for
replacement.
UNIT 3: Memory management
 Page cleanup: When a process terminates, the operating system frees the memory allocated to the process
and cleans up the corresponding entries in the page tables.

Difference between Paging and Swapping :


Swapping Paging

It is the procedure of copying out the entire


It is a technique of memory allocation.
process.

Swapping occurs when whole process is Paging occurs when some part of the process is
transferred to the disk. transferred to the disk.

In this, a process is swapped temporarily In this. the contiguous block of memory is made non-
from main memory to secondary memory. contiguous but of fixed size called frame or pages.

Swapping can be performed without any It is a concept used in Non-contiguous Memory


memory management. Management.

Swapping is done by inactive processes. The only active process can perform paging.

It provides the direction regarding the


No suggestion is given regarding the solution in it.
solution.

Swapping copies the whole information, so


Paging is relatively faster than swapping.
is relatively slower.
Segmentation in Operating System

A process is divided into Segments. The chunks that a program is divided into which are not necessarily all of the
exact sizes are called segments. Segmentation gives the user’s view of the process which paging does not provide.
Here the user’s view is mapped to physical memory.

Types of Segmentation in Operating System

 Virtual Memory Segmentation: Each process is divided into a number of segments, but the segmentation is
not done all at once. This segmentation may or may not take place at the run time of the program.

 Simple Segmentation: Each process is divided into a number of segments, all of which are loaded into
memory at run time, though not necessarily contiguously.

There is no simple relationship between logical addresses and physical addresses in segmentation. A table stores the
information about all such segments and is called Segment Table.

What is Segment Table?

It maps a two-dimensional Logical address into a one-dimensional Physical address. It’s each table entry has:

 Base Address: It contains the starting physical address where the segments reside in memory.

 Segment Limit: Also known as segment offset. It specifies the length of the segment.
UNIT 3: Memory management
Segmentation
Translation of Two-dimensional Logical Address to Dimensional Physical Address.

Translation
The address generated by the CPU is divided into:

 Segment number (s): Number of bits required to represent the segment.

 Segment offset (d): Number of bits required to represent the size of the segment.

Advantages of Segmentation in Operating System

 No Internal fragmentation.

 Segment Table consumes less space in comparison to Page table in paging.

 As a complete module is loaded all at once, segmentation improves CPU utilization.

 The user’s perception of physical memory is quite similar to segmentation. Users can divide user programs
into modules via segmentation. These modules are nothing more than separate processes’ codes.

 The user specifies the segment size, whereas, in paging, the hardware determines the page size.

 Segmentation is a method that can be used to segregate data from security operations.

 Flexibility: Segmentation provides a higher degree of flexibility than paging. Segments can be of variable
size, and processes can be designed to have multiple segments, allowing for more fine-grained memory
allocation.

 Sharing: Segmentation allows for sharing of memory segments between processes. This can be useful for
inter-process communication or for sharing code libraries.

 Protection: Segmentation provides a level of protection between segments, preventing one process from
accessing or modifying another process’s memory segment. This can help increase the security and stability
of the system.

Disadvantages of Segmentation in Operating System

 As processes are loaded and removed from the memory, the free memory space is broken into little pieces,
causing External fragmentation.

 Overhead is associated with keeping a segment table for each activity.

 Due to the need for two memory accesses, one for the segment table and the other for main memory,
access time to retrieve the instruction increases.

 Fragmentation: As mentioned, segmentation can lead to external fragmentation as memory becomes


divided into smaller segments. This can lead to wasted memory and decreased performance.

 Overhead: Using a segment table can increase overhead and reduce performance. Each segment table entry
requires additional memory, and accessing the table to retrieve memory locations can increase the time
needed for memory operations.

 Complexity: Segmentation can be more complex to implement and manage than paging. In particular,
managing multiple segments per process can be challenging, and the potential for segmentation faults can
increase as a result.
UNIT 3: Memory management

S.NO Paging Segmentation

In paging, the program is divided into In segmentation, the program is divided into
1.
fixed or mounted size pages. variable size sections.

For the paging operating system is


2. For segmentation compiler is accountable.
accountable.

3. Page size is determined by hardware. Here, the section size is given by the user.

4. It is faster in comparison to segmentation. Segmentation is slow.

Paging could result in internal Segmentation could result in external


5.
fragmentation. fragmentation.

In paging, the logical address is split into Here, the logical address is split into section
6.
a page number and page offset. number and section offset.

While segmentation also comprises the segment


Paging comprises a page table that
7. table which encloses segment number and
encloses the base address of every page.
segment offset.

The page table is employed to keep up the


8. Section Table maintains the section data.
page data.

In paging, the operating system must In segmentation, the operating system maintains
9.
maintain a free frame list. a list of holes in the main memory.
UNIT 3: Memory management
S.NO Paging Segmentation

10. Paging is invisible to the user. Segmentation is visible to the user.

In paging, the processor needs the page


In segmentation, the processor uses segment
11. number, and offset to calculate the
number, and offset to calculate the full address.
absolute address.

It is hard to allow sharing of procedures Facilitates sharing of procedures between the


12.
between processes. processes.

In paging, a programmer cannot


13 It can efficiently handle data structures.
efficiently handle data structure.

14. This protection is hard to apply. Easy to apply for protection in segmentation.

The size of the page needs always be


15. There is no constraint on the size of segments.
equal to the size of frames.

A page is referred to as a physical unit of A segment is referred to as a logical unit of


16.
information. information.

17. Paging results in a less efficient system. Segmentation results in a more efficient system.
What is Demand Paging in Operating System?

The concept of query navigation in the operating system. This concept says that we should not load any pages into
the main memory until we need them, or keep all pages in secondary memory until we need them.

Demand Paging

Demand paging can be described as a memory management technique that is used in operating systems to improve
memory usage and system performance. Demand paging is a technique used in virtual memory systems where
pages enter main memory only when requested or needed by the CPU.

In demand paging, the operating system loads only the necessary pages of a program into memory at runtime,
instead of loading the entire program into memory at the start.

A page fault occurred when the program needed to access a page that is not currently in memory. The operating
system then loads the required pages from the disk into memory and updates the page tables accordingly. This
process is transparent to the running program and it continues to run as if the page had always been in memory.

Pure Demand Paging

Pure demand paging is a specific implementation of demand paging. The operating system only loads pages into
memory when the program needs them. In on-demand paging only, no pages are initially loaded into memory when
the program starts, and all pages are initially marked as being on disk.

Benefits of the Demand Paging

So in the Demand Paging technique, there are some benefits that provide efficiency of the operating system.
UNIT 3: Memory management
 Efficient use of physical memory: Query paging allows for more efficient use because only the necessary
pages are loaded into memory at any given time.

 Support for larger programs: Programs can be larger than the physical memory available on the system
because only the necessary pages will be loaded into memory.

 Faster program start: Because only part of a program is initially loaded into memory, programs can start
faster than if the entire program were loaded at once.

 Reduce memory usage: Query paging can help reduce the amount of memory a program needs, which can
improve system performance by reducing the amount of disk I/O required.

Drawbacks of the Demand Paging

 Page Fault Overload: The process of swapping pages between memory and disk can cause a performance
overhead, especially if the program frequently accesses pages that are not currently in memory.

 Degraded performance: If a program frequently accesses pages that are not currently in memory, the
system spends a lot of time swapping out pages, which degrades performance.

 Fragmentation: Query paging can cause physical memory fragmentation, degrading system performance
over time.

 Complexity: Implementing query paging in an operating system can be complex, requiring complex
algorithms and data structures to manage page tables and swap space.

Working Process of Demand Paging

So, let’s understand this with the help of an example. Suppose we want to run a process P which has four pages P0,
P1, P2, and P3. Currently, in the page table, we have pages P1 and P3.

Demand Paging

So there are some steps that are followed in the working process of the demand paging in the operating system.

 Program Execution: When a program starts, the operating system creates a process for the program and
allocates a portion of memory to the process.

 Creating page tables: The operating system creates page tables for processes, which track which program
pages are currently in memory and which are on disk.

 Page fault handling: A page fault occurred when the program attempted to access a page that is not
currently in memory. The operating system interrupts the program and checks the page tables to see if the
required page is on disk.

 Page Fetch: If the required page is on disk, the operating system fetches the page from the disk and loads it
into memory.
The page table is then updated to reflect the page’s new location in memory.

 Resuming the program: Once the required pages have been loaded into memory, the operating system
resumes execution of the program where it left off. The program continues to run as if the page had always
been in memory.

 Page replacement: If there is not enough free memory to hold all the pages a program needs, the operating
system may need to replace one or more pages currently in memory with pages currently in memory. on the
disk. The page replacement algorithm used by the operating system determines which pages are selected for
replacement.
UNIT 3: Memory management
 Page cleanup: When a process terminates, the operating system frees the memory allocated to the process
and cleans up the corresponding entries in the page tables.

S.No. Demand Paging Segmentation

In demand paging, the pages are of While in segmentation, segments can be of


1.
equal size. different size.

Page size is fixed in the demand Segment size may vary in segmentation as it grants
2.
paging. dynamic increase of segments.

It does not allows sharing of the


3. While segments can be shared in segmentation.
pages.

In demand paging, on demand pages In segmentation, during compilation segments are


4.
are loaded in the memory. allocated to the program.

Page map table in demand paging Segment map table in segmentation demonstrates
5.
manages record of pages in memory. every segment address in the memory.

It provides large virtual memory and It provides virtual memory and maximum size of
6.
have more efficient use of memory. segment is defined by the size of memory.

7. Virtual memory is divided into pages. Virtual memory is divided into segments.

Size of Unit of demand Paging Pages Size of Unit of segmentation Segments are variable
8.
can be of equal or variable size. in size.

Memory allocation of Pages are Memory allocation of Segments are allocated at the
9.
allocated dynamically. process start.

Memory access is Page-level


10. Memory access is segment-level protection.
protection.

Memory wastage is Internal


11. Memory wastage is external fragmentation.
fragmentation.

Paging algorithm is non- demand Paging(Fixed


12. Paging algorithm is Demand Paging.
Allocation).
Virtual Memory in Operating Syste

Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part
of the main memory. The addresses a program may use to reference memory are distinguished from the addresses
the memory system uses to identify physical storage sites and program-generated addresses are translated
automatically to the corresponding machine addresses.
UNIT 3: Memory management
The size of virtual storage is limited by the addressing scheme of the computer system and the amount of secondary
memory available not by the actual number of main storage locations.

It is a technique that is implemented using both hardware and software. It maps memory addresses used by a
program, called virtual addresses, into physical addresses in computer memory.

1. All memory references within a process are logical addresses that are dynamically translated into physical
addresses at run time. This means that a process can be swapped in and out of the main memory such that it
occupies different places in the main memory at different times during the course of execution.

2. A process may be broken into a number of pieces and these pieces need not be continuously located in
the main memory during execution. The combination of dynamic run-time address translation and the use of
a page or segment table permits this.

If these characteristics are present then, it is not necessary that all the pages or segments are present in the main
memory during execution. This means that the required pages need to be loaded into memory whenever required.
Virtual memory is implemented using Demand Paging or Demand Segmentation.

Demand Paging

The process of loading the page into memory on demand (whenever a page fault occurs) is known as demand
paging. The process includes the following steps are as follows:

Demand Paging
1. If the CPU tries to refer to a page that is currently not available in the main memory, it generates an
interrupt indicating a memory access fault.

2. The OS puts the interrupted process in a blocking state. For the execution to proceed the OS must bring the
required page into the memory.

3. The OS will search for the required page in the logical address space.

4. The required page will be brought from logical address space to physical address space. The page
replacement algorithms are used for the decision-making of replacing the page in physical address space.

5. The page table will be updated accordingly.

6. The signal will be sent to the CPU to continue the program execution and it will place the process back into
the ready state.

Hence whenever a page fault occurs these steps are followed by the operating system and the required page is
brought into memory.

Advantages of Virtual Memory

 More processes may be maintained in the main memory: Because we are going to load only some of the
pages of any particular process, there is room for more processes. This leads to more efficient utilization of
the processor because it is more likely that at least one of the more numerous processes will be in the ready
state at any particular time.

 A process may be larger than all of the main memory: One of the most fundamental restrictions in
programming is lifted. A process larger than the main memory can be executed because of demand paging.
The OS itself loads pages of a process in the main memory as required.

 It allows greater multiprogramming levels by using less of the available (primary) memory for each process.

 It has twice the capacity for addresses as main memory.

 It makes it possible to run more applications at once.


UNIT 3: Memory management
 Users are spared from having to add memory modules when RAM space runs out, and applications are
liberated from shared memory management.

 When only a portion of a program is required for execution, speed has increased.

 Memory isolation has increased security.

 It makes it possible for several larger applications to run at once.

 Memory allocation is comparatively cheap.

 It doesn’t require outside fragmentation.

 It is efficient to manage logical partition workloads using the CPU.

 Automatic data movement is possible.

Disadvantages of Virtual Memory

 It can slow down the system performance, as data needs to be constantly transferred between the physical
memory and the hard disk.

 It can increase the risk of data loss or corruption, as data can be lost if the hard disk fails or if there is a
power outage while data is being transferred to or from the hard disk.

 It can increase the complexity of the memory management system, as the operating system needs to
manage both physical and virtual memory.

Page Fault Service Time: The time taken to service the page fault is called page fault service time. The page fault
service time includes the time taken to perform all the above six steps.

Let Main memory access time is: m


Page fault service time is: s
Page fault rate is : p
Then, Effective memory access time = (p*s) + (1-p)*m

Swapping
Swapping is a process out means removing all of its pages from memory, or marking them so that they will be
removed by the normal page replacement process. Suspending a process ensures that it is not runnable while it is
swapped out. At some later time, the system swaps back the process from the secondary storage to the main
memory. When a process is busy swapping pages in and out then this situation is called thrashing.

Thrashing
At any given time, only a few pages of any process are in the main memory, and therefore more processes can be
maintained in memory. Furthermore, time is saved because unused pages are not swapped in and out of memory.
However, the OS must be clever about how it manages this scheme. In the steady state practically, all of the main
memory will be occupied with process pages, so that the processor and OS have direct access to as many processes
as possible. Thus when the OS brings one page in, it must throw another out. If it throws out a page just before it is
used, then it will just have to get that page again almost immediately. Too much of this leads to a condition called
Thrashing. The system spends most of its time swapping pages rather than executing instructions. So a good page
replacement algorithm is required.

In the given diagram, the initial degree of multiprogramming up to some extent of point(lambda), the CPU utilization
is very high and the system resources are utilized 100%. But if we further increase the degree of multiprogramming
the CPU utilization will drastically fall down and the system will spend more time only on the page replacement and
the time taken to complete the execution of the process will increase. This situation in the system is called
thrashing.
UNIT 3: Memory management
Causes of Thrashing
1. High Degree of Multiprogramming: If the number of processes keeps on increasing in the memory then the
number of frames allocated to each process will be decreased. So, fewer frames will be available for each process.
Due to this, a page fault will occur more frequently and more CPU time will be wasted in just swapping in and out of
pages and the utilization will keep on decreasing.

For example:
Let free frames = 400
Case 1: Number of processes = 100
Then, each process will get 4 frames.

Case 2: Number of processes = 400


Each process will get 1 frame.
Case 2 is a condition of thrashing, as the number of processes is increased, frames per process are decreased. Hence
CPU time will be consumed just by swapping pages.

2. Lacks of Frames: If a process has fewer frames then fewer pages of that process will be able to reside in memory
and hence more frequent swapping in and out will be required. This may lead to thrashing. Hence a sufficient
amount of frames must be allocated to each process in order to prevent thrashing.

Recovery of Thrashing

 Do not allow the system to go into thrashing by instructing the long-term scheduler not to bring the
processes into memory after the threshold.

 If the system is already thrashing then instruct the mid-term scheduler to suspend some of the processes so
that we can recover the system from thrashing.

Performance in Virtual Memory

 Let p be the page fault rate( 0 <= p <= 1).

 if p = 0 no page faults

 if p =1, every reference is a fault.

Effective access time (EAT) = (1-p)* Memory Access Time + p * Page fault time.

Page fault time = page fault overhead + swap out + swap in +restart overhead

The performance of a virtual memory management system depends on the total number of page faults, which
depend on “paging policies” and “frame allocation“

Frame Allocation

A number of frames allocated to each process in either static or dynamic.

 Static Allocation: The number of frame allocations to a process is fixed.

 Dynamic Allocation: The number of frames allocated to a process changes.

Paging Policies

 Fetch Policy: It decides when a page should be loaded into memory.

 Replacement Policy: It decides which page in memory should be replaced.

 Placement Policy: It decides where in memory should a page be loaded.


UNIT 3: Memory management
Page Replacement Algorithms in Operating Systems
In an operating system that uses paging for memory management, a page replacement algorithm is needed to
decide which page needs to be replaced when a new page comes in.

Page Fault: A page fault happens when a running program accesses a memory page that is mapped into the virtual
address space but not loaded in physical memory. Since actual physical memory is much smaller than virtual
memory, page faults happen. In case of a page fault, Operating System might have to replace one of the existing
pages with the newly needed page. Different page replacement algorithms suggest different ways to decide which
page to replace. The target for all algorithms is to reduce the number of page faults.

Page Replacement Algorithms:


1. First In First Out (FIFO): This is the simplest page replacement algorithm. In this algorithm, the operating system
keeps track of all pages in the memory in a queue, the oldest page is in the front of the queue. When a page needs
to be replaced page in the front of the queue is selected for removal.

Example 1: Consider page reference string 1, 3, 0, 3, 5, 6, 3 with 3 page frames.Find the number of page faults.

Initially, all slots are empty, so when 1, 3, 0 came they are allocated to the empty slots —> 3 Page Faults.

when 3 comes, it is already in memory so —> 0 Page Faults. Then 5 comes, it is not available in memory so it
replaces the oldest page slot i.e 1. —>1 Page Fault. 6 comes, it is also not available in memory so it replaces the
oldest page slot i.e 3 —>1 Page Fault. Finally, when 3 come it is not available so it replaces 0 1 page fault.

Belady’s anomaly proves that it is possible to have more page faults when increasing the number of page frames
while using the First in First Out (FIFO) page replacement algorithm. For example, if we consider reference strings 3,
2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4, and 3 slots, we get 9 total page faults, but if we increase slots to 4, we get 10-page faults.

2. Optimal Page replacement: In this algorithm, pages are replaced which would not be used for the longest
duration of time in the future.

Example-2: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page frame. Find number of page
fault.

Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults

0 is already there so —> 0 Page fault. when 3 came it will take the place of 7 because it is not used for the longest
duration of time in the future.—>1 Page fault. 0 is already there so —> 0 Page fault. 4 will takes place of 1 —> 1 Page
Fault.

Now for the further page reference string —> 0 Page fault because they are already available in the memory.

Optimal page replacement is perfect, but not possible in practice as the operating system cannot know future
requests. The use of Optimal Page replacement is to set up a benchmark so that other replacement algorithms can
be analyzed against it.
UNIT 3: Memory management
3. Least Recently Used: In this algorithm, page will be replaced which is least recently used.
Example-3: Consider the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page frames. Find number of
page faults.

Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults

0 is already their so —> 0 Page fault. when 3 came it will take the place of 7 because it is least recently used —>1
Page fault

0 is already in memory so —> 0 Page fault.

4 will takes place of 1 —> 1 Page Fault

Now for the further page reference string —> 0 Page fault because they are already available in the memory.

4. Most Recently Used (MRU): In this algorithm, page will be replaced which has been used recently. Belady’s
anomaly can occur in this algorithm.

Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults

0 is already their so–> 0 page fault

when 3 comes it will take place of 0 because it is most recently used —>1 Page fault

when 0 comes it will take place of 3 —>1 Page fault

when 4 comes it will take place of 0 —>1 Page fault

2 is already in memory so —> 0 Page fault

when 3 comes it will take place of 2 —>1 Page fault

when 0 comes it will take place of 3 —>1 Page fault

when 3 comes it will take place of 0 —>1 Page fault

when 2 comes it will take place of 3 —>1 Page fault

when 3 comes it will take place of 2 —>1 Page fault


UNIT 4: I/O management & Disk scheduling:
Input and Output Devices
An input/output device, often known as an IO device, is any hardware that allows a human operator or other
systems to interface with a computer. Input/output devices, as the name implies, are capable of delivering data
(output) to and receiving data from a computer (input). An input/output (I/O) device is a piece of hardware that can
take, output, or process data. It receives data as input and provides it to a computer, as well as sends computer data
to storage media as a storage output.

Input Devices

Input devices are the devices that are used to send signals to the computer for performing tasks. The receiver at the
end is the CPU (Central Processing Unit), which works to send signals to the output devices. Some of the
classifications of Input devices are:

 Keyboard Devices

 Pointing Devices

 Composite Devices

 Game Controller

 Visual Devices

 Audio Input Devices

Some of the input devices are described below.

Keyboard

The keyboard is the most frequent and widely used input device for entering data into a computer. Although there
are some additional keys for performing other operations, the keyboard layout is similar to that of a typical
typewriter.
Generally, keyboards come in two sizes: 84 keys or 101/102 keys but currently keyboards with 104 keys or 108 keys
are also available for Windows and the Internet.

Keyboard

Types of Keys

 Numeric Keys: It is used to enter numeric data or move the cursor. It usually consists of a set of 17 keys.

 Typing Keys: The letter keys (A-Z) and number keys (09) are among these keys.
UNIT 4: I/O management & Disk scheduling:
 Control Keys: These keys control the pointer and the screen. There are four directional arrow keys on it.
Home, End, Insert, Alternate(Alt), Delete, Control(Ctrl), etc., and Escape are all control keys (Esc).

 Special Keys: Enter, Shift, Caps Lock, NumLk, Tab, etc., and Print Screen are among the special function keys
on the keyboard.

 Function Keys: The 12 keys from F1 to F12 are on the topmost row of the keyboard.

Mouse

The most common pointing device is the mouse. The mouse is used to move a little cursor across the screen while
clicking and dragging. The cursor will stop if you let go of the mouse. The computer is dependent on you to move the
mouse; it won’t move by itself. As a result, it’s an input device.
A mouse is an input device that lets you move the mouse on a flat surface to control the coordinates and movement
of the on-screen cursor/pointer.
The left mouse button can be used to select or move items, while the right mouse button when clicked displays extra
menus.

Mouse

Joystick

A joystick is a pointing device that is used to move the cursor on a computer screen. A spherical ball is attached to
both the bottom and top ends of the stick. In a socket, the lower spherical ball slides. You can move the joystick in all
four directions.

Joystick
UNIT 4: I/O management & Disk scheduling:
The joystick’s function is comparable to that of a mouse. It is primarily used in CAD (Computer-Aided Design) and
playing video games on the computer.

Track Ball

Track Ball is an accessory for notebooks and laptops, which works on behalf of a mouse. It has a similar structure to a
mouse. Its structure is like a half-inserted ball and we use fingers for cursor movement. Different shapes are used for
this like balls, buttons, or squares.

Light Pen

A light pen is a type of pointing device that looks like a pen. It can be used to select a menu item or to draw on the
monitor screen. A photocell and an optical system are enclosed in a tiny tube. When the tip of a light pen is moved
across a monitor screen while the pen button is pushed, the photocell sensor element identifies the screen location
and provides a signal to the CPU.

Light Pen

Scanner

A scanner is an input device that functions similarly to a photocopier. It’s employed when there’s information on
paper that needs to be transferred to the computer’s hard disc for subsequent manipulation. The scanner collects
images from the source and converts them to a digital format that may be saved on a disc. Before they are printed,
these images can be modified.
UNIT 4: I/O management & Disk scheduling:
Scanner

Optical Mark Reader (OMR)

An Optical Mark Reader is a device that is generally used in educational institutions to check the answers to
objective exams. It recognizes the marks present by pencil and pen.

Optical Character Reader (OCR)

OCR stands for optical character recognition, and it is a device that reads printed text. OCR optically scans the text,
character by character turns it into a machine-readable code, and saves it to the system memory.

Magnetic Ink Card Reader (MICR)

It is a device that is generally used in banks to deal with the cheques given to the bank by the customer. It helps in
reading the magnetic ink present in the code number and cheque number. This process is very fast compared to any
other process.

Bar Code Reader

A bar code reader is a device that reads data that is bar-coded (data that is represented by light and dark lines).Bar-
coded data is commonly used to mark things, number books, and so on. It could be a handheld scanner or part of a
stationary scanner. A bar code reader scans a bar code image, converts it to an alphanumeric value, and then sends
it to the computer to which it is connected.

Bar Code Reader

Web Camera

Because a web camera records a video image of the scene in front of it, a webcam is an input device. It is either built
inside the computer (for example, a laptop) or attached through a USB connection. A webcam is a computer-
connected tiny digital video camera. It’s also known as a web camera because it can take images and record video.
These cameras come with software that must be installed on the computer in order to broadcast video in real-time
over the Internet. It can shoot images and HD videos, however, the video quality isn’t as good as other cameras (In
Mobiles or other devices or normal cameras).
UNIT 4: I/O management & Disk scheduling:

Web Camera

Digitizer

Digitizer is a device that is used to convert analog signals to digital signals. it converts signals into numeric values. An
example of a Digitizer is Graphic Tablet, which is used to convert graphics to binary data.

Microphone

The microphone works as an input device that receives input voice signals and also has the responsibility of
converting it also to digital form. It is a very common device that is present in every device which is related to music.

Output Devices

Output Devices are the devices that show us the result after giving the input to a computer system. Output can be of
many different forms like image, graphic audio, video, etc. Some of the output devices are described below.

Monitor

Monitors, also known as Visual Display Units (VDUs), are a computer’s primary output device. It creates images by
arranging small dots, known as pixels, in a rectangular pattern. The amount of pixels determines the image’s
sharpness.
The two kinds of viewing screens used for monitors are described below.

 Cathode-Ray Tube (CRT) Monitor: Pixels are minuscule visual elements that make up a CRT display. The
higher the image quality or resolution, the smaller the pixels.

 Flat-Panel Display Monitor: In comparison to the CRT, a flat-panel display is a type of video display with less
volume, weight, and power consumption. They can be hung on the wall or worn on the wrist.

Flat-panel displays are currently used in calculators, video games, monitors, laptop computers, and graphical
displays.
UNIT 4: I/O management & Disk scheduling:

Monitor

Television

Television is one of the common output devices which is present in each and every house. It portrays video and
audio files on the screen as the user handles the television. Nowadays, we are using plasma displays as compared to
CRT screens which we used earlier.

Printer

Printers are output devices that allow you to print information on paper. There are certain types of printers which
are described below.

 Impact Printers

 Character Printers

 Line Printers

 Non-Impact Printers

 Laser Printers

 Inkjet Printers

Printer
UNIT 4: I/O management & Disk scheduling:
Impact Printer

Characters are printed on the ribbon, which is subsequently crushed against the paper, in impact printers. The
following are the characteristics of impact printers:

 Exceptionally low consumable cost.

 Quite noisy

 Because of its low cost, it is ideal for large-scale printing.

 To create an image, there is physical contact with the paper.

Character Printers

Character Printer has the capability to print only one character at a time. It is of two types.

 Dot Matrix Printer

 Daisy Wheel

Line Printers

Line Printers are printers that have the capability to print one line at a time. It is of two types.

 Drum Printer

 Chain Printer

Non-Impact Printers

Characters are printed without the need for a ribbon in non-impact printers. Because these printers print a full page
at a time, they’re also known as Page Printers. The following are the characteristics of non-impact printers:

 Faster

 They don’t make a lot of noise.

 Excellent quality

 Supports a variety of typefaces and character sizes

Laser Printers

Laser Printers use laser lights for producing dots which will produce characters on the page.

Inkjet Printers

Inkjet printers are printers that use spray technology for printing papers. High-quality papers are produced in an
Inkjet printer. They also do color printing.

Speakers

Speakers are devices that produce sound after getting a command from a computer. Nowadays, speakers come with
wireless technology also like Bluetooth speakers.

Projector

Projectors are optical devices that have the work to show visuals on both types of screens, stationary and moving
both. It helps in displaying images on a big screen. Projectors are generally used in theatres, auditoriums, etc.

Plotter
UNIT 4: I/O management & Disk scheduling:
Plotter is a device that helps in making graphics or other images to give a real view. A graphic card is mandatorily
required to use these devices. These are the pen-like devices that help in generating exact designs on the computer.

Braille Reader

Braille Reader is a very important device that is used by blind users. It helps people with low vision or no vision to
recognize the data by running their fingers over the device to understand easily. It is a very important device for
blind persons as it gives them the comfort to understand the letters, alphabets, etc which helps them in study.

Video Card

A video Card is a device that is fitted into the motherboard of the computer. It helps in improvising digital content in
output devices. It is an important tool that helps people in using multiple devices.

Global Positioning System (GPS)

Global Positioning System helps the user in terms of directions, as it uses satellite technology to track the
geometrical locations of the users. With continuous latitudinal and longitudinal calculations, GPS gives accurate
results. Nowadays, all smart devices have inbuilt GPS.

Headphones

Headphones are just like a speaker, which is generally used by a single person or it is a single-person usable device
and is not commonly used in large areas. These are also called headsets having a lower sound frequency.

The Input and Output Devices of a Computer

There are so many devices that contain the characteristics of both input and output. They can perform both
operations as they receive data and provide results. Some of them are mentioned below.

USB Drive

USB Drive is one of the devices which perform both input and output operations as a USB Drive helps in receiving
data from a device and sending it to other devices.

Modem

Modems are one of the important devices that helps in transmitting data using telephonic lines.

CD and DVD

CD and DVD are the most common device that helps in saving data from one computer in a particular format and
send data to other devices which works as an input device to the computer.

Headset

The headset consists of a speaker and microphone where a speaker is an output device and a microphone works as
an input device.

Facsimile

A facsimile is a fax machine that consists of a scanner and printer, where the scanner works as an input device and
the printer works as an output device.

Design and Implementation in Operating System


The design of an operating system is a broad and complex topic that touches on many aspects of computer science.
This article will cover the design of operating systems in general and then focus on the implementation aspect.
UNIT 4: I/O management & Disk scheduling:
Design Goals:

Design goals are the objectives of the operating system. They must be met to fulfill design requirements and they
can be used to evaluate the design. These goals may not always be technical, but they often have a direct impact on
how users perceive their experience with an operating system. While designers need to identify all design goals and
prioritize them, they also need to ensure that these goals are compatible with each other as well as compatible with
user expectations or expert advice

Designers also need to identify all possible ways in which their designs could conflict with other parts of their
systems—and then prioritize those potential conflicts based on cost-benefit analysis (CBA). This process allows for
better decision-making about what features make sense for inclusion into final products versus those which would
require extensive rework later down the road. It’s also important to note that CBA is not just about financial costs; it
can also include other factors like user experience, time to market, and the impact on other systems.

The process of identifying design goals, conflicts, and priorities is often referred to as “goal-driven design.” The goal
of this approach is to ensure that each design decision is made with the best interest of users and other stakeholders
in mind.

Mechanisms and Policies:

An operating system is a set of software components that manage a computer’s resources and provide overall
system management.

Mechanisms and policies are the two main components of an operating system. Mechanisms handle low-
level functions such as scheduling, memory management, and interrupt handling; policies handle higher-level
functions such as resource management, security, and reliability. A well-designed OS should provide both
mechanisms and policies for each component in order for it to be successful at its task:

Mechanisms should ensure that applications have access to appropriate hardware resources (seats). They should
also make sure that applications don’t interfere with each other’s use of these resources (for example through
mutual exclusion).

Policies determine how processes will interact with one another when they’re running simultaneously on multiple
CPUs within a single machine instance – what processor affinity should occur during multitasking operations? Should
all processes be allowed access simultaneously or just those belonging specifically within group ‘A’?’

These are just some of the many questions that policies must answer. The OS is responsible for enforcing these
mechanisms and policies, as well as handling exceptions when they occur. The operating system also provides a
number of services to applications, such as file access and networking capabilities.

The operating system is also responsible for making sure that all of these tasks are done efficiently and in a timely
manner. The OS provides applications with access to the underlying hardware resources and ensures that they’re
properly utilized by the application. It also handles any exceptions that occur during execution so that they don’t
cause the entire system to crash.

Implementation:

Implementation is the process of writing source code in a high-level programming language, compiling it into object
code, and then interpreting (executing) this object code by means of an interpreter. The purpose of an operating
system is to provide services to users while they run applications on their computers.

The main function of an operating system is to control the execution of programs. It also provides services such as
memory management, interrupt handling, and file system access facilities so that programs can be better utilized by
users or other devices attached to the system.

An operating system is a program or software that controls the computer’s hardware and resources. It acts as an
intermediary between applications, users, and the computer’s hardware. It manages the activities of all programs
running on a computer without any user intervention.
UNIT 4: I/O management & Disk scheduling:
The operating system performs many functions such as managing the computer’s memory, enforcing security
policies, and controlling peripheral devices. It also provides a user interface that allows users to interact with their
computers.

The operating system is typically stored in ROM or flash memory so it can be run when the computer is turned on.
The first operating systems were designed to control mainframe computers. They were very large and complex,
consisting of millions of lines of code and requiring several people to develop them.

Today, operating systems are much smaller and easier to use. They have been designed to be modular so they can
be customized by users or developers.

There are many different types of operating systems:

1. Graphical user interfaces (GUIs) like Microsoft Windows and Mac OS.

2. Command line interfaces like Linux or UNIX

3. Real-time operating systems that control industrial and scientific equipment

4. Embedded operating systems are designed to run on a single computer system without needing an external
display or keyboard.

An operating system is a program that controls the execution of computer programs and provides services to the
user.

It is responsible for managing computer hardware resources and providing common services for all programs
running on the computer. An operating system also facilitates user interaction with the computer.

In addition to these basic functions, an operating system manages resources such as memory, input/output devices,
file systems, and other components of a computer system’s hardware architecture (hardware). It does not manage
application software or its data; this responsibility resides with individual applications themselves or their respective
developers via APIs provided by each application’s interfaces with their respective environments (e.g., Java VM).

The operating system is the most important component of a computer, as it allows users to interact with all of the
other components. The operating system provides access to hardware resources such as storage devices and
printers, as well as making sure that programs are running correctly and coordinating their activities.

The design and implementation of an operating system is a complex process that involves many different disciplines.
The goal is to provide users with a reliable, efficient, and convenient computing environment, so as to make their
work more efficient.

Design Issues of Distributed System


Distributed System is a collection of autonomous computer systems that are physically separated but are connected
by a centralized computer network that is equipped with distributed system software. These are used in numerous
applications, such as online gaming, web applications, and cloud computing. However, creating a distributed system
is not simple, and there are a number of design considerations to take into account. The following are some of the
major design issues of distributed systems:

Design issues of the distributed system –

1. Heterogeneity: Heterogeneity is applied to the network, computer hardware, operating system, and
implementation of different developers. A key component of the heterogeneous distributed system client-
server environment is middleware. Middleware is a set of services that enables applications and end-user to
interact with each other across a heterogeneous distributed system.

2. Openness: The openness of the distributed system is determined primarily by the degree to which new
resource-sharing services can be made available to the users. Open systems are characterized by the fact
UNIT 4: I/O management & Disk scheduling:
that their key interfaces are published. It is based on a uniform communication mechanism and published
interface for access to shared resources. It can be constructed from heterogeneous hardware and software.

3. Scalability: The scalability of the system should remain efficient even with a significant increase in the
number of users and resources connected. It shouldn’t matter if a program has 10 or 100 nodes;
performance shouldn’t vary. A distributed system’s scaling requires consideration of a number of elements,
including size, geography, and management.

4. Security: The security of an information system has three components Confidentially, integrity, and
availability. Encryption protects shared resources and keeps sensitive information secrets when transmitted.

5. Failure Handling: When some faults occur in hardware and the software program, it may produce incorrect
results or they may stop before they have completed the intended computation so corrective measures
should to implemented to handle this case. Failure handling is difficult in distributed systems because the
failure is partial i, e, some components fail while others continue to function.

6. Concurrency: There is a possibility that several clients will attempt to access a shared resource at the same
time. Multiple users make requests on the same resources, i.e. read, write, and update. Each resource must
be safe in a concurrent environment. Any object that represents a shared resource in a distributed system
must ensure that it operates correctly in a concurrent environment.

7. Transparency: Transparency ensures that the distributed system should be perceived as a single entity by
the users or the application programmers rather than a collection of autonomous systems, which is
cooperating. The user should be unaware of where the services are located and the transfer from a local
machine to a remote one should be transparent.

I/O buffering and its Various Techniques


A buffer is a memory area that stores data being transferred between two devices or between a device and an
application.

Uses of I/O Buffering :

 Buffering is done to deal effectively with a speed mismatch between the producer and consumer of the data
stream.

 A buffer is produced in main memory to heap up the bytes received from modem.

 After receiving the data in the buffer, the data get transferred to disk from buffer in a single operation.

 This process of data transfer is not instantaneous, therefore the modem needs another buffer in order to
store additional incoming data.

 When the first buffer got filled, then it is requested to transfer the data to disk.

 The modem then starts filling the additional incoming data in the second buffer while the data in the first
buffer getting transferred to disk.

 When both the buffers completed their tasks, then the modem switches back to the first buffer while the
data from the second buffer get transferred to the disk.

 The use of two buffers disintegrates the producer and the consumer of the data, thus minimizes the time
requirements between them.

 Buffering also provides variations for devices that have different data transfer sizes.

Types of various I/O buffering techniques :

1. Single buffer :
A buffer is provided by the operating system to the system portion of the main memory.
UNIT 4: I/O management & Disk scheduling:
Block oriented device –

 System buffer takes the input.

 After taking the input, the block gets transferred to the user space by the process and then the process
requests for another block.

 Two blocks works simultaneously, when one block of data is processed by the user process, the next block is
being read in.

 OS can swap the processes.

 OS can record the data of system buffer to user processes.

Stream oriented device –

 Line- at a time operation is used for scroll made terminals. User inputs one line at a time, with a carriage
return signaling at the end of a line.

 Byte-at a time operation is used on forms mode, terminals when each keystroke is significant.

2. Double buffer :

Block oriented –

 There are two buffers in the system.

 One buffer is used by the driver or controller to store data while waiting for it to be taken by higher level of
the hierarchy.

 Other buffer is used to store data from the lower level module.

 Double buffering is also known as buffer swapping.

 A major disadvantage of double buffering is that the complexity of the process get increased.

 If the process performs rapid bursts of I/O, then using double buffering may be deficient.

Stream oriented –

 Line- at a time I/O, the user process need not be suspended for input or output, unless process runs ahead
of the double buffer.

 Byte- at a time operations, double buffer offers no advantage over a single buffer of twice the length.
UNIT 4: I/O management & Disk scheduling:
3. Circular buffer :

 When more than two buffers are used, the collection of buffers is itself referred to as a circular buffer.

 In this, the data do not directly passed from the producer to the consumer because the data would change
due to overwriting of buffers before they had been consumed.

 The producer can only fill up to buffer i-1 while data in buffer i is waiting to be consumed.

Buffering in OS
In Operating Systems I/O operations are one of the most fundamental tasks that is needed to be carried out
correctly and with the utmost efficiency. One of the techniques that we can use to ensure the utmost efficiency of
the I/O Operations is Buffering. So, Buffering is a process in which the data is stored in a buffer or cache, which
makes this stored data more accessible than the original source. Buffer is an area in memory that is used to hold the
data that is being transmitted from one place to another and store the data temporarily.

There are a number of data storage devices that are used in a system, like Hard Disks, network devices, pen drives,
etc. So, there might be some waiting time faced by the processes or applications that are attempting to access that
data from the storage devices. This problem is mainly caused when the devices from where device is slow or have
low latency.

This problem is significantly solved using Buffering, as in this process the buffer acts as an intermediate between the
storage device and the processes/applications. In this process, the data is already transferred to the Buffer so the
data retrieval can be done from it which significantly reduces the waiting time and hence improves the performance
of the system.

Types of Buffering in OS

There are mainly three types of Buffering that are used in OS:

1. Single Buffering

2. Double Buffering

3. Circular Buffering

Single Buffering

This is the simplest type of Buffering where only one system buffer is allocated by the Operating System for the
system to work with. The producer(I/O device) produces only one block of data in the buffer for the consumer to
receive. After one complete transaction of one block of data, the buffer memory again produces the buffer data.
UNIT 4: I/O management & Disk scheduling:

Double Buffering

This is an upgrade over Single Buffering as instead of using one buffer data here two are used. The working of this is
similar to the previous one, the difference is that the data is first moved to the first buffer then it is moved to the
second buffer. Then retrieved by the consumer end. Here on one hand the data is inserted into one buffer while the
data in the other buffer is processed into the other one.

Circular Buffering

Double Buffering is upgraded to this, in this process more than two buffers are used. The mechanism which was used
earlier is a bit enhanced here, where one buffer is used to insert the data while the next one of it used to process the
data that was earlier inserted. This chain of processing is done until the last buffer in the queue and then the data is
retrieved from the last buffer by the consumer. This mechanism is used where we need faster data transfers and
more bulky data is transferred.
UNIT 4: I/O management & Disk scheduling:

Function of Buffering in OS

 Synchronization: This process increases the synchronization of different devices that are connected, so the
system’s performance also improves.

 Smoothening: The input and output devices have different operating speeds and Buffer data block sizes, this
process encapsulates the difference and ensures a smooth operation.

 Efficient Usage: Using this processing technique the system overhead and the inefficient usage of the system
resources.

How Buffering in OS works?

The different types of Buffering work a little differently as explained in brief earlier, but the baseline working is the
same in all the types. This work is given further:

 The operating system starts with allocating memory for creating the Buffers which can be one or more, the
size of each one depends on requirements.

 Then the data which is read from the input device is stored in the buffer, as the buffer act as the
intermediate stage between the sender and receiver.

 The details of all the buffers that are present in the operating system, details include information like the
amount of data stored in the buffer, etc. This information helps the Operating system to manage all the
buffers.

 The data is processed and retrieved by the CPU, using this technique the CPU works independently and
improves the device’s speed. This process helps in the Asynchronous functioning of the CPU in the device.

 Then the Data in the Buffer is Flushed i.e., it is deleted and the memory is freed. The temporary memory
space is further used.
UNIT 4: I/O management & Disk scheduling:

Advantages of Buffering

 Buffering significantly reduces the waiting time for a process or application to access a device in the system

 Smoothens the I/O operations between the different devices that are connected to the system.

 Using Buffer number of calls needed for carrying out an operation, so it increases the overall performance of
the system.

 Buffering helps cut down on the number of I/O operations that are needed to access the desired data.

Disadvantages of Buffering

 Buffers/Temporary memory that is used to assign data while transferring takes up a lot of memory in a long
process.

 Most of the time the exact size of the data going to be transferred is unpredictable so more memory is
assigned for every data and most of the time the extra space goes wasted.

 Due to unpredictability sometimes more data is stored on the Buffer than it can store which leads to Buffer
Overflow and data corruption.

 In some situations, Buffers can result in a delay between the read and write of the data in the memory and
the processing of the data.
UNIT 4: I/O management & Disk scheduling:
Difference between Spooling and Buffering
There are two ways by which Input/output subsystems can improve the performance and efficiency of the computer
by using a memory space in the main memory or on the disk and these two are spooling and buffering.

Spooling –

Spooling stands for Simultaneous peripheral operation online. A spool is similar to buffer as it holds the jobs for a
device until the device is ready to accept the job. It considers disk as a huge buffer that can store as many jobs for
the device till the output devices are ready to accept them.

Buffering –

The main memory has an area called buffer that is used to store or hold the data temporarily that is being
transmitted either between two devices or between a device or an application. Buffering is an act of storing data
temporarily in the buffer. It helps in matching the speed of the data stream between the sender and the receiver. If
the speed of the sender’s transmission is slower than the receiver, then a buffer is created in the main memory of
the receiver, and it accumulates the bytes received from the sender and vice versa.

The basic difference between Spooling and Buffering is that Spooling overlaps the input/output of one job with the
execution of another job while the buffering overlaps the input/output of one job with the execution of the same
job.

Differences between Spooling and Buffering –

 The key difference between spooling and buffering is that Spooling can handle the input/output of one job
along with the computation of another job at the same time while buffering handles input/output of one job
along with its computation.

 Spooling stands for Simultaneous Peripheral Operation online. Whereas buffering is not an acronym.

 Spooling is more efficient than buffering, as spooling can overlap processing two jobs at a time.

 Buffering uses limited area in main memory while Spooling uses the disk as a huge buffer.

Comparison chart –

SPOOLING BUFFERING

It overlap the input/output of one job with It overlaps the input/output of one job
Basic Difference
the execution of another job. with the execution of the same job.

Full form (stands


Simultaneous peripheral operation online No full form
for)

Efficiency Spooling is more efficient than buffering. Buffering is less efficient than spooling.

Consider Size It considers disk as a huge spool or buffer. Buffer is a limited area in main memory.
UNIT 4: I/O management & Disk scheduling:
SPOOLING BUFFERING

Remote
It can process data at remote places. It does not support remote processing.
Processing

Implemented through software or


Implemented using spoolers which manage
hardware-based mechanisms such as
Implementation input/output requests and allocate
circular buffers or FIFO queues
resources as needed

Can handle large amounts of data since Limited by the size of memory available for
Capacity spooled data is stored on disk or other buffering
external storage

Errors can occur if buffer overflow


Since data is stored on external storage,
happens, which can cause data loss or
Error handling spooling can help recover from system
corruption
crashes or other errors

Less complex than spooling since buffering


More complex than buffering since spooling
is a simpler technique for managing data
Complexity requires additional software to manage
transfer
input/output requests

FCFS Disk Scheduling Algorithms


Prerequisite: Disk scheduling algorithms.
Given an array of disk track numbers and initial head position, our task is to find the total number of seek operations
done to access all the requested tracks if First Come First Serve (FCFS) disk scheduling algorithm is used.

First Come First Serve (FCFS)


FCFS is the simplest disk scheduling algorithm. As the name suggests, this algorithm entertains requests in the order
they arrive in the disk queue. The algorithm looks very fair and there is no starvation (all requests are serviced
sequentially) but generally, it does not provide the fastest service.

Algorithm:

1. Let Request array represents an array storing indexes of tracks that have been requested in ascending order
of their time of arrival. ‘head’ is the position of disk head.

2. Let us one by one take the tracks in default order and calculate the absolute distance of the track from the
head.

3. Increment the total seek count with this distance.

4. Currently serviced track position now becomes the new head position.

5. Go to step 2 until all tracks in request array have not been serviced.

Example:
UNIT 4: I/O management & Disk scheduling:
Input:

Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}

Initial head position = 50

Output:

Total number of seek operations = 510

Seek Sequence is

176

79

34

60

92

11

41

114

The following chart shows the sequence in which requested tracks are serviced using FCFS.

Therefore, the total seek count is calculated as:

= (176-50)+(176-79)+(79-34)+(60-34)+(92-60)+(92-11)+(41-11)+(114-41)

= 510

Implementation:
Implementation of FCFS is given below. Note that distance is used to store absolute distance between head and
current track position.

 C++

 C

 Java
UNIT 4: I/O management & Disk scheduling:
 Python3

 C#

 Javascript

// C++ program to demonstrate

// FCFS Disk Scheduling algorithm

#include <stdio.h>

#include <math.h>

int size = 8;

void FCFS(int arr[],int head)

int seek_count = 0;

int cur_track, distance;

for(int i=0;i<size;i++)

cur_track = arr[i];

// calculate absolute distance

distance = fabs(head - cur_track);

// increase the total count

seek_count += distance;

// accessed track is now new head

head = cur_track;

printf("Total number of seek operations: %d\n",seek_count);

// Seek sequence would be the same


UNIT 4: I/O management & Disk scheduling:
// as request array sequence

printf("Seek Sequence is\n");

for (int i = 0; i < size; i++) {

printf("%d\n",arr[i]);

//Driver code

int main()

// request array

int arr[8] = { 176, 79, 34, 60, 92, 11, 41, 114 };

int head = 50;

FCFS(arr,head);

return 0;

//This code is contributed by Pratham Kashyap

Output:

Total number of seek operations = 510

Seek Sequence is

176

79

34

60

92

11

41

114
UNIT 4: I/O management & Disk scheduling:
SCAN (Elevator) Disk Scheduling Algorithms
Given an array of disk track numbers and initial head position, our task is to find the total number of seek operations
to access all the requested tracks if the SCAN disk scheduling algorithm is used.

In the SCAN Disk Scheduling Algorithm, the head starts from one end of the disk and moves towards the other end,
servicing requests in between one by one and reaching the other end. Then the direction of the head is reversed and
the process continues as the head continuously scans back and forth to access the disk. So, this algorithm works as
an elevator and is hence also known as the elevator algorithm. As a result, the requests at the midrange are serviced
more and those arriving behind the disk arm will have to wait.

Advantages of SCAN (Elevator) Algorithm

 This algorithm is simple and easy to understand.

 SCAN algorithm has no starvation.

 This algorithm is better than the FCFS Disk Scheduling algorithm.

Disadvantages of the SCAN (Elevator) Algorithm

 More complex algorithm to implement.

 This algorithm is not fair because it causes a long waiting time for the cylinders just visited by the head.

 It causes the head to move till the end of the disk in this way the requests arriving ahead of the arm position
would get immediate service but some other requests that arrive behind the arm position will have to wait
for the request to complete.

Algorithm

Step 1: Let the Request array represents an array storing indexes of tracks that have been requested in ascending
order of their time of arrival. ‘head’ is the position of the disk head.

Step 2: Let direction represents whether the head is moving towards left or right.

Step 3: In the direction in which the head is moving, service all tracks one by one.

Step 4: Calculate the absolute distance of the track from the head.

Step 5: Increment the total seek count with this distance.

Step 6: Currently serviced track position now becomes the new head position.

Step 7: Go to step 3 until we reach one of the ends of the disk.

Step 8: If we reach the end of the disk reverse the direction and go to step 2 until all tracks in the request array have
not been serviced.

Example:

Input:
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50
Direction = left (We are moving from right to left)
Output:
Total number of seek operations = 226
Seek Sequence is
41
34
11
UNIT 4: I/O management & Disk scheduling:
0
60
79
92
114
176

The following chart shows the sequence in which requested tracks are serviced using SCAN.

SCAN Disk Scheduling Algorithm

Therefore, the total seek count is calculated as:

= (50-41) + (41-34) + (34-11) + (11-0) + (60-0) + (79-60) + (92-79) + (114-92) + (176-114)


= 226

Implementation

The implementation of SCAN is given below. Note that distance is used to store the absolute distance between the
head and the current track position. disk_size is the size of the disk. Vectors left and right store all the request tracks
on the left-hand side and the right-hand side of the initial head position respectively.

 C++

 Java

 Python3

 C#

 Javascript

// C++ program to demonstrate

// SCAN Disk Scheduling algorithm

#include <bits/stdc++.h>

using namespace std;


UNIT 4: I/O management & Disk scheduling:

int size = 8;

int disk_size = 200;

void SCAN(int arr[], int head, string direction)

int seek_count = 0;

int distance, cur_track;

vector<int> left, right;

vector<int> seek_sequence;

// appending end values

// which has to be visited

// before reversing the direction

if (direction == "left")

left.push_back(0);

else if (direction == "right")

right.push_back(disk_size - 1);

for (int i = 0; i < size; i++) {

if (arr[i] < head)

left.push_back(arr[i]);

if (arr[i] > head)

right.push_back(arr[i]);

// sorting left and right vectors

std::sort(left.begin(), left.end());

std::sort(right.begin(), right.end());

// run the while loop two times.

// one by one scanning right


UNIT 4: I/O management & Disk scheduling:
// and left of the head

int run = 2;

while (run--) {

if (direction == "left") {

for (int i = left.size() - 1; i >= 0; i--) {

cur_track = left[i];

// appending current track to seek sequence

seek_sequence.push_back(cur_track);

// calculate absolute distance

distance = abs(cur_track - head);

// increase the total count

seek_count += distance;

// accessed track is now the new head

head = cur_track;

direction = "right";

else if (direction == "right") {

for (int i = 0; i < right.size(); i++) {

cur_track = right[i];

// appending current track to seek sequence

seek_sequence.push_back(cur_track);

// calculate absolute distance

distance = abs(cur_track - head);

// increase the total count

seek_count += distance;
UNIT 4: I/O management & Disk scheduling:

// accessed track is now new head

head = cur_track;

direction = "left";

cout << "Total number of seek operations = "

<< seek_count << endl;

cout << "Seek Sequence is" << endl;

for (int i = 0; i < seek_sequence.size(); i++) {

cout << seek_sequence[i] << endl;

// Driver code

int main()

// request array

int arr[size] = { 176, 79, 34, 60,

92, 11, 41, 114 };

int head = 50;

string direction = "left";

SCAN(arr, head, direction);

return 0;

}
UNIT 4: I/O management & Disk scheduling:
Output

Total number of Seek Operations = 226

Seek Sequence: 41, 34, 11, 0, 60, 79, 92, 114, 176

Time Complexity: O(N * logN)

Auxiliary Space: O(N)

C-SCAN Disk Scheduling Algorithm


Given an array of disk track numbers and initial head position, our task is to find the total number of seek operations
to access all the requested tracks if a C-SCAN Disk Scheduling algorithm is used.

The Circular SCAN (C-SCAN) Scheduling Algorithm is a modified version of the SCAN Disk Scheduling Algorithm that
deals with the inefficiency of the SCAN algorithm by servicing the requests more uniformly. Like SCAN (Elevator
Algorithm), C-SCAN moves the head from one end servicing all the requests to the other end. However, as soon as
the head reaches the other end, it immediately returns to the beginning of the disk without servicing any requests
on the return trip (see chart below) and starts servicing again once reaches the beginning. This is also known as the
“Circular Elevator Algorithm” as it essentially treats the cylinders as a circular list that wraps around from the final
cylinder to the first one.

Advantages of C-SCAN (Circular Elevator) Disk Scheduling Algorithm

 Works well with moderate to heavy loads.

 It provides better response time and uniform waiting time.

Disadvantages of C-SCAN (Circular Elevator) Disk Scheduling Algorithm

 May not be fair to service requests for tracks at the extreme end.

 It has more seek movements as compared to the SCAN Algorithm.

Algorithm

Step 1: Let the Request array represents an array storing indexes of tracks that have been requested in ascending
order of their time of arrival. ‘head’ is the position of the disk head.

Step 2: The head services only in the right direction from 0 to the disk size.

Step 3: While moving in the left direction do not service any of the tracks.

Step 4: When we reach the beginning(left end) reverse the direction.

Step 5: While moving in the right direction it services all tracks one by one.

Step 6: While moving in the right direction calculate the absolute distance of the track from the head.

Step 7: Increment the total seek count with this distance.

Step 8: Currently serviced track position now becomes the new head position.

Step 9: Go to step 6 until we reach the right end of the disk.

Step 9: If we reach the right end of the disk reverse the direction and go to step 3 until all tracks in the request array
have not been serviced.

Example:
UNIT 4: I/O management & Disk scheduling:
Input:
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50
Direction = right(We are moving from left to right)
Output:
Initial position of head: 50
Total number of seek operations = 389
Seek Sequence: 60, 79, 92, 114, 176, 199, 0, 11, 34, 41

The following chart shows the sequence in which requested tracks are serviced using SCAN.

C-SCAN Disk Scheduling Algorithm

Therefore, the total seek count is calculated as:

= (60-50) + (79-60) + (92-79) + (114-92) + (176-114) + (199-176) + (199-0) + (11-0) + (34-11) + (41-34)
= 389

Implementation

The implementation of the C-SCAN algorithm is given below.

Note: The distance variable is used to store the absolute distance between the head and the current track position.
disk_size is the size of the disk. Vectors left and right store all the request tracks on the left-hand side and the right-
hand side of the initial head position respectively.

 C++

 Java

 Python3

 C#

 Javascript

// C++ program to demonstrate


UNIT 4: I/O management & Disk scheduling:
// C-SCAN Disk Scheduling algorithm

#include <bits/stdc++.h>

using namespace std;

// Code by Vikram Chaurasia

int size = 8;

int disk_size = 200;

void CSCAN(int arr[], int head)

int seek_count = 0;

int distance, cur_track;

vector<int> left, right;

vector<int> seek_sequence;

// appending end values

// which has to be visited

// before reversing the direction

left.push_back(0);

right.push_back(disk_size - 1);

// tracks on the left of the

// head will be serviced when

// once the head comes back

// to the beginning (left end).

for (int i = 0; i < size; i++) {

if (arr[i] < head)

left.push_back(arr[i]);

if (arr[i] > head)

right.push_back(arr[i]);

}
UNIT 4: I/O management & Disk scheduling:

// sorting left and right vectors

std::sort(left.begin(), left.end());

std::sort(right.begin(), right.end());

// first service the requests

// on the right side of the

// head.

for (int i = 0; i < right.size(); i++) {

cur_track = right[i];

// appending current track to seek sequence

seek_sequence.push_back(cur_track);

// calculate absolute distance

distance = abs(cur_track - head);

// increase the total count

seek_count += distance;

// accessed track is now new head

head = cur_track;

// once reached the right end

// jump to the beginning.

head = 0;

// adding seek count for head returning from 199 to 0

seek_count += (disk_size - 1);

// Now service the requests again

// which are left.


UNIT 4: I/O management & Disk scheduling:
for (int i = 0; i < left.size(); i++) {

cur_track = left[i];

// appending current track to seek sequence

seek_sequence.push_back(cur_track);

// calculate absolute distance

distance = abs(cur_track - head);

// increase the total count

seek_count += distance;

// accessed track is now the new head

head = cur_track;

cout << "Total number of seek operations = "

<< seek_count << endl;

cout << "Seek Sequence is" << endl;

for (int i = 0; i < seek_sequence.size(); i++) {

cout << seek_sequence[i] << endl;

// Driver code

int main()

// request array

int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };
UNIT 4: I/O management & Disk scheduling:
int head = 50;

cout << "Initial position of head: " << head << endl;

CSCAN(arr, head);

return 0;

Output

Initial Position of Head: 50


Total Number of Seek Operations = 389
Seek Sequence: 60, 79, 92, 114, 176, 199, 0, 11, 34, 41

Program for SSTF Disk Scheduling Algorithm


Given an array of disk track numbers and initial head position, our task is to find the total number of seek operations
done to access all the requested tracks if Shortest Seek Time First (SSTF) is a disk scheduling algorithm is used.

The basic idea is the tracks that are closer to the current disk head position should be serviced first in order to
minimize the seek operations is basically known as Shortest Seek Time First (SSTF).

Advantages of Shortest Seek Time First (SSTF)

 Better performance than the FCFS scheduling algorithm.

 It provides better throughput.

 This algorithm is used in Batch Processing systems where throughput is more important.

 It has a less average response and waiting time.

Disadvantages of Shortest Seek Time First (SSTF)

 Starvation is possible for some requests as it favours easy-to-reach requests and ignores the far-away
processes.

 There is a lack of predictability because of the high variance of response time.

 Switching direction slows things down.

Algorithm

Step 1: Let the Request array represents an array storing indexes of tracks that have been requested. ‘head’ is the
position of the disk head.

Step 2: Find the positive distance of all tracks in the request array from the head.

Step 3: Find a track from the requested array which has not been accessed/serviced yet and has a minimum distance
from the head.

Step 4: Increment the total seek count with this distance.

Step 5: Currently serviced track position now becomes the new head position.
UNIT 4: I/O management & Disk scheduling:
Step 6: Go to step 2 until all tracks in the request array have not been serviced.

Example:

Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50

The following chart shows the sequence in which requested tracks are serviced using SSTF.

Therefore, the total seek count is calculated as:

SSTF (Shortest Seek Time First)

= (50-41)+(41-34)+(34-11)+(60-11)+(79-60)+(92-79)+(114-92)+(176-114)
= 204
which can also be directly calculated as: (50-11) + (176-11)

Implementation

The implementation of SSTF is given below. Note that we have made a node class having 2 members. ‘distance’ is
used to store the distance between the head and the track position. ‘accessed’ is a boolean variable that tells
whether the track has been accessed/serviced before by the disk head or not.

 C++

 Java

 Python3

 C#

 Javascript
UNIT 4: I/O management & Disk scheduling:
// C++ program for implementation of

// SSTF disk scheduling

#include <bits/stdc++.h>

using namespace std;

// Calculates difference of each

// track number with the head position

void calculatedifference(int request[], int head,

int diff[][2], int n)

for(int i = 0; i < n; i++)

diff[i][0] = abs(head - request[i]);

// Find unaccessed track which is

// at minimum distance from head

int findMIN(int diff[][2], int n)

int index = -1;

int minimum = 1e9;

for(int i = 0; i < n; i++)

if (!diff[i][1] && minimum > diff[i][0])

minimum = diff[i][0];

index = i;

return index;
UNIT 4: I/O management & Disk scheduling:
}

void shortestSeekTimeFirst(int request[],

int head, int n)

if (n == 0)

return;

// Create array of objects of class node

int diff[n][2] = { { 0, 0 } };

// Count total number of seek operation

int seekcount = 0;

// Stores sequence in which disk access is done

int seeksequence[n + 1] = {0};

for(int i = 0; i < n; i++)

seeksequence[i] = head;

calculatedifference(request, head, diff, n);

int index = findMIN(diff, n);

diff[index][1] = 1;

// Increase the total count

seekcount += diff[index][0];

// Accessed track is now new head

head = request[index];

}
UNIT 4: I/O management & Disk scheduling:
seeksequence[n] = head;

cout << "Total number of seek operations = "

<< seekcount << endl;

cout << "Seek sequence is : " << "\n";

// Print the sequence

for(int i = 0; i <= n; i++)

cout << seeksequence[i] << "\n";

// Driver code

int main()

int n = 8;

int proc[n] = { 176, 79, 34, 60, 92, 11, 41, 114 };

shortestSeekTimeFirst(proc, 50, n);

return 0;

// This code is contributed by manish19je0495

Output

Total number of seek operations = 204


Seek Sequence: 50, 41, 34, 11, 60, 79, 92, 114, 176

Time Complexity: O(N^2)

Auxiliary Space: O(N)


UNIT 4: I/O management & Disk scheduling:
RAID (Redundant Arrays of Independent Disks)
RAID is a technique that makes use of a combination of multiple disks instead of using a single disk for increased
performance, data redundancy, or both. The term was coined by David Patterson, Garth A. Gibson, and Randy Katz
at the University of California, Berkeley in 1987.

Why Data Redundancy?

Data redundancy, although taking up extra space, adds to disk reliability. This means, that in case of disk failure, if
the same data is also backed up onto another disk, we can retrieve the data and go on with the operation. On the
other hand, if the data is spread across multiple disks without the RAID technique, the loss of a single disk can affect
the entire data.

Key Evaluation Points for a RAID System

 Reliability: How many disk faults can the system tolerate?

 Availability: What fraction of the total session time is a system in uptime mode, i.e. how available is the
system for actual use?

 Performance: How good is the response time? How high is the throughput (rate of processing work)? Note
that performance contains a lot of parameters and not just the two.

 Capacity: Given a set of N disks each with B blocks, how much useful capacity is available to the user?

RAID is very transparent to the underlying system. This means, that to the host system, it appears as a single big disk
presenting itself as a linear array of blocks. This allows older technologies to be replaced by RAID without making too
many changes to the existing code.

Different RAID Levels

1. RAID-0 (Stripping)

2. RAID-1 (Mirroring)

3. RAID-2 (Bit-Level Stripping with Dedicated Parity)

4. RAID-3 (Byte-Level Stripping with Dedicated Parity)

5. RAID-4 (Block-Level Stripping with Dedicated Parity)

6. RAID-5 (Block-Level Stripping with Distributed Parity)

7. RAID-6 (Block-Level Stripping with two Parity Bits)


UNIT 4: I/O management & Disk scheduling:

Raid Controller

1. RAID-0 (Stripping)

 Blocks are “stripped” across disks.

RAID-0

 In the figure, blocks “0,1,2,3” form a stripe.


UNIT 4: I/O management & Disk scheduling:
 Instead of placing just one block into a disk at a time, we can work with two (or more) blocks placed into a
disk before moving on to the next one.

Raid-0

Evaluation

 Reliability: 0
There is no duplication of data. Hence, a block once lost cannot be recovered.

 Capacity: N*B
The entire space is being used to store data. Since there is no duplication, N disks each having B blocks are
fully utilized.

Advantages

1. It is easy to implement.

2. It utilizes the storage capacity in a better way.

Disadvantages

1. A single drive loss can result in the complete failure of the system.

2. Not a good choice for a critical system.

2. RAID-1 (Mirroring)

 More than one copy of each block is stored in a separate disk. Thus, every block has two (or more) copies,
lying on different disks.
UNIT 4: I/O management & Disk scheduling:

Raid-1

 The above figure shows a RAID-1 system with mirroring level 2.

 RAID 0 was unable to tolerate any disk failure. But RAID 1 is capable of reliability.

Evaluation

Assume a RAID system with mirroring level 2.

 Reliability: 1 to N/2
1 disk failure can be handled for certain because blocks of that disk would have duplicates on some other
disk. If we are lucky enough and disks 0 and 2 fail, then again this can be handled as the blocks of these disks
have duplicates on disks 1 and 3. So, in the best case, N/2 disk failures can be handled.

 Capacity: N*B/2
Only half the space is being used to store data. The other half is just a mirror of the already stored data.

Advantages

1. It covers complete redundancy.

2. It can increase data security and speed.

Disadvantages

1. It is highly expensive.

2. Storage capacity is less.

3. RAID-2 (Bit-Level Stripping with Dedicated Parity)


UNIT 4: I/O management & Disk scheduling:
 In Raid-2, the error of the data is checked at every bit level. Here, we use Hamming Code Parity Method to
find the error in the data.

 It uses one designated drive to store parity.

 The structure of Raid-2 is very complex as we use two disks in this technique. One word is used to store bits
of each word and another word is used to store error code correction.

 It is not commonly used.

Advantages

1. In case of Error Correction, it uses hamming code.

2. It Uses one designated drive to store parity.

Disadvantages

1. It has a complex structure and high cost due to extra drive.

2. It requires an extra drive for error detection.

4. RAID-3 (Byte-Level Stripping with Dedicated Parity)

 It consists of byte-level striping with dedicated parity striping.

 At this level, we store parity information in a disc section and write to a dedicated parity drive.

 Whenever failure of the drive occurs, it helps in accessing the parity drive, through which we can reconstruct
the data.
UNIT 4: I/O management & Disk scheduling:
Raid-3

 Here Disk 3 contains the Parity bits for Disk 0, Disk 1, and Disk 2. If data loss occurs, we can construct it with
Disk 3.

Advantages

1. Data can be transferred in bulk.

2. Data can be accessed in parallel.

Disadvantages

1. It requires an additional drive for parity.

2. In the case of small-size files, it performs slowly.

5. RAID-4 (Block-Level Stripping with Dedicated Parity)

 Instead of duplicating data, this adopts a parity-based approach.

Raid-4

 In the figure, we can observe one column (disk) dedicated to parity.

 Parity is calculated using a simple XOR function. If the data bits are 0,0,0,1 the parity bit is XOR(0,0,0,1) = 1. If
the data bits are 0,1,1,0 the parity bit is XOR(0,1,1,0) = 0. A simple approach is that an even number of ones
results in parity 0, and an odd number of ones results in parity 1.
UNIT 4: I/O management & Disk scheduling:

Raid-4

 Assume that in the above figure, C3 is lost due to some disk failure. Then, we can recompute the data bit
stored in C3 by looking at the values of all the other columns and the parity bit. This allows us to recover lost
data.

Evaluation

 Reliability: 1
RAID-4 allows recovery of at most 1 disk failure (because of the way parity works). If more than one disk
fails, there is no way to recover the data.

 Capacity: (N-1)*B
One disk in the system is reserved for storing the parity. Hence, (N-1) disks are made available for data
storage, each disk having B blocks.

Advantages

1. It helps in reconstructing the data if at most one data is lost.

Disadvantages

1. It can’t help in reconstructing when more than one data is lost.

6. RAID-5 (Block-Level Stripping with Distributed Parity)

 This is a slight modification of the RAID-4 system where the only difference is that the parity rotates among
the drives.
UNIT 4: I/O management & Disk scheduling:

Raid-5

 In the figure, we can notice how the parity bit “rotates”.

 This was introduced to make the random write performance better.

Evaluation

 Reliability: 1
RAID-5 allows recovery of at most 1 disk failure (because of the way parity works). If more than one disk
fails, there is no way to recover the data. This is identical to RAID-4.

 Capacity: (N-1)*B
Overall, space equivalent to one disk is utilized in storing the parity. Hence, (N-1) disks are made available for
data storage, each disk having B blocks.

Advantages

1. Data can be reconstructed using parity bits.

2. It makes the performance better.

Disadvantages

1. Its technology is complex and extra space is required.

2. If both discs get damaged, data will be lost forever.

7. RAID-6 (Block-Level Stripping with two Parity Bits)


UNIT 4: I/O management & Disk scheduling:
 Raid-6 helps when there is more than one disk failure. A pair of independent parities are generated and
stored on multiple disks at this level. Ideally, you need four disk drives for this level.

 There are also hybrid RAIDs, which make use of more than one RAID level nested one after the other, to
fulfill specific requirements.

Raid-6

Advantages

1. Very high data Accessibility.

2. Fast read data transactions.

Disadvantages

1. Due to double parity, it has slow write data transactions.

2. Extra space is required.

Advantages of RAID

 Data redundancy: By keeping numerous copies of the data on many disks, RAID can shield data from disk
failures.

 Performance enhancement: RAID can enhance performance by distributing data over several drives,
enabling the simultaneous execution of several read/write operations.

 Scalability: RAID is scalable, therefore by adding more disks to the array, the storage capacity may be
expanded.
UNIT 4: I/O management & Disk scheduling:
 Versatility: RAID is applicable to a wide range of devices, such as workstations, servers, and personal PCs

Disadvantages of RAID

 Cost: RAID implementation can be costly, particularly for arrays with large capacities.

 Complexity: The setup and management of RAID might be challenging.

 Decreased performance: The parity calculations necessary for some RAID configurations, including RAID 5
and RAID 6, may result in a decrease in speed.

 Single point of failure: RAID is not a comprehensive backup solution, while offering data redundancy. The
array’s whole contents could be lost if the RAID controller malfunctions.

Cache Memory Performance


Types of Caches :

 L1 Cache : Cache built in the CPU itself is known as L1 or Level 1 cache. This type of cache holds most recent
data so when, the data is required again so the microprocessor inspects this cache first so it does not need
to go through main memory or Level 2 cache. The main significance behind above concept is “Locality of
reference”, according to which a location just accessed by the CPU has a higher probability of being required
again.

 L2 Cache : This type of cache resides on a separate chip next to the CPU also known as Level 2 Cache. This
cache stores recent used data that cannot be found in the L1 Cache. Some CPU’s has both L1 and L2 Cache
built-in and designate the separate cache chip as level 3 (L3) Cache.

Cache that is built into the CPU is faster than separate cache. Separate cache is faster than RAM. Built-in Cache
runs as a speed of a microprocessor.

 Disk Cache : It contains most recent read in data from the hard disk and this cache is much slower than RAM.

 Instruction Cache Vs Data Cache : Instruction or I-cache stores instructions only while Data or D-cache stores
only data. Distinguishing the stored data by this method recognizes the different access behavior pattern of
instructions and data. For example : The programs need to involve few write accesses, and they often exhibit
more temporal and spatial locality than the data they process.

 Unified Cache Vs Split Cache : A cache that stores both instructions and data is referred to as a unified
cache. A split cache on other hand, consist of two associated but largely independent units – An I-cache and
D-cache. This type of cache can also be designed to deal with two independent units differently.

The performance of the cache memory is measured in terms of a quantity called Hit Ratio. When the CPU refers to
the memory and reveals the word in the cache, it’s far stated that a hit has successfully occurred. If the word is not
discovered in the cache, then the CPU refers to the main memory for the favored word and it is referred to as
a miss to cache.

 Hit Ratio (h) :

Hit Ratio (h) = Number of Hits / Total CPU references to memory = Number of hits / ( Number of Hits + Number of
Misses )

The Hit ratio is nothing but a probability of getting hits out of some number of memory references made by the CPU.
So its range is 0 <= h <= 1.

 Miss Ratio: The miss ratio is the probability of getting miss out of some number of memory references made
by the CPU. Miss Ratio = Number of misses / Total CPU references to memory = Number
of misses/ (Number of hits + Number of misses) Miss Ratio = 1 – hit ratio(h)

 Average Access Time ( tavg ) :


UNIT 4: I/O management & Disk scheduling:
tavg = h X tc + ( 1- h ) X ( tc + tm ) = tc + ( 1- h ) X tm

Let tc, h and tm denote the cache access time, hit ratio in cache and and main access time respectively.

Average memory access time = Hit Time + Miss Rate X Miss Penalty

Miss Rate : It can be defined as he fraction of accesses that are not in the cache (i.e. (1-h)).

Miss Penalty : It can be defined as the addition clock cycles to service the miss, the extra time needed to carry the
favored information into cache from main memory in case of miss in cache.

Cache Memory Structure

Types of Cache misses :

 Compulsory Miss (Cold start Misses or First reference Misses) : This type of miss occurs when the first
access to a block happens. In this type of miss, the block must be brought into the cache.

 Capacity Miss : This type of miss occurs when a program working set is much bigger than the cache storage
capacity. Blocks need to be discarded as keeping all blocks is not possible during program execution.

 Conflict Miss (Collision Misses or Interference Misses) : This miss is found majorly in the case of set
associative or direct mapped block placement strategies, conflict miss occur when several blocks are
mapped to the same set or block frame.

 Coherence Miss (Invalidation) : It occurs when other external processors ( e.g. I/O ) updates memory.

CPU Performance :
CPU time divide into clock cycles that spends for executing packages/programs, and clock cycles that spend for
waiting for memory system. Cache hits are part of regular CPU cycle.

CPU time = ( CPU execution clock cycles + memory stall clock cycles ) X Clock Cycle time

1. Memory Stall Clock cycles ( for write-back cache ) :

 Memory Stall Clock-cycles = Read Stall-cycles + Write Stall-cycles

 Read-Write Cycle = ( Read/Programs ) X Read miss rate X read miss penalty

 Write-Stall Cycle = ( Write/Programs ) X Write miss rate X Write miss penalty + Write Buffer Stalls

2. Memory Stall Clock cycles ( for write-through cache ) :

 Assume write buffer stalls are negligible. Every access (read/write) treated similar.

 Memory Stall Clock-cycles = ( Memory Access/Program ) X Miss Rate X Miss Penalties


UNIT 4: I/O management & Disk scheduling:
 Memory Stall Clock-cycles = (Instructions/Program ) X ( Misses/Instructions ) X Miss Penalties

Measuring and Improving Cache Performance :

1. Technique used to minimize the average memory access time :

 Reducing hit time, miss penalty or miss rate.

 Reducing Miss penalty X Miss rate.

2. Techniques for reducing Hit time :

 Small and Simple cache.

 Trace caches and pipelined cache access

 Avoid time loss in address translation.

3. Techniques for reducing Miss Penalty :

 Usage of Multi-level cache.

 Giving priority to read misses over write.

 Victim Caches

4. Techniques for reducing Miss Rate :

 Increased Block size

 Higher Associativity.

 Compiler optimization

 Large Cache.

5. Techniques for reducing ( Miss Rate X Miss Penalty ) :

 Non- blocking cache

 Hardware pre-fetching

 Compiler controlled pre-fetching


Unit 5 : OS Security
System Protection in Operating System
Introduction:

System protection in an operating system refers to the mechanisms implemented by the operating system to ensure
the security and integrity of the system. System protection involves various techniques to prevent unauthorized
access, misuse, or modification of the operating system and its resources.

There are several ways in which an operating system can provide system protection:

User authentication: The operating system requires users to authenticate themselves before accessing the system.
Usernames and passwords are commonly used for this purpose.

Access control: The operating system uses access control lists (ACLs) to determine which users or processes have
permission to access specific resources or perform specific actions.

Encryption: The operating system can use encryption to protect sensitive data and prevent unauthorized access.

Firewall: A firewall is a software program that monitors and controls incoming and outgoing network traffic based
on predefined security rules.

Antivirus software: Antivirus software is used to protect the system from viruses, malware, and other malicious
software.

System updates and patches: The operating system must be kept up-to-date with the latest security patches and
updates to prevent known vulnerabilities from being exploited.

By implementing these protection mechanisms, the operating system can prevent unauthorized access to the
system, protect sensitive data, and ensure the overall security and integrity of the system.

What is Protection?
Protection refers to a mechanism which controls the access of programs, processes, or users to the resources
defined by a computer system. We can take protection as a helper to multi programming operating system, so that
many users might safely share a common logical name space such as directory or files.

Need for Protection:

 To prevent the access of unauthorized users

 To ensure that each active programs or processes in the system uses resources only as the stated policy

 To improve reliability by detecting latent errors

Role of Protection:
The role of protection is to provide a mechanism that implement policies which defines the uses of resources in the
computer system. Some policies are defined at the time of design of the system, some are designed by management
of the system and some are defined by the users of the system to protect their own files and programs. Every
application has different policies for use of the resources and they may change over time so protection of the system
is not only concern of the designer of the operating system. Application programmer should also design the
protection mechanism to protect their system against misuse. Policy is different from mechanism. Mechanisms
determine how something will be done and policies determine what will be done. Policies are changed over time
and place to place. Separation of mechanism and policy is important for the flexibility of the system.

Advantages of system protection in an operating system:

1. Ensures the security and integrity of the system

2. Prevents unauthorized access, misuse, or modification of the operating system and its resources
Unit 5 : OS Security
3. Protects sensitive data

4. Provides a secure environment for users and applications

5. Prevents malware and other security threats from infecting the system

6. Allows for safe sharing of resources and data among users and applications

7. Helps maintain compliance with security regulations and standards

Disadvantages of system protection in an operating system:

1. Can be complex and difficult to implement and manage

2. May slow down system performance due to increased security measures

3. Can cause compatibility issues with some applications or hardware

4. Can create a false sense of security if users are not properly educated on safe computing practices

5. Can create additional costs for implementing and maintaining security measures.

Access matrix in Operating System


Access Matrix is a security model of protection state in computer system. It is represented as a matrix. Access matrix
is used to define the rights of each process executing in the domain with respect to each object. The rows of matrix
represent domains and columns represent objects. Each cell of matrix represents set of access rights which are given
to the processes of domain means each entry(i, j) defines the set of operations that a process executing in domain Di
can invoke on object Oj.

Different types of rights:

There are different types of rights the files can have. The most common ones are:

1. Read- This is a right given to a process in a domain, which allows it to read the file.

2. Write- Process in domain can write into the file.

3. Execute- Process in domain can execute the file.

4. Print- Process in domain only has access to printer.

Sometimes, domains can have more than one right, i.e. combination of rights mentioned above.

Let us now understand how an access matrix works from the example given below.

F1 F2 F3 Printer

D1 read read

D2 print

D3 read execute

D4 read write read write


Unit 5 : OS Security
Observations of above matrix:

 There are four domains and four objects– three files(F1, F2, F3) and one printer.

 A process executing in D1 can read files F1 and F3.

 A process executing in domain D4 has same rights as D1 but it can also write on files.

 Printer can be accessed by only one process executing in domain D2.

 A process executing in domain D3 has the right to read file F2 and execute file F3.

Mechanism of access matrix:

The mechanism of access matrix consists of many policies and semantic properties. Specifically, we must ensure that
a process executing in domain Di can access only those objects that are specified in row i. Policies of access matrix
concerning protection involve which rights should be included in the (i, j)th entry. We must also decide the domain
in which each process executes. This policy is usually decided by the operating system. The users decide the contents
of the access-matrix entries. Association between the domain and processes can be either static or dynamic. Access
matrix provides a mechanism for defining the control for this association between domain and processes.

Switch operation: When we switch a process from one domain to another, we execute a switch operation on an
object(the domain). We can control domain switching by including domains among the objects of the access matrix.
Processes should be able to switch from one domain (Di) to another domain (Dj) if and only if a switch right is given
to access(i, j). This is explained using an example below:

F1 F2 F3 Printer D1 D2 D3 D4

D1 read read switch

D2 print switch switch

D3 read execute

D4 read write read write switch

According to the above matrix, a process executing in domain D2 can switch to domain D3 and D4. A process
executing in domain D4 can switch to domain D1 and process executing in domain D1 can switch to domain D2.

Access Control in Computer Network


Access control is a method of limiting access to a system or to physical or virtual resources. It is a process by which
users can access and are granted certain prerogative to systems, resources or information. Access control is a
security technique that has control over who can view different aspects, what can be viewed and who can use
resources in a computing environment. It is a fundamental concept in security that reduces risk to the business or
organization. To establish a secure system, electronic access control systems are used that depend on user
credentials, access card readers, auditing and reports to track employee access to restricted business locations and
areas. These systems include access control panels to prohibit entry to sensitive areas like alarms and lock down
areas to prevent unauthorized access or operations. Access control systems perform identification, authentication,
and authorization of users and entities by evaluating required login credentials that may include passwords, pins,
bio-metric scans or other authentication factors. There is multi-factor authentication which requires two or more
Unit 5 : OS Security
authentication factors which is often an important part of the layered defense to protect access control
systems. Authentication Factors:

 Password or PIN

 Bio-metric measurement (fingerprint & retina scan)

 Card or Key

For computer security, access control include the authorization, authentication and audit of the entity trying to gain
access. Access control models have a subject and an object.

The Subject-the human user-is the one trying to gain access to the object-usually the software. In computer systems,
an access control list contains a list of permissions and the users to whom these permissions apply.

Authentication Mechanism:

1. Two-factor authentication

2. Multi factor authentication

3. one-time password

4. Three-factor authentication

5. Bio metrics

6. Hard Tokens

7. Soft Tokens

8. Contextual Authentication

9. Device identification

Different access control models are used depending on the compliance requirements and the security levels of
information technology that is to be protected. Basically access control is of 2 types:

1. Physical Access Control: Physical access control restricts entry to campuses, buildings, rooms and physical IT
assets.

2. Logical Access Control: Logical access control limits connections to computer networks, system files and
data.

Access Control Models:


1. Attribute-based Access Control (ABAC): In this model, access is granted or declined by evaluating a set of
rules, policies, and relationships using the attributes of users, systems and environmental conditions.

2. Discretionary Access Control (DAC): In DAC, the owner of data determines who can access specific
resources.

3. History-Based Access Control (HBAC): Access is granted or declined by evaluating the history of activities of
the inquiring party that includes behavior, the time between requests and content of requests.

4. Identity-Based Access Control (IBAC): By using this model network administrators can more effectively
manage activity and access based on individual requirements.

5. Mandatory Access Control (MAC): A control model in which access rights are regulated by a central
authority based on multiple levels of security. Security Enhanced Linux is implemented using MAC on the
Linux operating system.
Unit 5 : OS Security
6. Organization-Based Access control (OrBAC): This model allows the policy designer to define a security policy
independently of the implementation.

7. Role-Based Access Control (RBAC): RBAC allows access based on the job title. RBAC eliminates discretion on
a large scale when providing access to objects. For example, there should not be permissions for human
resources specialist to create network accounts.

8. Rule-Based Access Control (RAC): RAC method is largely context based. Example of this would be only
allowing students to use the labs during a certain time of day.

System Security
Prerequisite – Basic Network Attacks, Types of Viruses
The security of a computer system is a crucial task. It is a process of ensuring the confidentiality and integrity of the
OS. Security is one of most important as well as the major task in order to keep all the threats or other malicious
tasks or attacks or program away from the computer’s software system.
A system is said to be secure if its resources are used and accessed as intended under all the circumstances, but no
system can guarantee absolute security from several of various malicious threats and unauthorized access.

The security of a system can be threatened via two violations:

 Threat: A program that has the potential to cause serious damage to the system.

 Attack: An attempt to break security and make unauthorized use of an asset.

Security violations affecting the system can be categorized as malicious and accidental threats. Malicious threats, as
the name suggests are a kind of harmful computer code or web script designed to create system vulnerabilities
leading to back doors and security breaches. Accidental Threats, on the other hand, are comparatively easier to be
protected against. Example: Denial of Service DDoS attack.

Security can be compromised via any of the breaches mentioned:

 Breach of confidentiality: This type of violation involves the unauthorized reading of data.

 Breach of integrity: This violation involves unauthorized modification of data.

 Breach of availability: It involves unauthorized destruction of data.

 Theft of service: It involves the unauthorized use of resources.

 Denial of service: It involves preventing legitimate use of the system. As mentioned before, such attacks can
be accidental in nature.

Security System Goal:


Henceforth, based on the above breaches, the following security goals are aimed:

1. Integrity:
The objects in the system mustn’t be accessed by any unauthorized user & any user not having sufficient
rights should not be allowed to modify the important system files and resources.

2. Secrecy:
The objects of the system must be accessible only to a limited number of authorized users. Not everyone
should be able to view the system files.

3. Availability:
All the resources of the system must be accessible to all the authorized users i.e. only one user/process
should not have the right to hog all the system resources. If such kind of situation occurs, denial of service
could happen. In this kind of situation, malware might hog the resources for itself & thus preventing the
legitimate processes from accessing the system resources.
Unit 5 : OS Security
Threats can be classified into the following two categories:

1. Program Threats:
A program was written by a cracker to hijack the security or to change the behavior of a normal process. In
other words, if a user program is altered and further made to perform some malicious unwanted tasks, then
it is known as Program Threats.

2. System Threats:
These threats involve the abuse of system services. They strive to create a situation in which operating-
system resources and user files are misused. They are also used as a medium to launch program threats.

Types of Program Threats:

1. Virus:
An infamous threat, known most widely. It is a self-replicating and malicious thread that attaches itself to a
system file and then rapidly replicates itself, modifying and destroying essential files leading to a system
breakdown.

Further, Types of computer viruses can be described briefly as follows:


– file/parasitic – appends itself to a file
– boot/memory – infects the boot sector
– macro – written in a high-level language like VB and affects MS Office files
– source code – searches and modifies source codes
– polymorphic – changes in copying each time
– encrypted – encrypted virus + decrypting code
– stealth – avoids detection by modifying parts of the system that can be used to detect it, like the read system
call
– tunneling – installs itself in the interrupt service routines and device drivers
– multipartite – infects multiple parts of the system

2. Trojan Horse:
A code segment that misuses its environment is called a Trojan Horse. They seem to be attractive and
harmless cover programs but are really harmful hidden programs that can be used as the virus carrier. In one
of the versions of Trojan, the User is fooled to enter confidential login details on an application. Those details
are stolen by a login emulator and can be further used as a way of information breaches. One of the major
as well as a serious threat or consequences of the Trojan horse is that it will actually perform proper damage
once installed or run on the computer’s system but at first, a glance will appear to be useful software and
later turns out to be maliciously unwanted one.

Another variance is Spyware, Spyware accompanies a program that the user has chosen to install and download ads
to display on the user’s system, thereby creating pop-up browser windows and when certain sites are visited by the
user, it captures essential information and sends it over to the remote server. Such attacks are also known
as Convert Channels.

3. Trap Door:
The designer of a program or system might leave a hole in the software that only he is capable of using, the
Trap Door works on similar principles. Trap Doors are quite difficult to detect as to analyze them, one needs
to go through the source code of all the components of the system. In other words, if we may have to define
a trap door then it would be like, a trap door is actually a kind of a secret entry point into a running or static
program that actually allows anyone to gain access to any system without going through the usual security
access procedures.
Unit 5 : OS Security
4. Logic Bomb:

A program that initiates a security attack only under a specific situation. To be very precise, a logic bomb is
actually the most malicious program which is inserted intentionally into the computer system and that is
triggered or functions when specific conditions have been met for it to work.

5. Worm: A
computer worm is a type of malware that replicates itself and infects other computers while remaining
active on affected systems. A computer worm replicates itself in order to infect machines that aren’t already
infested. It frequently accomplishes this by taking advantage of components of an operating system that are
automatic and unnoticed by the user. Worms are frequently overlooked until their uncontrolled replication
depletes system resources, slowing or stopping other activities.

Types of System Threats –


Aside from the program threats, various system threats are also endangering the security of our system:

1. Worm:
An infection program that spreads through networks. Unlike a virus, they target mainly LANs. A computer affected
by a worm attacks the target system and writes a small program “hook” on it. This hook is further used to copy the
worm to the target computer. This process repeats recursively, and soon enough all the systems of the LAN are
affected. It uses the spawn mechanism to duplicate itself. The worm spawns copies of itself, using up a majority of
system resources and also locking out all other processes.

The basic functionality of the worm can be represented as:

2. Port Scanning:
It is a means by which the cracker identifies the vulnerabilities of the system to attack. It is an automated process
that involves creating a TCP/IP connection to a specific port. To protect the identity of the attacker, port scanning
attacks are launched from Zombie Systems, that is systems that were previously independent systems that are also
serving their owners while being used for such notorious purposes.

3. Denial of Service:
Such attacks aren’t aimed for the purpose of collecting information or destroying system files. Rather, they are used
for disrupting the legitimate use of a system or facility.
These attacks are generally network-based. They fall into two categories:
– Attacks in this first category use so many system resources that no useful work can be performed.

For example, downloading a file from a website that proceeds to use all available CPU time.
– Attacks in the second category involve disrupting the network of the facility. These attacks are a result of the abuse
of some fundamental TCP/IP principles.
the fundamental functionality of TCP/IP.
Unit 5 : OS Security
Security Measures Taken –
To protect the system, Security measures can be taken at the following levels:

 Physical:
The sites containing computer systems must be physically secured against armed and malicious intruders.
The workstations must be carefully protected.

 Human:
Only appropriate users must have the authorization to access the system. Phishing(collecting confidential
information) and Dumpster Diving(collecting basic information so as to gain unauthorized access) must be
avoided.

 Operating system:
The system must protect itself from accidental or purposeful security breaches.

 Networking System:
Almost all of the information is shared between different systems via a network. Intercepting these data
could be just as harmful as breaking into a computer. Henceforth, Network should be properly secured
against such attacks.

Usually, Anti Malware programs are used to periodically detect and remove such viruses and threats. Additionally, to
protect the system from Network Threats, a Firewall is also be used.

Basic Network Attacks in Computer Network


Many people rely on the Internet for many of their professional, social and personal activities. But there are also
people who attempt to damage our Internet-connected computers, violate our privacy and render inoperable the
Internet services.

Given the frequency and variety of existing attacks as well as the threat of new and more destructive future attacks,
network security has become a central topic in the field of computer networking.

How are computer networks vulnerable? What are some of the more prevalent types of attacks today?

Malware – short for malicious software which is specifically designed to disrupt, damage, or gain authorized access
to a computer system. Much of the malware out there today is self-replicating: once it infects one host, from that
host it seeks entry into other hosts over the Internet, and from the newly infected hosts, it seeks entry into yet more
hosts. In this manner, self-replicating malware can spread exponentially fast.

Virus – A malware which requires some form of user’s interaction to infect the user’s device. The classic example is
an e-mail attachment containing malicious executable code. If a user receives and opens such an attachment, the
user inadvertently runs the malware on the device.

Worm – A malware which can enter a device without any explicit user interaction. For example, a user may be
running a vulnerable network application to which an attacker can send malware. In some cases, without any user
intervention, the application may accept the malware from the Internet and run it, creating a worm.

Botnet – A network of private computers infected with malicious software and controlled as a group without the
owners’ knowledge, e.g. to send spam.

DoS (Denial of Service) – A DoS attack renders a network, host, or other pieces of infrastructure unusable by
legitimate users. Most Internet DoS attacks fall into one of three categories :

• Vulnerability attack: This involves sending a few well-crafted messages to a vulnerable application or operating
system running on a targeted host. If the right sequence of packets is sent to a vulnerable application or operating
system, the service can stop or, worse, the host can crash.
Unit 5 : OS Security
• Bandwidth flooding: The attacker sends a deluge of packets to the targeted host—so many packets that the
target’s access link becomes clogged, preventing legitimate packets from reaching the server.

• Connection flooding: The attacker establishes a large number of half-open or fully open TCP connections at the
target host. The host can become so bogged down with these bogus connections that it stops accepting legitimate
connections.

DDoS (Distributed DoS) – DDoS is a type of DOS attack where multiple compromised systems, are used to target a
single system causing a Denial of Service (DoS) attack. DDoS attacks leveraging botnets with thousands of comprised
hosts are a common occurrence today. DDoS attacks are much harder to detect and defend against than a DoS
attack from a single host.

Packet sniffer – A passive receiver that records a copy of every packet that flies by is called a packet sniffer. By
placing a passive receiver in the vicinity of the wireless transmitter, that receiver can obtain a copy of every packet
that is transmitted! These packets can contain all kinds of sensitive information, including passwords, social security
numbers, trade secrets, and private personal messages. some of the best defenses against packet sniffing involve
cryptography.

IP Spoofing – The ability to inject packets into the Internet with a false source address is known as IP spoofing, and is
but one of many ways in which one user can masquerade as another user. To solve this problem, we will need end-
point authentication, that is, a mechanism that will allow us to determine with certainty if a message originates from
where we think it does.

Man-in-the-Middle Attack – As the name indicates, a man-in-the-middle attack occurs when someone between you
and the person with whom you are communicating is actively monitoring, capturing, and controlling your
communication transparently. For example, the attacker can re-route a data exchange. When computers are
communicating at low levels of the network layer, the computers might not be able to determine with whom they
are exchanging data.

Compromised-Key Attack – A key is a secret code or number necessary to interpret secured information. Although
obtaining a key is a difficult and resource-intensive process for an attacker, it is possible. After an attacker obtains a
key, that key is referred to as a compromised key. An attacker uses the compromised key to gain access to a secured
communication without the sender or receiver being aware of the attack.

Phishing – The fraudulent practice of sending emails purporting to be from reputable companies in order to induce
individuals to reveal personal information, such as passwords and credit card numbers.

DNS spoofing – Also referred to as DNS cache poisoning, is a form of computer security hacking in which corrupt
Domain Name System data is introduced into the DNS resolver’s cache, causing the name server to return an
incorrect IP address.

Rootkit – Rootkits are stealthy packages designed to benefit administrative rights and get the right of entry to a
community tool. Once installed, hackers have complete and unrestricted get right of entry to the tool and can,
therefore, execute any movement including spying on customers or stealing exclusive data with no hindrance.

Find out about Organization Assaults:


There’s something else to find out about network assaults.

Zeus Malware: Variations, Techniques and History:

Zeus, otherwise called Zbot, is a malware bundle that utilizes a client/server model. Programmers utilize the Zeus
malware to make gigantic botnets. The primary reason for Zeus is to assist programmers with acquiring unapproved
admittance to monetary frameworks by taking accreditations, banking data and monetary information. The
penetrated information is then sent back to the assailants through the Zeus Order and Control (C&C) server.

Zeus has tainted north of 3 million PCs in the USA, and has compromised significant associations like NASA and the
Bank of America.
Unit 5 : OS Security
Cobalt Strike: White Cap Programmer Force to be reckoned with in Some unacceptable Hands

Cobalt Strike is a business infiltration testing instrument. This instrument empowers security analyzers admittance to
a huge assortment of assault capacities. You can utilize Cobalt Strike to execute stick phishing and gain unapproved
admittance to frameworks. It can likewise recreate an assortment of malware and other high level danger strategies.

While Cobalt Strike is a real instrument utilized by moral programmers, some digital hoodlums get the preliminary
rendition and break its product insurance, or even get admittance to a business duplicate of the product.

FTCode Ransomware: Dispersion, Life systems and Assurance

FTCode is a kind of ransomware, intended to encode information and power casualties to pay a payoff for a
decoding key. The code is written in PowerShell, implying that it can scramble records on a Windows gadget without
downloading some other parts. FTCode loads its executable code just into memory, without saving it to plate, to
forestall location by antivirus. The FTCode ransomware is conveyed through spam messages containing a
contaminated Word layout in Italian.

Mimikatz: World’s Most Perilous Secret word Taking Stage

Mimikatz is an open-source instrument at first created by moral programmer Benjamin Delpy, to exhibit a blemish in
Microsoft’s confirmation conventions. .As such, the apparatus takes passwords. It is conveyed on Windows and
empowers clients to extricate Kerberos tickets and other validation tokens from the machine. A portion of the more
significant assaults worked with by Mimikatz incorporate Pass-the-Hash, Kerberos Brilliant Ticket, Pass the Key, and
Pass-the-Ticket.

Understand more: Mimikatz: World’s Most Risky Secret key Taking Stage

Grasping Honor Acceleration and 5 Normal Assault Strategies

Honor heightening is a typical technique for acquiring unapproved admittance to frameworks. Programmers start
honor heightening by tracking down weak focuses in an association’s guards and accessing a framework. Typically,
the primary place of infiltration won’t concede aggressors with the fundamental degree of access or information.
They will go on with honor heightening to acquire authorizations or get admittance to extra, more delicate
frameworks.

Cryptography Introduction
Cryptography is the study and practice of techniques for secure communication in the presence of third parties
called adversaries. It deals with developing and analyzing protocols that prevents malicious third parties from
retrieving information being shared between two entities thereby following the various aspects of information
security. Secure Communication refers to the scenario where the message or data shared between two parties can’t
be accessed by an adversary. In Cryptography, an Adversary is a malicious entity, which aims to retrieve precious
information or data thereby undermining the principles of information security. Data Confidentiality, Data Integrity,
Authentication and Non-repudiation are core principles of modern-day cryptography.

1. Confidentiality refers to certain rules and guidelines usually executed under confidentiality agreements
which ensure that the information is restricted to certain people or places.

2. Data integrity refers to maintaining and making sure that the data stays accurate and consistent over its
entire life cycle.

3. Authentication is the process of making sure that the piece of data being claimed by the user belongs to it.

4. Non-repudiation refers to the ability to make sure that a person or a party associated with a contract or a
communication cannot deny the authenticity of their signature over their document or the sending of a
message.
Unit 5 : OS Security
Consider two parties Alice and Bob. Now, Alice wants to send a message m to Bob over a secure channel. So, what
happens is as follows. The sender’s message or sometimes called the Plaintext, is converted into an unreadable form
using a Key k. The resultant text obtained is called the Ciphertext. This process is known as Encryption. At the time of
received, the Ciphertext is converted back into the plaintext using the same Key k, so that it can be read by the
receiver. This process is known as Decryption.

Alice (Sender) Bob (Receiver)

C = E (m, k) ----> m = D (C, k)

Here, C refers to the Ciphertext while E and D are the Encryption and Decryption algorithms respectively. Let’s
consider the case of Caesar Cipher or Shift Cipher as an example. As the name suggests, in Caesar’s Cipher each
character in a word is replaced by another character under some defined rules. Thus, if A is replaced by D, B by E and
so on. Then, each character in the word would be shifted by a position of 3. For example:

Types of Cryptography:
There are several types of cryptography, each with its own unique features and applications. Some of the most
common types of cryptography include:

1. Symmetric-key cryptography: This type of cryptography involves the use of a single key to encrypt and decrypt
data. Both the sender and receiver use the same key, which must be kept secret to maintain the security of the
communication.

2. Asymmetric-key cryptography: Asymmetric-key cryptography, also known as public-key cryptography, uses a pair
of keys – a public key and a private key – to encrypt and decrypt data. The public key is available to anyone, while
the private key is kept secret by the owner.

Hash functions: A hash function is a mathematical algorithm that converts data of any size into a fixed-size output.
Hash functions are often used to verify the integrity of data and ensure that it has not been tampered with.

Applications of Cryptography:

Cryptography has a wide range of applications in modern-day communication, including:

 Secure online transactions: Cryptography is used to secure online transactions, such as online banking and
e-commerce, by encrypting sensitive data and protecting it from unauthorized access.

 Digital signatures: Digital signatures are used to verify the authenticity and integrity of digital documents
and ensure that they have not been tampered with.

 Password protection: Passwords are often encrypted using cryptographic algorithms to protect them from
being stolen or intercepted.

Military and intelligence applications: Cryptography is widely used in military and intelligence applications to protect
classified information and communications.
Unit 5 : OS Security
Challenges of Cryptography:
While cryptography is a powerful tool for securing information, it also presents several challenges, including:

 Key management: Cryptography relies on the use of keys, which must be managed carefully to maintain the
security of the communication.

 Quantum computing: The development of quantum computing poses a potential threat to current
cryptographic algorithms, which may become vulnerable to attacks.

 Human error: Cryptography is only as strong as its weakest link, and human error can easily compromise the
security of a communication.

Authentication in Computer Network


Authentication is the process of verifying the identity of a user or information. User authentication is the process of
verifying the identity of a user when that user logs in to a computer system.

There are different types of authentication systems which are: –

1. Single-Factor authentication: – This was the first method of security that was developed. On this
authentication system, the user has to enter the username and the password to confirm whether that user is logging
in or not. Now if the username or password is wrong, then the user will not be allowed to log in or access the
system.

Advantage of the Single-Factor Authentication System: –


 It is a very simple to use and straightforward system.

 it is not at all costly.

 The user does not need any huge technical skills.

The disadvantage of the Single-Factor Authentication


 It is not at all password secure. It will depend on the strength of the password entered by the user.

 The protection level in Single-Factor Authentication is much low.

2. Two-factor Authentication: – In this authentication system, the user has to give a username, password, and
other information. There are various types of authentication systems that are used by the user for securing the
system. Some of them are: – wireless tokens and virtual tokens. OTP and more.

Advantages of the Two-Factor Authentication


 The Two-Factor Authentication System provides better security than the Single-factor Authentication
system.

 The productivity and flexibility increase in the two-factor authentication system.

 Two-Factor Authentication prevents the loss of trust.

Disadvantages of Two-Factor Authentication


 It is time-consuming.

3. Multi-Factor authentication system,: – In this type of authentication, more than one factor of authentication is
needed. This gives better security to the user. Any type of keylogger or phishing attack will not be possible in a Multi-
Factor Authentication system. This assures the user, that the information will not get stolen from them.

The advantage of the Multi-Factor Authentication System are: –


Unit 5 : OS Security
 No risk of security.

 No information could get stolen.

 No risk of any key-logger activity.

 No risk of any data getting captured.

The disadvantage of the Multi-Factor Authentication System are: –


 It is time-consuming.

 it can rely on third parties. The main objective of authentication is to allow authorized users to access the
computer and to deny access to unauthorized users. Operating Systems generally identify/authenticates
users using the following 3 ways: Passwords, Physical identification, and Biometrics. These are explained as
following below.

1. Passwords: Password verification is the most popular and commonly used authentication technique.
A password is a secret text that is supposed to be known only to a user. In a password-based system,
each user is assigned a valid username and password by the system administrator. The system stores
all usernames and Passwords. When a user logs in, their user name and password are verified by
comparing them with the stored login name and password. If the contents are the same then the
user is allowed to access the system otherwise it is rejected.

2. Physical Identification: This technique includes machine-readable badges(symbols), cards, or smart


cards. In some companies, badges are required for employees to gain access to the organization’s
gate. In many systems, identification is combined with the use of a password i.e the user must insert
the card and then supply his /her password. This kind of authentication is commonly used with
ATMs. Smart cards can enhance this scheme by keeping the user password within the card itself.
This allows authentication without the storage of passwords in the computer system. The loss of
such a card can be dangerous.

3. Biometrics: This method of authentication is based on the unique biological characteristics of each
user such as fingerprints, voice or face recognition, signatures, and eyes.

4. A scanner or other devices to gather the necessary data about the user.

5. Software to convert the data into a form that can be compared and stored.

6. A database that stores information for all authorized users.

7. Facial Characteristics – Humans are differentiated on the basis of facial characteristics such as eyes,
nose, lips, eyebrows, and chin shape.

8. Fingerprints – Fingerprints are believed to be unique across the entire human population.

9. Hand Geometry – Hand geometry systems identify features of the hand that includes the shape,
length, and width of fingers.

10. Retinal pattern – It is concerned with the detailed structure of the eye.

11. Signature – Every individual has a unique style of handwriting, and this feature is reflected in the
signatures of a person.

12. Voice – This method records the frequency pattern of the voice of an individual speaker.

You might also like