0% found this document useful (0 votes)
6 views210 pages

Operating System Unit 1

The document outlines the objectives and outcomes of a course on Operating Systems at APEX Institute of Technology, focusing on understanding OS functionalities, resource management, and memory management. It details various types of operating systems, including serial, batch, multi-programming, time-sharing, and distributed systems, along with their advantages and disadvantages. The course also includes assessments and references for further study.

Uploaded by

rahul104941
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views210 pages

Operating System Unit 1

The document outlines the objectives and outcomes of a course on Operating Systems at APEX Institute of Technology, focusing on understanding OS functionalities, resource management, and memory management. It details various types of operating systems, including serial, batch, multi-programming, time-sharing, and distributed systems, along with their advantages and disadvantages. The course also includes assessments and references for further study.

Uploaded by

rahul104941
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 210

APEX INSTITUTE OF TECHNOLOGY

Bachelor of Engineering (Computer Science & Engineering)


OPERATING SYSTEM
Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Operating
System
Course Objective: Students will try to learn

1 To understand a fundamental understanding of operating


systems and its functionalities.

2 To understand the working of an OS as a resource manager,


file system manager, process manager, memory manager and
I/O manager and methods used to implement the different
parts of OS
3 To understand the concepts and implementation Memory
management policies and virtual memory in advance
operating system.

2
Operating
System
Course Outcomes • The student will be able to
CO Title Level understand fundamental
Numbe understanding of operating systems
r and its functionalities.
CO1 Describe the important computer Underst
system resources and the role of and
• The student will be able to
operating system in their management understand the process management,
policies and algorithms. various scheduling algorithms,
CO2 Understand the process management Rememb
policies and scheduling of processes concurrency and synchronization.
er
by CPU and familiar with memory • The student will be able to
management and its allocation
understand memory management
policies.
CO3 Identify use and evaluate the storage Apply and virtual memory concepts in
management policies with respect to modern Operating systems
different storage management
technologies.

3
Content
• 1. Introduction of O.S
• 2. Computer system structure
• 3. Components of computer system
• 4.Operating system Tasks
• 5. Operating system Services
What is an Operating System?
• A program that acts as an intermediary between a user of a
computer and the computer hardware

• Operating system goals:


– Execute user programs and make solving user problems
easier
– Make the computer system convenient to use
– Use the computer hardware in an efficient manner
Computer System Structure
• Computer system can be divided into four components:
– Hardware – provides basic computing resources
• CPU, memory, I/O devices
– Operating system
• Controls and coordinates use of hardware among various
applications and users
– Application programs – define the ways in which the
system resources are used to solve the computing problems of
the users
• Word processors, compilers, web browsers, database
systems, video games
– Users
• People, machines, other computers
Components of a Computer
System

Image no: 1
Image Reference: https://tse4.mm.bing.net/th?id=OIP.fDtpxnkhJATPOgrR3JDKrQAAAA&pid=Api&P=0&w=300&h=300
What Operating Systems do?
• Depends on the point of view
• Users want convenience, ease of use
– Don’t care about resource utilization
• But shared computer such as mainframe or minicomputer must
keep all users happy
• Users of dedicate systems such as workstations have dedicated
resources but frequently use shared resources from servers
• Handheld computers are resource poor, optimized for usability
and battery life
• Some computers have little or no user interface, such as
embedded computers in devices and automobiles
Operating System Tasks
• OS is a resource allocator
– Manages all resources
– Decides between conflicting requests for efficient and fair
resource use

• OS is a control program
– Controls execution of programs to prevent errors and
improper use of the computer
Operating System Tasks Cont_
• Multiprogramming needed for efficiency
– Single user cannot keep CPU and I/O devices busy at all
times
– Multiprogramming organizes jobs (code and data) so CPU
always has one to execute
– One job selected and run via job scheduling
Timesharing (multitasking) is logical extension in which CPU
switches jobs so frequently that users can interact with each job
while it is running, creating interactive computing
– Response time should be < 1 second
– Each user has at least one program executing in memory ฀
process
– If several jobs ready to run at the same time ฀ CPU
scheduling
Memory Layout for
• .
Multiprogrammed System

Image no: 2
Image Reference:
http://2.bp.blogspot.com/_ZTUez9i41DE/SI4qMdEk07I/AAAAAAAAABw/YFThR9dX0to/s400/Memory+Layout+For+A+Multiprogramming+Sy
stem.jpg
Transition from User to
• .
Kernel/System Mode
Timer to prevent infinite loop / process hogging resources
– Set interrupt after specific period
– Operating system decrements counter
– When counter zero generate an interrupt
– Set up before scheduling process to regain control or
terminate program that exceeds allotted time

Image no: 3
Image Reference: https://tse3.mm.bing.net/th?id=OIP.M_H_PLAOOMh0IkHFg7WfbQHaDp&pid=Api&P=0&w=306&h=152
Operating System Services
• Operating systems provide an environment for execution of
programs and services to programs and users
• One set of operating-system services provides functions that are
helpful to the user:
– User interface - Almost all operating systems have a user
interface (UI).
• Varies between Command-Line (CLI), Graphics User
Interface (GUI), Batch
– Program execution - The system must be able to load a
program into memory and to run that program, end execution,
either normally or abnormally (indicating error)
– I/O operations - A running program may require I/O, which
may involve a file or an I/O device
Operating System Services
(Cont.)
– Communications – Processes may exchange information, on
the same computer or between computers over a network
• Communications may be via shared memory or through
message passing (packets moved by the OS)
– Error detection – OS needs to be constantly aware of possible
errors
• May occur in the CPU and memory hardware, in I/O devices,
in user program
• For each type of error, OS should take the appropriate action
to ensure correct and consistent computing
• Debugging facilities can greatly enhance the user’s and
programmer’s abilities to efficiently use the system
Operating System Services
(Cont.)
• Another set of OS functions exists for ensuring the efficient
operation of the system itself via resource sharing
– Resource allocation - When multiple users or multiple jobs
running concurrently, resources must be allocated to each of
them
– Accounting - To keep track of which users use how much and
what kinds of computer resources
– Protection and security - The owners of information stored in
a multiuser or networked computer system may want to control
use of that information, concurrent processes should not
interfere with each other
• Protection involves ensuring that all access to system
resources is controlled
A View of Operating System
Services

Image no:5
Image Reference : https://tse1.mm.bing.net/th?id=OIP.3S82SuUl9seqdpxmyDqpvwHaDt&pid=Api&P=0&w=300&h=300
Assessment Pattern
S.N Type of Weight Frequency of Final Weight age Remarks
o. Assessme age of Task in internal
nt conduct Assessment

10
Assignme Applicable to
1 marks One per unit 10 marks
nt course type
for each
Surprise 12 Applicable to
One per unit
2 test marks 4 marks course type
for each
Applicable to
4 marks two per unit
3 Quiz 4 marks course type
for each
Mid two per Applicable to
20
4 semester semester 20 marks course type
marks
Test
Attendanc
e and
5 NA Na 2 marks
Engageme
nt on BB
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System Concepts”,
Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles,
7th edition Pearson Education Limited, 2014 ISBN: 1292061944,
9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach",
Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCOWd7
aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fEyq
RiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU

