Operating System Unit 1
Operating System Unit 1
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
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
• 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.
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
28
APEX INSTITUTE OF TECHNOLOGY
Bachelor of Engineering (Computer Science & Engineering)
OPERATING SYSTEM
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
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
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
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
P1 P2 P3
0 24 27 30
• Waiting time for P1 = 0; P2 = 24; P3 = 27
P2 P3 P1
0 3 6 30
• 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
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
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.
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
• 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
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).
• 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
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:
• 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
Image no : 2
• Image Reference: https://tse3.mm.bing.net/th?id=OIP.o6AEzS2IP2QXbXsscjDIzAHaEK&pid=Api&P=0&w=300&h=300
• 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
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
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