20
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM

Instructor: Ms Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Content
1. Types of operating system
2. Serial Processing Operating System
3.Batch Operating system
4.Multi-programming Operating System
5.Distributed Operating System
6.Network Operating System
7.Real Time Operating System
8.Multi processor Operating System
Types of Operating System

• There are many types of operating systems that can be listed to study
the types the operating systems.
฀ Serial Processing Operating System
฀ Batch Operating system
฀ Multi-programming Operating System
฀ Time Sharing System
฀ Distributed Operating System
฀ Network Operating System
฀ Real Time Operating System
฀ Multi processor Operating System
Serial operating System
• Serial Processing: The Serial Processing Operating Systems are those which
Performs all the instructions into as sequence Manner or the
Instructions those are given by the user will be executed by
using the FIFO Manner means First in First Out.
.
• In this the Program Counter will determines which instruction is going
to Execute and the which instruction will be Execute after this.
Mainly the Punch Cards are used for this.

• Problem : the Main Problem is that a user doesn’t interact with


the System while he is working on the System, means the user can’t be able
to enter the data for Execution.
Batch Operating Systems
The Batch Processing is same as the Serial Processing Technique. But
in the Batch Processing Similar Types of jobs are Firstly Prepared and
they are Stored on the Card.
According to the concept of the batch operating systems, it states that
until a JOB (or process) has been completely processed and has been
successfully executed, we cannot perform another job or process at
the same time.
•The very first concept which denoted the task to be performed by the
operating system was the concept of Job. A job is defined as a piece of
work done on a computer. It generally consists of the program along
with the data.
•Let’s consider a scenario where , and are different jobs that are
supposed to be assigned to the batch operating system. All the three jobs
cannot be run, processed and executed at the same time as per the concept
of this kind of a system.
Batch Operating
• Systems
If the input/output is required, the gets transferred from the main memory to
fulfilled the requirements of the same.
• At this time the main memory remains empty. The job gets successfully
executed after the requirements of the input and output are fulfilled.
Therefore there is no user interaction involved in such systems. Such jobs
that run without the end user interaction are called BATCH JOBS. Example
for a batch job can be the program that reads a large file and gives out a
report.
• Batch processing is basically done for those frequently used programs that
could be run with minimal human interaction.

ADVANTAGES
• The following are the advantages of using a batch operator:
• Reduction of manual work.
• Fast and well managed execution.
• Reduction in the repetitive usage of the punch cards and magnetic tapes.
• Reduction in CPU’s idle time.
Disadvantages
The following are the disadvantages
of the batch operating systems:
• SEQUENTIAL EXECUTION: Jobs in a batch system
are always executed sequentially.
• STARVATION: Different jobs might take different amount of
time for execution which leads to the starvation of some of the
jobs.
Multi programming
Operating System
• As we know that in the Batch Processing System there are multiple jobs
Executed by the System. The System first prepares a batch and after that
he will Execute all the jobs that are Stored into the Batch.
• But the Main Problem is that if a process or job requires an Input
and Output Operation, then it is not possible and second there will be the
wastage of the Time when we are preparing the batch and the CPU
will remain idle at that Time.
• Multi-Programming we can Execute Many Programs on the System and
When we are Working with the Program then we can also Submit the
Second or Another Program for Running and the CPU will then
Execute the Second Program after the completion of the First Program.
• And in this we can also specify our Input means a user can also interact
with the System.
Memory Layout for Multiprogrammed
System

Image no : 1
Image reference : https://tse3.mm.bing.net/th?id=OIP.aqJD5BUuuT5K5diDhhgxnAHaJk&pid=Api&P=0&w=300&h=300
Time Sharing System
• These types of systems are also known by many other names such as
multitasking operating systems, fair share operating system, multi-
programming (Round Robin Technique) etc…
• The main idea behind a time sharing operating system can be
explained with an example. Consider an example where a
processor is undergoing some process for execution. During the
process of execution, if the processor wants to wait for an I/O or for any
other event, then at that time why should the CPU remain idle? In such
situation, the CPU switches over to some other and starts running it.
• In case, if again the processor waits, the CPU again switches over to
some other process and the process goes on. The main idea which
could be understood from this context is that, the CPU should not
remain idle and should remain busy in performing one or more
number of tasks at the same interval of time.
Time Sharing System
One important thing to be noted here is that when the process
volunteers to wait for some event, the CPU switches over to some
other task. We do not force the CPU to leave the existing task and
switch over to the other one.
The process itself wants to perform some task which is not related to
the CPU and hence it switches over to some other process.
It maintains the working of all the systems simultaneously.

• As the name suggests, the time is being equally shared for all the
processes. Hence, multi-tasking is multi- programming with time
sharing. The various tasks are scheduled to access the CPU for a fixed
time limit known as the time quantum.
• The switching of CPU among various processes is so rapid that it gives
us an illusion of all processes working at the same time.
Advantages of Time sharing
system
• The following are the advantages of using the time sharing
operating systems:
฀Reduced response time.
฀Reduced CPU’s idle time.
฀It avoids the duplication of the software.
Disadvantages of Time
sharing system
• The following are the disadvantages of the time sharing operating
systems:
฀The integrity and security of a user’s program is a doubt.
฀Problem of reliability.
฀Problem of data communication.
Distributed operating System
• A distributed operating system is a kind of system which uses
MULTIPLE CENTRAL PROCESSORS. This is done in a motive of
serving multiple real- time applications and multiple users. These
processors get the distributed amount of data processing jobs
accordingly.
• Consider an example in which a company has a lot of systems but has only
one printer. All the members of the company want to take the printouts
at the same time. This distributed operating system provides the users
the access to that printer using different systems.
• This is possible only when all the systems of the company are linked
together by a single communication network.
• Linking the systems does not mean that the data of each system is being
shared with each other, it rather means that when a task is to be performed,
it could be performed using any of the given systems in order to enhance the
pace of work.
ADVANTAGES
The following are the advantages of using the distributed operating
systems:
• A user at one site could get an access to the resource which is
available at another site using this resource sharing facility.
• The speed of data exchange with one another could be enhanced by using
email.
• Also even if one site of work encounters a failure, the remaining
sites still potentially remain operating.
• It also helps in reduction of the load on the host computer.
• Data exchange process within the network is fast and reliable.
DISADVANTAGES
The following are the disadvantages of the
distributed operating systems:
• The entire communication relies upon a single network and
hence failure in this network will result in the failure of the entire
communication.
• The language used to establish the distributed systems are
not well defined yet.
• This kind of a system is very expensive and it is not readily
available as the underlying software of this system is highly complex.
Network operating System
• The network operating system is similar to distributed operating system
when their architecture is concerned. This type of a system is a system that
runs upon a server and provides the server the ability to manage the
applications, security, users, data and other networking functions.
• The main motive of this kind of a system is to allow shared file and printer
access to multiple computers in a network. The multiplicity of computers
is known in such types of systems whereas in distributed type of
operating systems, the multiplicity is unknown. All the works to be
accessed are dependent upon the server and hence the work is done
manually through the server. The drawback of these kinds of systems is that
if any part of the server’s hardware encounters a problem, then all the
systems will get affected whereas this is not the case in a distributed
operating system.
Network operating System
The following operating systems are the examples of the network
operating system:
• WINDOWS SERVER 2003
• LINUX
• MICROSOFT WINDOWS SERVER 2008
• UNIX
• MAC OS X ETC…
ADVANTAGES OF NETWORK OPERATING SYSTEM
• The following are the advantages of
using a network operating system:
• The security of the system is managed by the server.
• The servers are centralized servers and are highly stable.
• The upgrades to new technologies and hardware can be easily
integrated into the system.
• The elements can be replaced when the need increases.
Disadvantages of the network
operating systems

• These systems are quite expensive.


• The malfunctioning of the server affects the whole
communication and hence the entire network gets affected.
Real Time operating System
These types of operating systems are the types of
those operating systems which do not perform buffering delays.
These operating systems are intended to serve the real time
applications. The deadline of a work is already fixed and hence the
chances of delays in such systems are negligible. The real time
operating system fails if it is not well defined or it does not have a fixed
time constraint.
APPLICATIONS

• They are used in the scientific experiments.


• Medical imaging systems
• Industrial control systems
• Weapon systems
• Air traffic control systems
• Robots
• Thermal power plants etc…
• The applications of such systems can easily help us to figure out the
reasons of having no buffering delays in real time operating systems
.
CLASSIFICATION
• Based upon the strictness of the time constraints, the real time operating
systems can be classified as follows:
• HARD REAL TIME SYSTEMS
• SOFT REAL TIME SYSTEMS
HARD REAL TIME SYSTEMS
• These types of real type systems are the systems which strictly follows the
definition of a real time system. The time constraints are strictly followed
here and hence no delays are accepted.
EXAMPLES
• The following are places where the time constraints are strictly followed:
• Submarine signaling
• RADAR
• Air traffic control systems
• Delays in the signaling of such systems are proved to lead hazardous
accidents.
SOFT REAL TIME SYSTEMS
These types of systems are the systems which are less strict when
compared to the hard time real systems and hence a little bit delay
could be accepted.
EXAMPLES:
The following are the examples of the soft real time systems:
• Multimedia
• Virtual reality
• Video conferencing etc…
Multi processing System
Generally a Computer has a Single Processor means a Computer
have a just one CPU for Processing the instructions. But if we
are Running multiple jobs, then this will decrease the Speed of CPU.
For Increasing the Speed of Processing then we uses the
Multiprocessing, in the Multi Processing there are two or More CPU in
a Single Operating System if one CPU will fail, then other CPU is
used for providing backup to the first CPU.
With the help of Multi- processing, we can Execute Many Jobs at a
Time. All the Operations are divided into the Number of CPU’s.
if first CPU Completed his Work before the Second CPU, then the Work
of Second CPU will be divided into the First and Second.
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System Concepts”,
Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles,
7th edition Pearson Education Limited, 2014 ISBN: 1292061944,
9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach",
Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCOWd7
aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fEyq
RiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU

28
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM

Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Content
1.User and Kernel Mode
2. System Calls
3.Types of system Calls
4. System Program
5. Layered O.S
6.Monolithic and Microlithic kernel
User and kernel Mode
User mode is the mode where all user applications are executed and no
access to hardware resources . The kernel mode has direct access to the
hardware and maintains control over all resources and the system itself. The
central or core elements of the operating system are part of the kernel mode.

Image no:1
Image reference: https://qph.fs.quoracdn.net/main-qimg-2b948999ea0d0e9639dd046d84cf1296
System Calls
• A system call is a mechanism that provides the interface between a
user mode to kernel mode . It is a programmatic method in which a
computer program requests a service from the kernel of the OS.
• System calls are the only entry points for the kernel system. System
call offers the services of the operating system to the user programs.
Following are situations which need system calls in OS:
• Access to hardware devices like scanner, printer, need a system call.
• System calls are used for the creation and management of new
processes.
Types of System Calls
.

There are mainly five types of system calls. These are explained in detail as
follows −
• Process Control
These system calls deal with processes such as process creation, process
termination etc.
• File Management
These system calls are responsible for file manipulation such as creating
a file, reading a file, writing into a file etc.
• Device Management
These system calls are responsible for device manipulation such as
reading from device buffers, writing into device buffers etc.
• Information Maintenance
These system calls handle information and its transfer between the
operating system and the user program.
• Communication
These system calls are useful for inter process communication. They also
deal with creating and deleting a communication connection.
Types of System Calls
• Process control
– end, abort
– load, execute
– create process, terminate process
– get process attributes, set process attributes
– wait for time
– wait event, signal event
– allocate and free memory
• File management
– create file, delete file
– open, close file
– read, write, reposition
– get and set file attributes
Types of System Calls (Cont.)
• Device management
– request device, release device
– read, write, reposition
– get device attributes, set device attributes
– logically attach or detach devices
• Information maintenance
– get time or date, set time or date
– get system data, set system data
– get and set process, file, or device attributes
• Communications
– create, delete communication connection
– send, receive messages
– transfer status information
– attach and detach remote devices
System Programs
System Program: a program, that provides system services to
application programs in kernel mode. Example- compilers, assemblers
Example: say user wants to copy a movies from one drive to another.
So, a copy and paste command is given to system. Accessing the
hardware (i.e. HDD) for content, copying it and making a copy of it,
services can be requested by system services provided by system
programs. They can be divided into:
– File manipulation
– Status information
– File modification
– Programming language support
– Program loading and execution
– Communications
System Programs(Cont_)
System Program is the program that is run in the kernel space. System
call is transition from kernel space to user space.
File management - Create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories
Status information
– Some ask the system for info - date, time, amount of available
memory, disk space, number of users
– Others provide detailed performance, logging, and debugging
information
– Typically, these programs format and print the output to the terminal or
other output devices
– Some systems implement a registry - used to store and retrieve
configuration information
System Programs (Cont.)
• File modification
– Text editors to create and modify files
– Special commands to search contents of files or perform
transformations of the text

• Programming-language support - Compilers, assemblers, debuggers


and interpreters sometimes provided

• Program loading and execution- Absolute loaders, reloadable loaders,


linkage editors, and overlay-loaders, debugging systems for higher-level
and machine language

• Communications - Provide the mechanism for creating virtual


connections among processes, users, and computer systems
– Allow users to send messages to one another’s screens, browse web
pages, send electronic-mail messages, log in remotely, transfer files
from one machine to another
Layered Operating System
Layered Operating System. The operating system is split into various layers In
the layered operating system and each of the layers have different
functionalities. Layering provides a one advantage in an operating system. All
the layers can be defined separately and interact with each other as required.
Also, it is easier to create, maintain and update the system if it is done in the
form of layers. Change in one layer specification does not affect the rest of the
layers .

Image no : 3
image reference : https://slideplayer.com/slide/5086933/
11
Monolithic kernel
• Kernel is the core part of an operating system; it manages the system
resources. Kernel is like a bridge between user applications and hardware
of the computer. The Kernel can be classified further into two categories,
Microkernel and Monolithic Kernel. Microkernel is the one in which user
services and kernel services are kept in separate address space.
• However, in Monolithic kernel user services and kernel services both
are kept in the same address space.
• user space consist of only user application which u want to run. as the
kernel service there is process management, file management, signal
handling, memory management, thread management, and so many
services are present there.
Microkernel and Monolithic
kernel

image no:4
image reference :https://techdifferences.com/wp-content/uploads/2016/12/Microkernel-Vs-Monolithic-K

13
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System Concepts”,
Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles,
7th edition Pearson Education Limited, 2014 ISBN: 1292061944,
9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach",
Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCOWd7
aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fEyq
RiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU

16
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM

Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Content
1. Process concept
2.Process state
3.Digram of Process State
4. CPU Switch From Process to Process
5. Representation of Process Scheduling
Process Concept
• An operating system executes a variety of programs:
– Batch system – jobs
– Time-shared systems – user programs or tasks
• Textbook uses the terms job and process almost
interchangeably
• Process – a program in execution; process execution
must progress in sequential fashion
• A process includes:
– program counter
– stack
– data section
Process in Memory

Image no : 1
image Reference:
https://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/images/Chapter3/3_01_Process_
Memory.jpg

4
Process State
• As a process executes, it changes state
– New: The process is being created
– Running: Instructions are being executed
– Waiting: The process is waiting for some
event to occur
– Ready: The process is waiting to be assigned
to a processor
– Terminated: The process has finished
execution
Diagram of Process state

Image no : 2
Image Reference:https://1.bp.blogspot.com/-
fr63SmDGyPc/VrwoLpX2YSI/AAAAAAAAAUI/msdsEoHQXJQ/s1600/Diagram_of_Process_State
.png
Process Control Block (PCB)
Information associated with each process
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
Process Control Block (PCB)

image no :1
image reference :https://tse2.mm.bing.net/th?id=OIP.rtEkQfe2yZTMP3jxUYnmTQHaF-
&pid=Api&P=0&w=300&h=300

8
CPU Switch From Process to
Process

Image no : 2
Image Reference:
https://tse3.mm.bing.net/th?id=OIP.0isrScNOi2kaYvJoTG4f8QHaE8&pid=Api&P=0&w=300&h=
300

9
Process Control Block (PCB)
Information associated with each process
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
Process Control Block (PCB)

image no :1
image reference :https://tse2.mm.bing.net/th?id=OIP.rtEkQfe2yZTMP3jxUYnmTQHaF-
&pid=Api&P=0&w=300&h=300

11
CPU Switch From Process to
Process

Image no : 2
Image Reference:
https://tse3.mm.bing.net/th?id=OIP.0isrScNOi2kaYvJoTG4f8QHaE8&pid=Api&P=0&w=300&h=
300

12
Ready Queue And Various I/O
Device Queues

Image no :3
Image Reference :
https://tse1.mm.bing.net/th?id=OIP.KLDJthXc0ZApBWWCGWINlQHaF7&pid=Api&P=0&w=300&h=300

13
Representation of Process
Scheduling

Image no : 4
Image Reference :
https://tse3.mm.bing.net/th?id=OIP.5kbbjnEa0FNmwUAbRuTKpQHaFj&pid=Api&P=0&w=234&h=1
77

14
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System Concepts”,
Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles,
7th edition Pearson Education Limited, 2014 ISBN: 1292061944,
9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach",
Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCOWd7
aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fEyq
RiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU

17
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM

Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN . EMPOWER


Content
• 1. CPU Scheduling
• 2. Scheduling Algorithms
• 3.FCFS Scheduling Algorithm
CPU Scheduling
• CPU scheduling is a process which allows one process to use the CPU
while the execution of another process is on hold(in waiting state) due
to unavailability of any resource like I/O etc, thereby making full use
of CPU. The aim of CPU scheduling is to make the system efficient,
fast and fair.
• Whenever the CPU becomes idle, the operating system must select
one of the processes in the ready queue to be executed. The selection
process is carried out by the short-term scheduler (or CPU scheduler).
• The scheduler selects from among the processes in memory that are
ready to execute, and allocates the CPU to one of them.
Alternating Sequence of CPU and
I/O Bursts

Image no :1
image Reference :https://tse4.mm.bing.net/th?id=OIP.StPe7V8FegLIhZVGYN0R_gHaFj&pid=Api&P=0&w=300&h=300
CPU Scheduler
• Selects from among the processes in ready queue, and allocates the
CPU to one of them
– Queue may be ordered in various ways

• CPU scheduling decisions may take place when a process:


1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates

• Scheduling under 1 and 4 is non-preemptive

• Otherwise scheduling is preemptive


Dispatcher
• Dispatcher module gives control of the CPU to the
process selected by the short-term scheduler; this
involves:
– Switching context(Saving PCB)
– Switching to user mode
– Jumping to the proper location in the user
program to restart that program(Loading PCB)
Dispatch latency – time it takes for the dispatcher
to stop one process and start another running
Scheduling Criteria
• CPU Utilization – Keep the CPU as busy as possible

• Throughput – Number of processes that complete their execution


per time unit

• Turnaround Time – Amount of time to execute a particular process

• Waiting Time – Amount of time a process has been waiting in the


ready queue

• Response Time – Amount of time it takes from when a request was


submitted until the first response is produced, not output (for time-
sharing environment)
Scheduling Algorithm
Optimization Criteria
• Max CPU utilization
• Max throughput
• Min turnaround time
• Min waiting time
• Min response time
First-Come, First-Served
(FCFS) Scheduling
Process Burst Time
P1 24
P2 3
P3 3

• Suppose that the processes arrive in the order: P1 , P2 , P3


• The Gantt Chart for the schedule is:

P1 P2 P3

0 24 27 30
• Waiting time for P1 = 0; P2 = 24; P3 = 27

• Average waiting time: (0 + 24 + 27)/3 = 17


FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order:
P2 , P3 , P1
• The Gantt chart for the schedule is:

P2 P3 P1

0 3 6 30

• Waiting time for P1 = 6; P2 = 0; P3 = 3


• Average waiting time: (6 + 0 + 3)/3 = 3
• Much better than previous case

• Convoy effect - short process waits long time behind long process
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System Concepts”, Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles, 7th edition Pearson
Education Limited, 2014 ISBN: 1292061944, 9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach", Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCOWd7aiGz9don
HRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fEyqRiVhbXD
GLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM
Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Content
1. Schedulers
2. Types of Schedulers
3.Interprocess communication
Schedulers
• Long-term scheduler (or job scheduler) –
selects which processes should be brought into
the ready queue
• Short-term scheduler (or CPU scheduler) –
selects which process should be executed next
and allocates CPU
Addition of Medium Term
Scheduling

Image no : 13
image Reference : http://www.cs.jhu.edu/~yairamir/cs418/os2/img012.gif

4
Schedulers (Cont.)
• Short-term scheduler is invoked very frequently
(milliseconds) ⇒ (must be fast)
• Long-term scheduler is invoked very infrequently (seconds,
minutes) ⇒ (may be slow)
• The long-term scheduler controls the degree of
multiprogramming
• Processes can be described as either:
– I/O-bound process – spends more time doing I/O than
computations, many short CPU bursts
– CPU-bound process – spends more time doing
computations; few very long CPU bursts
Context Switch
• When CPU switches to another process, the
system must save the state of the old process and
load the saved state for the new process
• Context-switch time is overhead; the system does
no useful work while switching
• Time dependent on hardware support.
Process Creation
• Parent process create children processes, which, in turn
create other processes, forming a tree of processes
• Resource sharing
– Parent and children share all resources
– Children share subset of parent’s resources
– Parent and child share no resources
• Execution
– Parent and children execute concurrently
– Parent waits until children terminate
Inter Process Communication
• Mechanism for processes to communicate and to synchronize their
actions
• Message system – processes communicate with each other without
resorting to shared variables
• IPC facility provides two operations:
– send(message) – message size fixed or variable
– receive(message)
• If P and Q wish to communicate, they need to:
– establish a communication link between them
– exchange messages via send/receive
• Implementation of communication link
– physical (e.g., shared memory, hardware bus)
– logical (e.g., logical properties)
Communications Models

Image no : 14
Image Reference : http://3.bp.blogspot.com/-
pTLteSAqoDY/UYnpZE1jBUI/AAAAAAAAAJQ/4BnyJIfuwLE/s1600/schramms-.jpg

9
Direct Communication
• Processes must name each other explicitly:
– send (P, message) – send a message to process P
– receive(Q, message) – receive a message from
process Q
Indirect Communication
• Messages are directed and received from mailboxes (also
referred to as ports)
– Each mailbox has a unique id
– Processes can communicate only if they share a
mailbox
• Properties of communication link
– Link established only if processes share a common
mailbox
– A link may be associated with many processes
– Each pair of processes may share several
communication links
– Link may be unidirectional or bi-directional
Indirect
Communication(Cont_)
• Operations
– create a new mailbox
– send and receive messages through
mailbox
– destroy a mailbox
• Primitives are defined as:
send(A, message) – send a message to
mailbox A
receive(A, message) – receive a message
from mailbox A
Indirect Communication(cont _)
• Mailbox sharing
– P1, P2, and P3 share mailbox A
– P1, sends; P2 and P3 receive
– Who gets the message?
• Solutions
– Allow a link to be associated with at most two processes
– Allow only one process at a time to execute a receive
operation
– Allow the system to select arbitrarily the receiver.
Sender is notified who the receiver was.
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System Concepts”,
Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles,
7th edition Pearson Education Limited, 2014 ISBN: 1292061944,
9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach",
Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCOWd7
aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fEyq
RiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU

16
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM
Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Content

1. Process Synchronization
2. Semaphore types
Process Synchronization
• Several Processes run in an Operating System
• Some of them share resources due to which
problems like data inconsistency may arise
• For Example: One process changing the data
in a memory location where another process is
trying to read the data from the same memory
location. It is possible that the data read by
the second process will be erroneous.
Race Condition
• A race condition is an undesirable situation that
occurs when a device or system attempts to
perform two or more operations at the same
time, but because of the nature of the device or
system, the operations must be done in the
proper sequence in order to be done
correctly.
Critical Section
• A Critical Section is a code segment that accesses
shared variables and has to be executed as an
atomic action. It means that in a group of
cooperating processes, at a given point of time,
only one process must be executing its critical
section. If any other process also wants to execute
its critical section, it must wait until the first one
finishes.
Solution to Critical Section
Problem
A solution to the critical section problem must satisfy the following
three conditions:
1. Mutual Exclusion: Out of a group of cooperating processes, only
one process can be in its critical section at a given point of time.
2. Progress: If no process is in its critical section, and if one or
more threads want to execute their critical section then any one of
these threads must be allowed to get into its critical section.
3. Bounded Waiting: After a process makes a request for getting into
its critical section, there is a limit for how many other
processes can get into their critical section, before this
process's request is granted.
Two-Process Solution(Turn
Variable)
For Process Pi For Process Pj
Non - CS Non - CS
while (turn ! = i); while (turn ! = j);
Critical Section Critical Section
turn = j; turn = i ;
Non - CS Non -CS
Two-Process
Solution(Flag
Pi PjVariable)
• Non CS • Non CS
• Flag[i] = T ; • Flag [j] = T ;
• while ( Flag[j] == T ) ; • while ( Flag[i] == T ) ;
• Critical Section • Critical Section
• Flag[i] = F ; • Flag[j]=F ;
Two-Process Solution(Peterson’s)

Image no: 1
Image Reference:

https://tse2.mm.bing.net/th?id=OIP.5ti9i0o5yzi7qKt_3Yr_BwHaFj&pid=Api&P=0&w=300&h=3 0
Multi Process Solution

1.Hardware solution
2.Software solution(Semaphore)
Hardware Solution
• In uni processor system we could disable the interrupts to
occur while a shared variable is being modified.
• Currently executing code would execute without
preemption
Cont…..

Image no: 2
Image Reference : https://tse2.mm.bing.net/th?id=OIP.oQAXuQBReOMyvgJKGVMzKQHaD-&pid=Api&P=0&w=300&h=300
Semaphore(Software Solution )
Semaphore is a integer variable which is used in mutual
exclusion mannerby various concurrent cooperating
process in order to achieve synchronization.

Can be used for


– Critical section (always initialize S=1)
– Order of execution
– Deadlock
Types of Semaphore
• Counting Semaphore: The value of a counting
semaphore can range over an unrestricted
domain.
• Binary Semaphore: The value of a binary
semaphore can range only between 0 and 1.
Binary semaphores are known as mutex locks, as
they are locks that provide mutual exclusion
Image no: 3
IMAGE REFERENCE:
https://doc.micrium.com/download/attachments/12848280/Resource%20Management.14.05.1.jpg?version=1&modificationDate=1385498089000&api=
v2
Wait and Signal

Image no: 4

Image no:4
Image Reference: https://www.geeksforgeeks.org/wp-content/uploads/P-and-V-
operation-in-OS.png
Binary Semaphore

Image no: 5
Image Reference: https://tse3.mm.bing.net/th?id=OIP.QVwSRpNAvyarSR-
6HMECXAHaHa&pid=Api&P=0&w=300&h=300
REFERENCES

Peter B., Silberchatz, A., “Operating System Concepts”, Addison


• “Galvin,
Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles,
7th edition Pearson Education Limited, 2014 ISBN: 1292061944,
9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach", Tata
Mc-Graw- Hill.
E-Video Links

• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCO
Wd7aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fE
yqRiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU

20
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM
Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Content
1.Counting Semaphore
2. Classical problem of process synchronization
3. Reader and Writer problem
4. The Dining Philosopher's Problem
Counting Semaphore
Counting semaphores can be used to control access
to a given resource consisting of a finite number o£
instances.

The semaphore is initialized to the number of


resources
available. Each process that wishes to use a resource
performs wait() operation on the
semaphore(thereby
decrementing the count).

When a process releases a resource, it performs a signal()


operation (incrementin th count)
When th count for th semaphore goes t 0, all resources
are being used. After that, processes that wish to use a
resource will block until the count becomes greater than 0.
Contd….
• We can also use semaphores to solve various
synchronization problems.
• For example, consider two concurrently running processes:
P1 with a statement S1 and P2 with a statement S2. Suppose
we require that S2 be executed only after S1 has
completed. We can implement this scheme readily by letting
P1 and P2 share a common semaphore synch, initialized to 0,
and by inserting the statements
Contd…

In process P2. Because synch is initialized to 0, P2 will


execute 52 only after P1 has invoked signal (synch), which
is after statement 51 has been executed.
Image no: 6
Image reference:
https://media.geeksforgeeks.org/wp-content/cdn-uploads/Semaphores_3.jpg
Classical problem of
process synchronization
• Producer consumer problem: This problem is
generalised in terms of the Producer Consumer
problem, where a finite buffer pool is used to exchange
messages between producer and consumer processes.
• Because the buffer pool has a maximum size, this
problem is often called the Bounded buffer problem.
Contd…
We assume that the pool consists of n buffers each capable
of holding one item.
Solution to this problem is-

The S semaphore provides mutual exclusion for accesses


the buffer pool and is initialized to the value 1.

Creating two counting semaphores "full" and the “ empty" to


keep track of the current number of full and empty buffers
respectively.
The pseudocode of the producer function looks like this: Do
{ // wait until empty > 0 and then decrement 'empty‘
wait(empty);
// acquire lock
wait(S);
/* perform the insert operation in a slot */
// release lock
signal(S); // increment 'full'
signal(full);
}
while(TRUE)
Cont ---
• the producer has just filled a slot in the buffer. Looking at
the above code for a producer, we can see that a producer
first waits until there is at least one empty slot.
• Then it decrements the empty semaphore because, there will
now be one less empty slot, since the producer is going to
insert data in one of those slots.
• Then, it acquires lock on the buffer, so that the consumer
cannot access the buffer until producer completes its
operation.
• After performing the insert operation, the lock is released
and the value of full is incremented because
The pseudocode for the consumer function looks like this:
do
{
// wait until full > 0 and then decrement 'full' wait(full);
// acquire the lock wait(S);

/* perform the remove operation in a slot */

// release the lock signal(S);


// increment 'empty' signal(empty);
}
while(TRUE);
Cont----
• The consumer waits until there is at least one full slot in the
buffer.
• Then it decrements the full semaphore because the number of
occupied slots will be decreased by one, after the consumer
completes its operation.
• After that, the consumer acquires lock on the buffer.
• Following that, the consumer completes the removal
operation so that the data from one of the full slots is
removed.
• Then, the consumer releases the lock.
• Finally, the empty semaphore is incremented by 1, because
the consumer has just removed data from an occupied slot,
thus making it empty.
READER AND WRITER
PROBLEM
Processes(called readers) that only read the shared data, and
never change it,

and there are other processes(called writers)


who may change the data in addition to reading, or instead o
f reading it.There are various type of readers-writers problem, most
centred on relative priorities of readers and writers.

• The code for the writer process looks like this:


while(TRUE)
{
wait(w);
/* perform the write operation */
signal(w);
}
Cont--
• And, the code for the reader process looks like this:
while(TRUE)
{
//acquire lock wait(m); read_count++;
if(read_count == 1) wait(w);
//release lock signal(m);
/* perform the reading operation */
// acquire lock wait(m); read_count--;
if(read_count == 0) signal(w);
// release lock signal(m);
}
The Dining Philosopher's
Problem
• It involves the allocation of limited resources to a group of processes
in a deadlock-free and starvation-free manner.
• There are five philosophers sitting around a table, in which there
are five chopsticks/forks kept beside them and a bowl of
rice in the centre,
Contd…
• philosopher may pick up only one chopstick at a time.
Obviously, she cannot pick up a chopstick that is already in
the hand of a neighbor. When a hungry philosopher has
both her chopsticks at the same time, she eats
without releasing her chopsticks. When she is finished
eating, she puts down both of her chopsticks and starts
thinking again.
Contd…

Image no : 6
IMAGE REFRENCE:. http://micro-os-plus.github.io/assets/images/2016/semaphore-multi-thread.png
Cont.
• From the problem statement, it is clear that a philosopher can
think for an indefinite amount of time. But when a
philosopher starts eating, he has to stop at some point of
time. The philosopher is in an endless cycle of thinking and
eating.
• An array of five semaphores, stick[5], for each of the five
chopsticks.
Solution1
• First of all take left fork then right fork
The code for each philosopher looks
like: while(TRUE)
{
wait(stick[i]); /* mod is used because if i=5, next
chopstick is 1 (dining table is circular) */
wait(stick[(i+1) % 5]);
/* eat */
signal(stick[i]);
signal(stick[(i+1) %
5]);
/* think */ }
Solutions
Several possible remedies to the deadlock problem are listed
next.
• Allow at most four philosophers to be sitting
simultaneously at the table.
• Allow a philosopher to pick up her chopsticks only if both
chopsticks are available (to do this, she must pick them up in
a critical section).
• Use an asymmetric solution; that is, an odd philosopher
picks up first her left chopstick and then her right
chopstick, whereas an even philosopher picks up her right
chopstick and then her left chopstick
CONT--
Arbitrator (Naive and Advanced).

• The naive arbitrator solution is have one arbitrator (a


mutex for example). Have each of the philosopher ask the
arbitrator for permission to eat.
• This solution allows one philosopher to eat at a time.
When they are done, another philosopher can ask for
permission to eat.
• The advanced arbitrator solution is to implement a class
that determines if the philosopher's forks are in the
arbitrator's possession.
REFERENCES

Peter B., Silberchatz, A., “Operating System Concepts”, Addison


• “Galvin,
Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles,
7th edition Pearson Education Limited, 2014 ISBN: 1292061944,
9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach", Tata
Mc-Graw- Hill.
E-Video Links

• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCO
Wd7aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fE
yqRiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU

23
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM

Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Remote Procedure Call

• Remote Procedure Call (RPC) is a powerful


technique for constructing distributed, client-server
based applications.
• It is based on extending the conventional local
procedure calling, so that the called procedure need
not exist in the same address space as the calling
procedure.
• The two processes may be on the same system, or
they may be on different systems with a network
connecting them.
Remote Procedure Call

Image no : 2
Image reference :https://www.geeksforgeeks.org/remote-procedure-call-rpc-in-operating-system/
Remote Procedure Call

Image no : 3
Image reference:http://web.mit.edu/6.033/1997/reports/dp1-danlief.html
Steps take place during a RPC:

1. A client invokes a client stub procedure, passing


parameters in the usual way. The client stub resides
within the client’s own address space.
2. The client stub marshalls(pack) the parameters
into a message. Marshalling includes converting the
representation of the parameters into a standard
format, and copying each parameter into the message.
3. The client stub passes the message to the transport
layer, which sends it to the remote server machine.
Steps take place during a RPC:
4. On the server, the transport layer passes the message to
a server stub, which demarshalls(unpack) the
parameters and calls the desired server routine using the
regular procedure call mechanism.
5. When the server procedure completes, it returns to the
server stub (e.g., via a normal procedure call return),
which marshalls the return values into a message. The
server stub then hands the message to the transport layer.
6. The transport layer sends the result message back to the
client transport layer, which hands the message back to
the client stub.
7. The client stub de marshalls the return parameters and
execution returns to the caller.
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating
System Concepts”, Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals
and Design Principles, 7th edition Pearson
Education Limited, 2014 ISBN: 1292061944,
9781292061948.
• Andrew Tananbaum, “Operating System”, PHI
Learning.
• Godbole, Kahate, "Operating System: A Concept
Based Approach", Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZ
Ngf8&list=PLxCzCOWd7aiGz9donHRrE9I3
Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt9
7EkA&list=PLBlnK6fEyqRiVhbXDGLXDk_
OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM
Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Content
• 1. Deadlocks
• 2. Resource Allocation Graph
The Deadlock Problem
• A deadlock consists of a set of
blocked processes, each holding a
resource and waiting to acquire a
resource held by another process in
the set

• Example
– A system has 2 disk drives
– P1 and P2 each hold one disk drive
and each needs the other one
Bridge Crossing
Example

Image no : 1
Image Reference : https://scanftree.com/operating-system/images/bridge-crossing-example.jpg

• Traffic only in one direction


• The resource is a one-lane bridge
• If a deadlock occurs, it can be resolved if one car
backs up (pre-empt resources and rollback)‫‏‬
• Several cars may have to be backed up if a deadlock
occurs
• Starvation is possible
System Model
• Resource types R1, R2, . . ., Rm
CPU cycles, memory space,
I/O devices
• Each resource type Ri has 1 or
more instances
• Each process utilizes a resource as
follows:
– request
– use
– release
Deadlock
Characterization
Deadlock can arise if four conditions hold simultaneously.
• Mutual exclusion: only one process at a time can use a
resource
• Hold and wait: a process holding at least one resource
is waiting to acquire additional resources held by other
processes
• No pre emption: a resource can be released only
voluntarily by the process holding it after that process has
completed its task
• Circular wait: there exists a set {P0, P1, …, P0} of
waiting processes such that P0 is waiting for a resource
that is held by P1, P1 is waiting for a resource that is held
by P2, …, Pn–1 is waiting for a resource that is held by
Pn, and Pn is waiting for a resource that is held by P0
Resource-Allocation Graph

Image no : 2
• Image Reference: https://tse3.mm.bing.net/th?id=OIP.o6AEzS2IP2QXbXsscjDIzAHaEK&pid=Api&P=0&w=300&h=300

A set of vertices V and a set of edges E.


• V is partitioned into two types:
P = {P1, P2,‫…‏‬,‫‏‬Pn}, the set consisting of all
the processes in the system
R = {R1, R2,‫…‏‬,‫‏‬Rm}, the set consisting of all
resource types in the system
• Request edge – directed edge P1 Rj
• Assignment edge – directed edge Rj Pi
Resource-Allocation

Graph
Process
(Cont.)‫‏‬

• Resource Type with 4 instances

• Pi requests instance of Rj

P
i
• Pi is holding an instance
Rj
of Rj

P
i
Rj
Resource Allocation Graph
With A Deadlock
Before P3 requested an After P3 requested an
instance of R2 instance of R2

Image no : 3
Image Reference : https://tse1.mm.bing.net/th?id=OIP.W0qaHbDoN6hR0DwtFqURWgHaFj&pid=Api&P=0&w=300&h=300
Graph With A Cycle But No
Deadlock

Image no : 4
Image Reference :
https://tse3.mm.bing.net/th?id=OIP.g1LFsjMxijZlfcwoNQCGmwHaFj&pid=Api&P=0&w=300&h=300

Process P4 may release its instance of


resource type R2.That resource can then
be allocated to P3, thereby breaking the
cycle.
Relationship of cycles to
deadlocks
• If a resource allocation graph contains no
cycles no deadlock

• If a resource allocation graph contains a


cycle and if only one instance exists per
resource type deadlock

• If a resource allocation graph contains a


cycle and and if several instances exists per
resource type possibility of deadlock
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System
Concepts”, Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design
Principles, 7th edition Pearson Education Limited, 2014
ISBN: 1292061944, 9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based
Approach", Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PL
xCzCOWd7aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=P
LBlnK6fEyqRiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM
Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN .


EMPOWER
Content
• 1. Deadlock Prevention
• 2.Deadlock Avoidance
Deadlock Prevention
To prevent deadlock, we can restrain the ways that a request can be made

• Mutual Exclusion – The mutual-exclusion


condition must hold for non-sharable
resources
Hold and Wait – we must guarantee that
whenever a process requests a resource, it
does not hold any other resources
– Require a process to request and be
allocated all its resources before it begins
execution, or allow a process to request
resources only when the process has none
result:
Deadlock Prevention
• No Pre emption –
(Cont.)‫‏‬
– If a process that is holding some resources requests
another resource that cannot be immediately
allocated to it, then all resources currently being held
are released
– Pre empted resources are added to the list of
resources for which the process is waiting
– A process will be restarted only when it can regain its
old resources, as well as the new ones that it is
requesting

• Circular Wait – impose a total ordering of all resource


types, and require that each process requests resources in
an increasing order of enumeration. For example:
F(tape drive) = 1
F(disk drive) = 5
F(printer) = 12
Deadlock Avoidance

• Simplest and most useful model requires


that each process declare the maximum
number of resources of each type that it
may need.

• The deadlock-avoidance algorithm


dynamically examines the resource-
allocation state to ensure that there can
never be a circular-wait condition
Safe State
• When a process requests an available resource, the
system must decide if immediate allocation leaves the
system in a safe state
– A system is in a safe state only if there exists a safe
sequence,A sequence of processes <P1, P2, …, Pn> is
a safe sequence for the current allocation state if, for
each Pi, the resource requests that Pi can still make,
can be satisfied by currently available resources plus
resources held by all Pj, with j < i.
– That is:If the Pi resource needs are not immediately
available, then Pi can wait until all Pj have finished
When Pj is finished, Pi can obtain needed resources,
execute, return allocated resources, and terminate
– When Pi terminates, Pi +1 can obtain its needed
resources, and so on
Safe State (continued)‫‏‬
• If a system is in safe state no
deadlocks

• If a system is in unsafe state


possibility of deadlock

• Avoidance ensure that a system


will never enter an unsafe state
Safe, Unsafe , Deadlock
State

Image no : 5
Image Reference :https://tse3.mm.bing.net/th?id=OIP.QZyYnenFXiie-MKkr-
aplQHaHa&pid=Api&P=0&w=300&h=300
Avoidance Algorithms
• For a single instance of a resource
type, use a resource-allocation graph

• For multiple instances of a resource


type, use the banker’s algorithm
Resource-Allocation
Graph Scheme
• Introduce a new kind of edge called a claim edge

• Claim edge Pi Rj indicates that


process Pj may request resource Rj; which is represented
by a dashed line

• A claim edge converts to a request edge when a process


requests a resource

• A request edge converts to an assignment edge when the


resource is allocated to the process

• When a resource is released by a process, an assignment


edge reconverts to a claim edge
Resource-Allocation
Graph with Claim Edges

Assignmen
Reques
t
t
edge
edge

Claim
Clai edge
m IMAGE NO : 7
edge IMAGE NO: 6
Image Reference :https://image.slidesharecdn.com/mca-iiosu-3deadlockiosystems-150318000401-
conversion-gate01/95/mca-ii-os-u3-dead-lock-io-systems-27-638.jpg?cb=1426637118
Unsafe State In
Resource-Allocation
Assignmen
Graph
Reques
t
t
edge
edge

Assignmen
Clai t
m edge
IMAGE NO :7
edge IMAGE REFERENCE : https://tse1.mm.bing.net/th?id=OIP.XP68CYHuJrnAob-
Wc5lOvwHaFj&pid=Api&P=0&w=231&h=174
Resource-Allocation
Graph Algorithm
• Suppose that process Pi requests a
resource Rj

• The request can be granted only if


converting the request edge to an
assignment edge does not result in the
formation of a cycle in the resource
allocation graph
Resource-Allocation
Graph Algorithm
• Suppose that process Pi requests a
resource Rj

• The request can be granted only if


converting the request edge to an
assignment edge does not result in the
formation of a cycle in the resource
allocation graph
Data Structures: Banker’s
Algorithm
Let n = number of processes, and m = number of
resources types.
• Available: Vector of length m.
– If available [j] = k, there are k instances of resource
type Rj available.
• Max: n x m matrix.
– If Max [i,j] = k, then process Pi may request at most
k instances of resource type Rj.
• Allocation: n x m matrix.
– If Allocation[i,j] = k then Pi is currently allocated k
instances of Rj.
• Need: n x m matrix.
– If Need[i,j] = k, then Pi may need k more instances
of Rj to complete its task.Need [i,j] = Max[i,j] –
Allocation [i,j]
Banker’s Safety
Algorithm
• 1) Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively.
Initialize: Work = Available
Finish[i] = false; for i=1, 2, 3, 4….n

• 2) Find an i such that both


a) Finish[i] = false
b) Needi <= Work if no such i exists goto step (4)

• 3) Work = Work + Allocation


Finish[i] = true
goto step (2)

• 4) if finish [i] = true for all i


then the system is in a safe state
Banker’s Resource-
Request
1)If Request <= Need
Algorithm
i i
Goto step (2) ; otherwise, raise an error condition, since the
process has exceeded its maximum claim.
2) If Requesti <= Available Goto step (3); otherwise,
Pi must wait, since the resources are not available.
3) Have the system pretend to have allocated the requested
resources to process Pi by modifying the state as
follows:
Available = Available – Requesti
Allocationi = Allocationi + Requesti
Needi = Needi– Requesti
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System
Concepts”, Addison Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design
Principles, 7th edition Pearson Education Limited, 2014
ISBN: 1292061944, 9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based
Approach", Tata Mc-Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PL
xCzCOWd7aiGz9donHRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=P
LBlnK6fEyqRiVhbXDGLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM
Instructor: Ms. Akansha Moral

Introduction to Operating System DISCOVER . LEARN . EMPOWER


Deadlock
Detection
Deadlock Detection
• If a system does not employ either a deadlock-prevention or
a deadlock avoidance algorithm, then a deadlock situation
may occur. In this environment, the system must provide:
– An algorithm that examines the state of the system to
determine whether a deadlock has occurred
– An algorithm to recover from the deadlock
• A detection-and-recovery scheme requires various kinds of
overhead
– Run-time costs of maintaining necessary information
and executing the detection algorithm
– Potential losses inherent in recovering from a deadlock
Single Instance of Each
Resource Type
Requires the creation and maintenance of a wait-for graph
– Consists of a variant of the resource-allocation graph
– The graph is obtained by removing the resource nodes
from a resource-allocation graph and collapsing the
appropriate edges
– Consequently; all nodes are processes
– Pi Pj if Pi is waiting for Pj.
– Periodically invoke an algorithm that searches for a cycle
in the graph
– If there is a cycle, there exists a deadlock
– An algorithm to detect a cycle in a graph requires an order
of n2 operations, where n is the number of vertices in the
graph
Resource-Allocation Graph and
Wait-for Graph

Resource-Allocation Graph Corresponding wait-for graph


Image no: 1
Image Reference: https://image.slidesharecdn.com/mch7deadlock-131217091250-phpapp02/95/mch7-deadlock-41-
638.jpg?cb=1387271605
Multiple Instances of a
Resource Type
Required data structures:

• Available: A vector of length m indicates the number of


available resources of each type.

• Allocation: An n x m matrix defines the number of


resources of each type currently allocated to each
process.

• Request: An n x m matrix indicates the current request


of each process. If Request [ij] = k, then process Pi is
requesting k more instances of resource type. Rj.
Detection-Algorithm Usage
• When should we invoke the detection algorithm? The answer depends
on two factors :
– How often is a deadlock likely to occur?
– How many processes will be affected by deadlock when it happens?

• If the detection algorithm is invoked arbitrarily, there may be many


cycles in the resource graph and so we would not be able to tell which
one of the many deadlocked processes “caused” the deadlock
• If the detection algorithm is invoked for every resource request, such an
action will incur a considerable overhead in computation time
• A less expensive alternative is to invoke the algorithm when CPU
utilization drops below 40%, for example
– This is based on the observation that a deadlock eventually cripples
system throughput and causes CPU utilization to drop
Recovery From
Deadlock
Recovery from Deadlock
• Two Approaches
– Process Termination
– Resource Pre emption
Process Termination
Abort all deadlocked processes
– This approach will break the deadlock, but at great expense
Abort one process at a time until the deadlock cycle is eliminated
– This approach incurs considerable overhead, since, after each process is
aborted, a deadlock-detection algorithm must be re-invoked to determine
whether any processes are still deadlocked
Many factors may affect which process is chosen for termination
– What is the priority of the process?
– How long has the process run so far and how much longer will the
process need to run before completing its task?
– How many more resources does the process need in order to finish its
task?
– How many processes will need to be terminated?
Resource Pre emption
• With this approach, we successively pre empt some resources
from processes and give these resources to other processes
until the deadlock cycle is broken
• When pre emption is required to deal with deadlocks, then
three issues need to be addressed:
– Selecting a victim – Which resources and which processes
are to be pre empted?
– Rollback – If we pre empt a resource from a process, what
should be done with that process?
– Starvation – How do we ensure that starvation will not
occur? That is, how can we guarantee that resources will
not always be pr eempted from the same process?
REFERENCES
• “Galvin, Peter B., Silberchatz, A., “Operating System Concepts”, Addison
Wesley, 9th Edition.
• William Stallings, Operating Systems: Internals and Design Principles, 7th edition
Pearson Education Limited, 2014 ISBN: 1292061944, 9781292061948.
• Andrew Tananbaum, “Operating System”, PHI Learning.
• Godbole, Kahate, "Operating System: A Concept Based Approach", Tata Mc-
Graw- Hill.
E-Video Links
• https://www.youtube.com/watch?v=bkSWJJZNgf8&list=PLxCzCOWd7aiGz9don
HRrE9I3Mwn6XdP8p
• https://www.youtube.com/watch?v=vBURTt97EkA&list=PLBlnK6fEyqRiVhbXD
GLXDk_OQAeuVcp2O
• https://nptel.ac.in/courses/106/108/106108101/
THANK YOU

You might also like