SlideShare une entreprise Scribd logo
1  sur  65
Télécharger pour lire hors ligne
Unit –IV
Introduction to Operating System, Process and
threads and Deadlocksthreads and Deadlocks
Syllabus
• Evolution of O.S.
• Function of OS.
• Types various OS.
• OS concepts.• OS concepts.
• OS structure
• Processes, threads, Inter process communication, IPC problems.
• Scheduling Resources,
• introduction to deadlock, ostrich algorithm,
• Deadlock detection and recovery,
• avoidance, prevention, other aspects
Concept of operating system
• It is an interface between user & hardware of a computer system
• It is system software which may be viewed as an organized
collection of software consisting of procedures for operating a
computer & providing environment for execution of program.computer & providing environment for execution of program.
• But what does it do?
to provide an orderly and controlled allocation of the
processors, memories and I/O devices among the various
programs competing for them
Real Life Example:
• Government
FIRST GENERATION (1945-55)
– Computer is made up of vacuum tubes.
– Programs are written in assembly language.
– Punched cards are used to upload programs and store a data.
FIRST GENERATION (1945-55)
Early batch system
– bring cards to 1401
– read cards to tape
– put tape on 7094 which does computing
– put tape on 1401 which prints output
Computer System
SECOND GENERATION
(1955-65)
– Transistors are used.
– Main frame was developed.
– Programs written in assembly language and in Fortran.
– Punched cards are used.
– Batch processing used.
Evolution of O.S. Function
• First generation 1945 – 1955
– vacuum tubes, plug boards (no OS)
• Second generation 1955 – 1965
– transistors, batch systems
• Third generation 1965 – 1980
– ICs and multiprogramming
• Fourth generation 1980 – present
– personal computers, hand-held devices, sensors
Hardware and software combine to solve specific problems
– Software: Application logic providing a service or solves some
problem: entertainment, information management, scientific problem
solving, system control, forwarding packets in a router, etc.
– Hardware: provides the basic computing resources (Processor(s),
Memory, System Bus and I/O modules).
• Software is divided into two categories:• Software is divided into two categories:
– System software: simplifies application programming by creating
convenient to use programming and run-time environments.
• Resource Management: time and space multiplexing of system
resources
• Extended virtual machine: standardized interfaces and abstractions
simplify programming and system use
– Application software: used directly by user (person, another program
or computer system) to solve some problem
Cont ..
– Functions of an Operating System
• Resource management
• User environment
– Design Approaches
• Layered, Kernel and Virtual
– Types of Advanced Operating Systems
• Distributed, Multiprocessor, Database and Real-time
– Overview of UNIX (why do we care)
Functions of an OS
– Resource Management
• Time management - temporal properties
– CPU and disk transfer scheduling
• Space management
– main and secondary storage allocation
• Synchronization and deadlock handling
• Accounting and status information
Functions of an OS (cont)
– User Environment - OS layer transforms bare hardware machine into
higher level abstractions
• Execution environment - process management, file manipulation,
interrupt handling, I/O operations, language.
• Error detection and handling
• Protection and security• Protection and security
• Fault tolerance and failure recovery
Design Approaches
– Deal with complexities of modern systems
– Separation of Policies and Mechanisms
• Policies - What should be done
• Mechanisms - How it should be done
– Three common approaches:
• Layered Approach• Layered Approach
• Kernel Approach
• Virtual Machine Approach
Layered Approach
Level Name Objects Example
13 Shell User programming env. Bash statements
12 User process User process Quit,kill,suspend,resume
11 Directories Directories Create,destroy,attach,list
Simplifies design, implementation and testing
Modular by dividing OS into functional layers.
11 Directories Directories Create,destroy,attach,list
10 Devices External: printer,display Create,open,close
9 File system Files Create,open,close
8 Communications Pipes Crreate,open,close
7 Virtual memory Segments,pages Read,write,fetch
6 Local secondary store Blocks,channel Read,write,fetch
5 Primitive process Process,semaphore Suspend,resume,wait
4 Interrupts Interrupt-handlers Invoke,mask,retry
3 Procedures Procedure,stack,display Mark stack,call,return
2 Instruction set Evaluation stack Load,store,add
1 Electronic circuit Registers,gates,buses Clear,transfer,activate
Kernel Based Approach
Kernel contains a collection of primitives which are used to build the
OS
OS implements policy
Kernel implements mechanisms
Hardware
kernel
Operating system
Virtual Machine Approach
Virtual software layer over hardware
Illusion of multiple instances of hardware
Supports multiple instances of OSs
Hardware
Virtual machine software
VM1 VM2 VM3 VM4
Types of Advanced OSs
Distributed Operating Systems
Multiprocessor Operating Systems
Database Operating Systems
Real-time Operating Systems
Distributed Operating Systems
– Controls and manages resources for a network of autonomous
computers
• manage both hardware and software resources
• behaves as a single monolithic system.
– User not aware of program or resource location
– Design issues same as traditional systems– Design issues same as traditional systems
– Practical issues:
• lack of shared memory
• lack of global clock
• unpredictable communication delays.
Multiprocessor Operating Systems
– Consists of a set of processors that
• share a set of physical memory blocks
• share a common clock
• "share" over an interconnection network.
– Control and manage resources
• hardware and software resources• hardware and software resources
• viewed as a uniprocessor system.
– Design issues same as traditional system.
– Practical issues:
• increased complexity of synchronization, scheduling, memory
management, protection and security
Database Operating Systems
– Database systems place increased demands on an operating system to
efficiently support:
• concept of a transactions
• manage large volumes of data
• concurrency control
• system failure control
Real-time Operating Systems
– Place application specific special requirements on an operating system.
– Policies and mechanisms are geared to ensuring jobs meet their
deadlines.
– Problem is one of resource scheduling and overall system utilization.
OS Concepts
– Processes
– Files
– System Calls
– The command interpreter
– Signals
OS Concepts - Processes
– A process is program in execution
– It consists of following:
Executable program
Program’s data
Stack and stack pointer
Program counter and other CPU registers
Details of opened files
OS Concepts – Files
– Every OS provides system calls for file management which include:
File creation
File deletion
Read & write operations
Files are stored in directory with system calls:
To put a file in directory
To remove a file from a directory
OS Concepts - Files
OS Concepts – System Calls
– Provide an interface to the services made available by an operating
system.
– User program interact with operating system through system calls.
– Normally available as library functions in a high level language
– System calls are available for:
Process management
Memory management
File operations
Input/output operations
OS Concepts – Command Interpreter
– Provides command-line interface
– Allows user to enter a command on command lone prompt
– The command to be executed are implemented in two ways:
• Command interpreter itself contains the necessary code to be
executed.
• Command is implemented through a system file. To execute a• Command is implemented through a system file. To execute a
command the necessary system file is loaded into memory and
executed.
OS Concepts – Signals
– Are to notify a process that a particular event has occurred.
– Can be synchronous and asynchronous.
OS Structure
– Monolithic system
– Layered system
– Virtual machines
– Client-server model
OS Structure – Monolithic system
– Written as collection of procedures
– Services provided through system calls.
OS Structure – Layered systems
• Based on layered approach consists of number of layers, each built on top
of lower layer.
OS Structure- Virtual Machine
– A single real machine gives an illusion of several virtual machines,
each having its own:
• Virtual processor
• Virtual storage and input/output devices
OS Structure – Client server model
• Kernel part is very small.
• Most of the OS functions are implemented using user processes.
Processes
– A process is program in execution
– It consists of following:
Executable program
Program’s data
Stack and stack pointer
Program counter and other CPU registers
Details of opened files
Processes States
1.New 2. Ready 3.Running 4.Blocked 5.Terminated
Processes
Control Block
• A data structure used to
keep track of all
information concerning
a process
• Includes:
• Process numberProcess number
• Priority
• Process state
• Program counter
• Registers
Threads
• Low cost alternative to processes for certain kind of concurrent
applications.
Benefits of Threads
– Improves responsiveness
– Takes less time terminate a thread than a process
– Takes less time to switch between two threads within the same process.
– Enhance efficiency in communication.
– Allows an application to have several different threads of activity
within the same address space.
Inter Process Communication
• Includes thread synchronization and data exchange between threads beyond
the process boundaries.
• Two methods of IPC:
• Through shared memory
• Through message passing.
IPC Problems
The Bounded Buffer (Producer-Consumer) Problem
– Assume there are n slots capable of holding one item. Process producer
will produce items to fill slots and process consumer will consume the
items in these slots.
– There is no information on the relative speeds of processes.
– Devise a protocol which will allow these processes to run concurrently.– Devise a protocol which will allow these processes to run concurrently.
– A common buffer whose elements (slots) will be filled/emptied by the
producer/consumer is needed.
– The consumer should not try to consume items which have not been
produced yet (i.e. the consumer can not consume empty slots).
– The producer should not try to put item into filled slots.
IPC Problems
The Readers and Writers Problem
– Imagine a big database, such as an airline reservation system, with
many competing processes wishing to read and write.
– It is acceptable to have multiple processes reading the database at the
same time, if one process is writing to the database, no other processes
may have access to the database, not even readers.may have access to the database, not even readers.
– The solution is that the readers have priority over writers.
– If a writer appears while several readers are in the database, the writer
must wait.
IPC Problems
The Dining Philosophers Problem
– There are N philosophers spending their lives thinking and eating in a
room. In their round table there is a plate of infinite rice and N
chopsticks.
– From time to time, a philosopher gets hungry.
– He tries to pick up the two chopsticks that are on his right and his left.– He tries to pick up the two chopsticks that are on his right and his left.
– A philosopher that picks both chopsticks successfully (one at a time)
starts eating.
– A philosopher may pick one chopstick at a time.
– When a philosopher finishes eating, he puts down both of his
chopsticks to their original position and he starts thinking again.
– The question is to write a program which does not let any philosopher
to die due to hunger (i.e. no deadlocks).
Process Scheduling
– Fundamental operating system function.
– Scheduling is a set of policies and mechanisms supported by operating
systems that controls the order in which the work to be done is
completed.
– Scheduler manages the running processes in the system
– There are various criteria/goals by which a scheduling algorithm can be– There are various criteria/goals by which a scheduling algorithm can be
evaluated:
1. FAIRNESS: Make sure each process gets its fair share of the CPU
2. EFFICIENCY: Keep the CPU busy 100% of the time
3. RESPONSE TIME: Minimize response time for interactive users
4. TURNAROUND: Minimize the time batch users must wait for output
5. THROUGHPUT: Maximize the number of jobs processed in a given
timeframe
Process Scheduling Algorithms
• Pre-emptive Scheduling
– Scheduler suspends a running process
– Allows other processes to run without each process having to
complete
– Must be careful with real-time
– Must be careful to avoid race conditions
– Multiuser friendly– Multiuser friendly
• Non pre-emptive Scheduling
– Run each process to completion
– Not efficient for I/O bound applications
– Easy to understand and implement
– No race condition issues
– Must prevent starvation
– No way to guarantee turnaround
Optimization Criteria
• Each scheduling algorithm must be evaluated from how it optimizes the
following variables:
– 1. Max CPU utilization
2. Max throughput
3. Min turnaround time
4. Min waiting time
5. Min response time
First-Come, First Served
– FCFS) same as FIFO
– Simple, fair, but poor performance.
– Average queuing time may be long.
Round Robin Scheduling
– Quantum: A time interval that a process is allowed to run
– – A process may not use its entire quantum if it needs to block for I/O
• With Round Robin scheduling each process is given a quantum of time
• When quantum expires or process blocks the scheduler picks the next
process to run
• Round robin scheduling requires a queue
– queue to get next process to run
– After process has run for its quantum, Enquire it.
Priority Scheduling
• Used when all processes are not equally important
• Priority Scheduling
– Each process is assigned a priority
– The process with the highest priority is chosen to run by the
scheduler
• Scheduler must ensure fairness
– May lower or increase priorities of some processes to ensure that:– May lower or increase priorities of some processes to ensure that:
• Processes are not getting too much CPU time
• Process are not getting too little CPU time
• Often priorities are grouped into classes
• Each process within a priority class must also be scheduled
– Can use round robin scheduling
• Starvation occurs if a low priority process never runs. Solution: build
aging into a variable priority
Shortest Job First
– When multiple batch jobs are sitting in a queue with the same priority,
the scheduler runs the shortest job first.
– Optimal for minimizing queuing time, but impossible to implement.
– Predicting the time the process will use on its next schedule:
t( n+1 ) = w * t( n ) + ( 1 - w ) * T( n )
– Here: t(n+1) is time of next burst.
t(n) is time of current burst.
T(n) is average of all previous bursts .
W is a weighting factor emphasizing current or
previous bursts.
• Traffic only in one direction.
DEADLOCKS Bridge Crossing
Example
• Traffic only in one direction.
• Each section of a bridge can be viewed as a resource.
• If a deadlock occurs, it can be resolved if one car backs up (preempt
resources and rollback).
• Several cars may have to be backed up if a deadlock occurs.
• Starvation is possible.
DEADLOCKS
NECESSARY CONDITIONS
ALL of these four must happen simultaneously for a deadlock to occur:
Mutual exclusion
One or more than one resource must be held by a process in a non-sharable
(exclusive) mode.
Hold and Wait
A process holds a resource while waiting for another resource.
No Preemption
There is only voluntary release of a resource - nobody else can make a process
give up a resource.
Circular Wait
Process A waits for Process B waits for Process C .... waits for Process A.
• If the graph contains no cycles, then no process is deadlocked.
• If there is a cycle, then:
a) If resource types have multiple instances, then deadlock MAY exist.
b) If each resource type has 1 instance, then deadlock has occurred.
DEADLOCKS RESOURCE
ALLOCATION GRAPH
R3 Assigned to P3
Resource allocation graph
P2 Requests P3
DEADLOCKS RESOURCE
ALLOCATION GRAPH
Resource allocation graph
with a deadlock.
Resource allocation graph
with a cycle but no deadlock.
HOW TO HANDLE DEADLOCKS – GENERAL STRATEGIES
There are three methods:
Ignore Deadlocks:
Ensure deadlock never occurs using either
Prevention Prevent any one of the 4 conditions from happening.
DEADLOCKS Strategy
Most Operating systems do this!!
Prevention Prevent any one of the 4 conditions from happening.
Avoidance Allow all deadlock conditions, but calculate cycles about to happen
and stop dangerous operations..
Allow deadlock to happen. This requires using both:
Detection Know a deadlock has occurred.
Recovery Regain the resources.
Do not allow one of the four conditions to occur.
Mutual exclusion:
a) Automatically holds for printers and other non-sharables.
b) Shared entities (read only files) don't need mutual exclusion (and aren’t
susceptible to deadlock.)
DEADLOCKS Deadlock
Prevention
susceptible to deadlock.)
c) Prevention not possible, since some devices are intrinsically non-sharable.
Hold and wait:
a) Collect all resources before execution.
b) A particular resource can only be requested when no others are being held. A
sequence of resources is always collected beginning with the same one.
c) Utilization is low, starvation possible.
Do not allow one of the four conditions to occur.
No preemption:
a) Release any resource already being held if the process can't get an additional
resource.
b) Allow preemption - if a needed resource is held by another process, which is also
waiting on some resource, steal it. Otherwise wait.
DEADLOCKS Deadlock
Prevention
Circular wait:
a) Number resources and only request in ascending order.
EACH of these prevention techniques may cause a decrease in utilization
and/or resources. For this reason, prevention isn't necessarily the best
technique.
Prevention is generally the easiest to implement.
If we have prior knowledge of how resources will be requested, it's possible to determine if we
are entering an "unsafe" state.
Possible states are:
Deadlock No forward progress can be made.
Unsafe state A state that may allow deadlock.
DEADLOCKS Deadlock
Avoidance
Unsafe state A state that may allow deadlock.
Safe state A state is safe if a sequence of processes exist such that there are enough
resources for the first to finish, and as each finishes and releases its
resources there are enough for the next to finish.
The rule is simple: If a request allocation would cause an unsafe state, do not honor that
request.
NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks.
NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks.
DEADLOCKS Deadlock
Avoidance
SAFE
DEADLOCK
UNSAFE
Only with luck will
processes avoid
deadlock.
O.S. can avoid
deadlock.
A method used to determine if a particular state is safe. It's safe if there exists a sequence
of processes such that for all the processes, there’s a way to avoid deadlock:
The algorithm uses these variables:
Need[I] – the remaining resource needs of each process.
DEADLOCKS
Safety Algorithm
Deadlock
Avoidance
Need[I] – the remaining resource needs of each process.
Work - Temporary variable – how many of the resource are currently available.
Finish[I] – flag for each process showing we’ve analyzed that process or not.
need <= available + allocated[0] + .. + allocated[I-1] Sign of success
Let work and finish be vectors of length m and n respectively.
Need an algorithm that determines
if deadlock occurred.
Also need a means of recovering
from that deadlock.
DEADLOCKS Deadlock Detection
SINGLE INSTANCE OF A RESOURCE TYPE
• Wait-for graph == remove the resources
from the usual graph and collapse edges.
• An edge from p(j) to p(i) implies that p(j) is
waiting for p(i) to release.
PROCESS TERMINATION:
• Could delete all the processes in the deadlock -- this is expensive.
• Delete one at a time until deadlock is broken ( time consuming ).
• Select who to terminate based on priority, time executed, time to
completion, needs for completion, or depth of rollback
DEADLOCKS Deadlock Recovery
completion, needs for completion, or depth of rollback
• In general, it's easier to preempt the resource, than to terminate the
process.
RESOURCE PREEMPTION:
• Select a victim - which process and which resource to preempt.
• Rollback to previously defined "safe" state.
• Prevent one process from always being the one preempted ( starvation ).
COMBINED APPROACH TO DEADLOCK HANDLING:
Type of resource may dictate best deadlock handling. Look at ease of
implementation, and effect on performance.
In other words, there is no one best technique.
DEADLOCKS
Deadlock Recovery
In other words, there is no one best technique.
Cases include:
Preemption for memory,
Pre allocation for swap space,
Avoidance for devices ( can extract Needs from process. )

Contenu connexe

Tendances

Operating system interview question
Operating system interview questionOperating system interview question
Operating system interview questionsriram saravanan
 
My ppt @ bec doms on process management
My ppt @ bec doms on process managementMy ppt @ bec doms on process management
My ppt @ bec doms on process managementBabasab Patil
 
Introduction to Operating System (Important Notes)
Introduction to Operating System (Important Notes)Introduction to Operating System (Important Notes)
Introduction to Operating System (Important Notes)Gaurav Kakade
 
M.c.a. (sem ii) operating systems
M.c.a. (sem   ii) operating systemsM.c.a. (sem   ii) operating systems
M.c.a. (sem ii) operating systemsTushar Rajput
 
Os solved question paper
Os solved question paperOs solved question paper
Os solved question paperAnkit Bhatnagar
 
Chapter 2: Operating System Structures
Chapter 2: Operating System StructuresChapter 2: Operating System Structures
Chapter 2: Operating System StructuresShafaan Khaliq Bhatti
 
Os presentation process
Os presentation processOs presentation process
Os presentation processNaseer Ahmad
 
CHAPTER READING TASK OPERATING SYSTEM
CHAPTER READING TASK OPERATING SYSTEMCHAPTER READING TASK OPERATING SYSTEM
CHAPTER READING TASK OPERATING SYSTEMNur Atiqah Mohd Rosli
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- IntroductionDebasis Das
 
Operating system concepts (notes)
Operating system concepts (notes)Operating system concepts (notes)
Operating system concepts (notes)Sohaib Danish
 
Operating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesOperating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesPeter Tröger
 
Unit II - 1 - Operating System Process
Unit II - 1 - Operating System ProcessUnit II - 1 - Operating System Process
Unit II - 1 - Operating System Processcscarcas
 

Tendances (20)

operating system lecture notes
operating system lecture notesoperating system lecture notes
operating system lecture notes
 
Operating system interview question
Operating system interview questionOperating system interview question
Operating system interview question
 
My ppt @ bec doms on process management
My ppt @ bec doms on process managementMy ppt @ bec doms on process management
My ppt @ bec doms on process management
 
Introduction to Operating System (Important Notes)
Introduction to Operating System (Important Notes)Introduction to Operating System (Important Notes)
Introduction to Operating System (Important Notes)
 
M.c.a. (sem ii) operating systems
M.c.a. (sem   ii) operating systemsM.c.a. (sem   ii) operating systems
M.c.a. (sem ii) operating systems
 
Os solved question paper
Os solved question paperOs solved question paper
Os solved question paper
 
Chapter 2: Operating System Structures
Chapter 2: Operating System StructuresChapter 2: Operating System Structures
Chapter 2: Operating System Structures
 
Os presentation process
Os presentation processOs presentation process
Os presentation process
 
CHAPTER READING TASK OPERATING SYSTEM
CHAPTER READING TASK OPERATING SYSTEMCHAPTER READING TASK OPERATING SYSTEM
CHAPTER READING TASK OPERATING SYSTEM
 
Operating System
Operating SystemOperating System
Operating System
 
Operating System
Operating SystemOperating System
Operating System
 
Cs8493 unit 4
Cs8493 unit 4Cs8493 unit 4
Cs8493 unit 4
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- Introduction
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Cs8493 unit 1
Cs8493 unit 1Cs8493 unit 1
Cs8493 unit 1
 
Operating system concepts (notes)
Operating system concepts (notes)Operating system concepts (notes)
Operating system concepts (notes)
 
Operating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - ProcessesOperating Systems 1 (6/12) - Processes
Operating Systems 1 (6/12) - Processes
 
Unit II - 1 - Operating System Process
Unit II - 1 - Operating System ProcessUnit II - 1 - Operating System Process
Unit II - 1 - Operating System Process
 
Cs8493 unit 5
Cs8493 unit 5Cs8493 unit 5
Cs8493 unit 5
 
Basic os-concepts
Basic os-conceptsBasic os-concepts
Basic os-concepts
 

En vedette

Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.Ravi Kumar Patel
 
Operating System (Scheduling, Input and Output Management, Memory Management,...
Operating System (Scheduling, Input and Output Management, Memory Management,...Operating System (Scheduling, Input and Output Management, Memory Management,...
Operating System (Scheduling, Input and Output Management, Memory Management,...Project Student
 
Functions Of Operating System
Functions Of Operating SystemFunctions Of Operating System
Functions Of Operating SystemDr.Suresh Isave
 
Operating System-Memory Management
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory ManagementAkmal Cikmat
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its conceptsKaran Thakkar
 
Operating Systems and Memory Management
Operating Systems and Memory ManagementOperating Systems and Memory Management
Operating Systems and Memory Managementguest1415ae65
 
Operating system and its function
Operating system and its functionOperating system and its function
Operating system and its functionNikhi Jain
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)Vaibhav Bajaj
 

En vedette (12)

Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
User Interface
User InterfaceUser Interface
User Interface
 
Operating System (Scheduling, Input and Output Management, Memory Management,...
Operating System (Scheduling, Input and Output Management, Memory Management,...Operating System (Scheduling, Input and Output Management, Memory Management,...
Operating System (Scheduling, Input and Output Management, Memory Management,...
 
Functions Of Operating System
Functions Of Operating SystemFunctions Of Operating System
Functions Of Operating System
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Operating System-Memory Management
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory Management
 
Memory management
Memory managementMemory management
Memory management
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its concepts
 
Operating Systems and Memory Management
Operating Systems and Memory ManagementOperating Systems and Memory Management
Operating Systems and Memory Management
 
Operating system and its function
Operating system and its functionOperating system and its function
Operating system and its function
 
Presentation on operating system
 Presentation on operating system Presentation on operating system
Presentation on operating system
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
 

Similaire à Unit 4

Ch2 operating-system structures
Ch2   operating-system structuresCh2   operating-system structures
Ch2 operating-system structuresWelly Dian Astika
 
Operating System Structure Part-I.pdf
Operating System Structure Part-I.pdfOperating System Structure Part-I.pdf
Operating System Structure Part-I.pdfHarika Pudugosula
 
1. Unit 1_Introduction to OS.pptx
1. Unit 1_Introduction to OS.pptx1. Unit 1_Introduction to OS.pptx
1. Unit 1_Introduction to OS.pptxAishwarya .
 
cs-intro-os.ppt
cs-intro-os.pptcs-intro-os.ppt
cs-intro-os.pptinfomerlin
 
Services and system calls
Services and system callsServices and system calls
Services and system callssangrampatil81
 
01. Introduction.ppt
01. Introduction.ppt01. Introduction.ppt
01. Introduction.pptwarlord56
 
Nt introduction(os)
Nt introduction(os)Nt introduction(os)
Nt introduction(os)NehaTadam
 
operating systemPPT sfgSun< Shg<SKJ <JSg
operating systemPPT sfgSun< Shg<SKJ <JSgoperating systemPPT sfgSun< Shg<SKJ <JSg
operating systemPPT sfgSun< Shg<SKJ <JSgDashrath5
 
Chapter one_oS.ppt
Chapter one_oS.pptChapter one_oS.ppt
Chapter one_oS.pptmiki304759
 
EMBEDDED OS
EMBEDDED OSEMBEDDED OS
EMBEDDED OSAJAL A J
 
Bca i-fundamental of computer-u-3-functions operating systems
Bca  i-fundamental of  computer-u-3-functions operating systemsBca  i-fundamental of  computer-u-3-functions operating systems
Bca i-fundamental of computer-u-3-functions operating systemsRai University
 
11. operating-systems-part-1
11. operating-systems-part-111. operating-systems-part-1
11. operating-systems-part-1Muhammad Ahad
 
Bsc cs 1 fit u-3 operating systems
Bsc cs 1 fit u-3 operating systemsBsc cs 1 fit u-3 operating systems
Bsc cs 1 fit u-3 operating systemsRai University
 
Bsc cs 1 fit u-3 operating systems
Bsc cs 1 fit u-3 operating systemsBsc cs 1 fit u-3 operating systems
Bsc cs 1 fit u-3 operating systemsRai University
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating SystemKathirvel Ayyaswamy
 
Mca i-fundamental of computer-u-3-functions operating systems
Mca  i-fundamental of  computer-u-3-functions operating systemsMca  i-fundamental of  computer-u-3-functions operating systems
Mca i-fundamental of computer-u-3-functions operating systemsRai University
 

Similaire à Unit 4 (20)

Ch2 operating-system structures
Ch2   operating-system structuresCh2   operating-system structures
Ch2 operating-system structures
 
Operating System Structure Part-I.pdf
Operating System Structure Part-I.pdfOperating System Structure Part-I.pdf
Operating System Structure Part-I.pdf
 
1. Unit 1_Introduction to OS.pptx
1. Unit 1_Introduction to OS.pptx1. Unit 1_Introduction to OS.pptx
1. Unit 1_Introduction to OS.pptx
 
cs-intro-os.ppt
cs-intro-os.pptcs-intro-os.ppt
cs-intro-os.ppt
 
Services and system calls
Services and system callsServices and system calls
Services and system calls
 
Os unit 1(cont)
Os unit 1(cont)Os unit 1(cont)
Os unit 1(cont)
 
01. Introduction.ppt
01. Introduction.ppt01. Introduction.ppt
01. Introduction.ppt
 
Nt introduction(os)
Nt introduction(os)Nt introduction(os)
Nt introduction(os)
 
Os concepts
Os conceptsOs concepts
Os concepts
 
Advanced_OS_Unit 1 & 2.ppt
Advanced_OS_Unit 1 & 2.pptAdvanced_OS_Unit 1 & 2.ppt
Advanced_OS_Unit 1 & 2.ppt
 
operating systemPPT sfgSun< Shg<SKJ <JSg
operating systemPPT sfgSun< Shg<SKJ <JSgoperating systemPPT sfgSun< Shg<SKJ <JSg
operating systemPPT sfgSun< Shg<SKJ <JSg
 
Chapter one_oS.ppt
Chapter one_oS.pptChapter one_oS.ppt
Chapter one_oS.ppt
 
EMBEDDED OS
EMBEDDED OSEMBEDDED OS
EMBEDDED OS
 
Bca i-fundamental of computer-u-3-functions operating systems
Bca  i-fundamental of  computer-u-3-functions operating systemsBca  i-fundamental of  computer-u-3-functions operating systems
Bca i-fundamental of computer-u-3-functions operating systems
 
11. operating-systems-part-1
11. operating-systems-part-111. operating-systems-part-1
11. operating-systems-part-1
 
Bsc cs 1 fit u-3 operating systems
Bsc cs 1 fit u-3 operating systemsBsc cs 1 fit u-3 operating systems
Bsc cs 1 fit u-3 operating systems
 
Bsc cs 1 fit u-3 operating systems
Bsc cs 1 fit u-3 operating systemsBsc cs 1 fit u-3 operating systems
Bsc cs 1 fit u-3 operating systems
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating System
 
Mca i-fundamental of computer-u-3-functions operating systems
Mca  i-fundamental of  computer-u-3-functions operating systemsMca  i-fundamental of  computer-u-3-functions operating systems
Mca i-fundamental of computer-u-3-functions operating systems
 
Operating System
Operating SystemOperating System
Operating System
 

Dernier

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Dernier (20)

Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Unit 4

  • 1. Unit –IV Introduction to Operating System, Process and threads and Deadlocksthreads and Deadlocks
  • 2. Syllabus • Evolution of O.S. • Function of OS. • Types various OS. • OS concepts.• OS concepts. • OS structure • Processes, threads, Inter process communication, IPC problems. • Scheduling Resources, • introduction to deadlock, ostrich algorithm, • Deadlock detection and recovery, • avoidance, prevention, other aspects
  • 3. Concept of operating system • It is an interface between user & hardware of a computer system • It is system software which may be viewed as an organized collection of software consisting of procedures for operating a computer & providing environment for execution of program.computer & providing environment for execution of program. • But what does it do? to provide an orderly and controlled allocation of the processors, memories and I/O devices among the various programs competing for them Real Life Example: • Government
  • 4. FIRST GENERATION (1945-55) – Computer is made up of vacuum tubes. – Programs are written in assembly language. – Punched cards are used to upload programs and store a data.
  • 5. FIRST GENERATION (1945-55) Early batch system – bring cards to 1401 – read cards to tape – put tape on 7094 which does computing – put tape on 1401 which prints output
  • 7. SECOND GENERATION (1955-65) – Transistors are used. – Main frame was developed. – Programs written in assembly language and in Fortran. – Punched cards are used. – Batch processing used.
  • 8. Evolution of O.S. Function • First generation 1945 – 1955 – vacuum tubes, plug boards (no OS) • Second generation 1955 – 1965 – transistors, batch systems • Third generation 1965 – 1980 – ICs and multiprogramming • Fourth generation 1980 – present – personal computers, hand-held devices, sensors
  • 9. Hardware and software combine to solve specific problems – Software: Application logic providing a service or solves some problem: entertainment, information management, scientific problem solving, system control, forwarding packets in a router, etc. – Hardware: provides the basic computing resources (Processor(s), Memory, System Bus and I/O modules). • Software is divided into two categories:• Software is divided into two categories: – System software: simplifies application programming by creating convenient to use programming and run-time environments. • Resource Management: time and space multiplexing of system resources • Extended virtual machine: standardized interfaces and abstractions simplify programming and system use – Application software: used directly by user (person, another program or computer system) to solve some problem
  • 10. Cont .. – Functions of an Operating System • Resource management • User environment – Design Approaches • Layered, Kernel and Virtual – Types of Advanced Operating Systems • Distributed, Multiprocessor, Database and Real-time – Overview of UNIX (why do we care)
  • 11. Functions of an OS – Resource Management • Time management - temporal properties – CPU and disk transfer scheduling • Space management – main and secondary storage allocation • Synchronization and deadlock handling • Accounting and status information
  • 12. Functions of an OS (cont) – User Environment - OS layer transforms bare hardware machine into higher level abstractions • Execution environment - process management, file manipulation, interrupt handling, I/O operations, language. • Error detection and handling • Protection and security• Protection and security • Fault tolerance and failure recovery
  • 13. Design Approaches – Deal with complexities of modern systems – Separation of Policies and Mechanisms • Policies - What should be done • Mechanisms - How it should be done – Three common approaches: • Layered Approach• Layered Approach • Kernel Approach • Virtual Machine Approach
  • 14. Layered Approach Level Name Objects Example 13 Shell User programming env. Bash statements 12 User process User process Quit,kill,suspend,resume 11 Directories Directories Create,destroy,attach,list Simplifies design, implementation and testing Modular by dividing OS into functional layers. 11 Directories Directories Create,destroy,attach,list 10 Devices External: printer,display Create,open,close 9 File system Files Create,open,close 8 Communications Pipes Crreate,open,close 7 Virtual memory Segments,pages Read,write,fetch 6 Local secondary store Blocks,channel Read,write,fetch 5 Primitive process Process,semaphore Suspend,resume,wait 4 Interrupts Interrupt-handlers Invoke,mask,retry 3 Procedures Procedure,stack,display Mark stack,call,return 2 Instruction set Evaluation stack Load,store,add 1 Electronic circuit Registers,gates,buses Clear,transfer,activate
  • 15. Kernel Based Approach Kernel contains a collection of primitives which are used to build the OS OS implements policy Kernel implements mechanisms Hardware kernel Operating system
  • 16. Virtual Machine Approach Virtual software layer over hardware Illusion of multiple instances of hardware Supports multiple instances of OSs Hardware Virtual machine software VM1 VM2 VM3 VM4
  • 17. Types of Advanced OSs Distributed Operating Systems Multiprocessor Operating Systems Database Operating Systems Real-time Operating Systems
  • 18. Distributed Operating Systems – Controls and manages resources for a network of autonomous computers • manage both hardware and software resources • behaves as a single monolithic system. – User not aware of program or resource location – Design issues same as traditional systems– Design issues same as traditional systems – Practical issues: • lack of shared memory • lack of global clock • unpredictable communication delays.
  • 19. Multiprocessor Operating Systems – Consists of a set of processors that • share a set of physical memory blocks • share a common clock • "share" over an interconnection network. – Control and manage resources • hardware and software resources• hardware and software resources • viewed as a uniprocessor system. – Design issues same as traditional system. – Practical issues: • increased complexity of synchronization, scheduling, memory management, protection and security
  • 20. Database Operating Systems – Database systems place increased demands on an operating system to efficiently support: • concept of a transactions • manage large volumes of data • concurrency control • system failure control
  • 21. Real-time Operating Systems – Place application specific special requirements on an operating system. – Policies and mechanisms are geared to ensuring jobs meet their deadlines. – Problem is one of resource scheduling and overall system utilization.
  • 22. OS Concepts – Processes – Files – System Calls – The command interpreter – Signals
  • 23. OS Concepts - Processes – A process is program in execution – It consists of following: Executable program Program’s data Stack and stack pointer Program counter and other CPU registers Details of opened files
  • 24. OS Concepts – Files – Every OS provides system calls for file management which include: File creation File deletion Read & write operations Files are stored in directory with system calls: To put a file in directory To remove a file from a directory
  • 25. OS Concepts - Files
  • 26. OS Concepts – System Calls – Provide an interface to the services made available by an operating system. – User program interact with operating system through system calls. – Normally available as library functions in a high level language – System calls are available for: Process management Memory management File operations Input/output operations
  • 27. OS Concepts – Command Interpreter – Provides command-line interface – Allows user to enter a command on command lone prompt – The command to be executed are implemented in two ways: • Command interpreter itself contains the necessary code to be executed. • Command is implemented through a system file. To execute a• Command is implemented through a system file. To execute a command the necessary system file is loaded into memory and executed.
  • 28. OS Concepts – Signals – Are to notify a process that a particular event has occurred. – Can be synchronous and asynchronous.
  • 29. OS Structure – Monolithic system – Layered system – Virtual machines – Client-server model
  • 30. OS Structure – Monolithic system – Written as collection of procedures – Services provided through system calls.
  • 31. OS Structure – Layered systems • Based on layered approach consists of number of layers, each built on top of lower layer.
  • 32. OS Structure- Virtual Machine – A single real machine gives an illusion of several virtual machines, each having its own: • Virtual processor • Virtual storage and input/output devices
  • 33. OS Structure – Client server model • Kernel part is very small. • Most of the OS functions are implemented using user processes.
  • 34. Processes – A process is program in execution – It consists of following: Executable program Program’s data Stack and stack pointer Program counter and other CPU registers Details of opened files
  • 35. Processes States 1.New 2. Ready 3.Running 4.Blocked 5.Terminated
  • 36. Processes Control Block • A data structure used to keep track of all information concerning a process • Includes: • Process numberProcess number • Priority • Process state • Program counter • Registers
  • 37. Threads • Low cost alternative to processes for certain kind of concurrent applications.
  • 38. Benefits of Threads – Improves responsiveness – Takes less time terminate a thread than a process – Takes less time to switch between two threads within the same process. – Enhance efficiency in communication. – Allows an application to have several different threads of activity within the same address space.
  • 39. Inter Process Communication • Includes thread synchronization and data exchange between threads beyond the process boundaries. • Two methods of IPC: • Through shared memory • Through message passing.
  • 40. IPC Problems The Bounded Buffer (Producer-Consumer) Problem – Assume there are n slots capable of holding one item. Process producer will produce items to fill slots and process consumer will consume the items in these slots. – There is no information on the relative speeds of processes. – Devise a protocol which will allow these processes to run concurrently.– Devise a protocol which will allow these processes to run concurrently. – A common buffer whose elements (slots) will be filled/emptied by the producer/consumer is needed. – The consumer should not try to consume items which have not been produced yet (i.e. the consumer can not consume empty slots). – The producer should not try to put item into filled slots.
  • 41. IPC Problems The Readers and Writers Problem – Imagine a big database, such as an airline reservation system, with many competing processes wishing to read and write. – It is acceptable to have multiple processes reading the database at the same time, if one process is writing to the database, no other processes may have access to the database, not even readers.may have access to the database, not even readers. – The solution is that the readers have priority over writers. – If a writer appears while several readers are in the database, the writer must wait.
  • 42. IPC Problems The Dining Philosophers Problem – There are N philosophers spending their lives thinking and eating in a room. In their round table there is a plate of infinite rice and N chopsticks. – From time to time, a philosopher gets hungry. – He tries to pick up the two chopsticks that are on his right and his left.– He tries to pick up the two chopsticks that are on his right and his left. – A philosopher that picks both chopsticks successfully (one at a time) starts eating. – A philosopher may pick one chopstick at a time. – When a philosopher finishes eating, he puts down both of his chopsticks to their original position and he starts thinking again. – The question is to write a program which does not let any philosopher to die due to hunger (i.e. no deadlocks).
  • 43. Process Scheduling – Fundamental operating system function. – Scheduling is a set of policies and mechanisms supported by operating systems that controls the order in which the work to be done is completed. – Scheduler manages the running processes in the system – There are various criteria/goals by which a scheduling algorithm can be– There are various criteria/goals by which a scheduling algorithm can be evaluated: 1. FAIRNESS: Make sure each process gets its fair share of the CPU 2. EFFICIENCY: Keep the CPU busy 100% of the time 3. RESPONSE TIME: Minimize response time for interactive users 4. TURNAROUND: Minimize the time batch users must wait for output 5. THROUGHPUT: Maximize the number of jobs processed in a given timeframe
  • 44. Process Scheduling Algorithms • Pre-emptive Scheduling – Scheduler suspends a running process – Allows other processes to run without each process having to complete – Must be careful with real-time – Must be careful to avoid race conditions – Multiuser friendly– Multiuser friendly • Non pre-emptive Scheduling – Run each process to completion – Not efficient for I/O bound applications – Easy to understand and implement – No race condition issues – Must prevent starvation – No way to guarantee turnaround
  • 45. Optimization Criteria • Each scheduling algorithm must be evaluated from how it optimizes the following variables: – 1. Max CPU utilization 2. Max throughput 3. Min turnaround time 4. Min waiting time 5. Min response time
  • 46. First-Come, First Served – FCFS) same as FIFO – Simple, fair, but poor performance. – Average queuing time may be long.
  • 47.
  • 48. Round Robin Scheduling – Quantum: A time interval that a process is allowed to run – – A process may not use its entire quantum if it needs to block for I/O • With Round Robin scheduling each process is given a quantum of time • When quantum expires or process blocks the scheduler picks the next process to run • Round robin scheduling requires a queue – queue to get next process to run – After process has run for its quantum, Enquire it.
  • 49.
  • 50. Priority Scheduling • Used when all processes are not equally important • Priority Scheduling – Each process is assigned a priority – The process with the highest priority is chosen to run by the scheduler • Scheduler must ensure fairness – May lower or increase priorities of some processes to ensure that:– May lower or increase priorities of some processes to ensure that: • Processes are not getting too much CPU time • Process are not getting too little CPU time • Often priorities are grouped into classes • Each process within a priority class must also be scheduled – Can use round robin scheduling • Starvation occurs if a low priority process never runs. Solution: build aging into a variable priority
  • 51. Shortest Job First – When multiple batch jobs are sitting in a queue with the same priority, the scheduler runs the shortest job first. – Optimal for minimizing queuing time, but impossible to implement. – Predicting the time the process will use on its next schedule: t( n+1 ) = w * t( n ) + ( 1 - w ) * T( n ) – Here: t(n+1) is time of next burst. t(n) is time of current burst. T(n) is average of all previous bursts . W is a weighting factor emphasizing current or previous bursts.
  • 52.
  • 53. • Traffic only in one direction. DEADLOCKS Bridge Crossing Example • Traffic only in one direction. • Each section of a bridge can be viewed as a resource. • If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback). • Several cars may have to be backed up if a deadlock occurs. • Starvation is possible.
  • 54. DEADLOCKS NECESSARY CONDITIONS ALL of these four must happen simultaneously for a deadlock to occur: Mutual exclusion One or more than one resource must be held by a process in a non-sharable (exclusive) mode. Hold and Wait A process holds a resource while waiting for another resource. No Preemption There is only voluntary release of a resource - nobody else can make a process give up a resource. Circular Wait Process A waits for Process B waits for Process C .... waits for Process A.
  • 55. • If the graph contains no cycles, then no process is deadlocked. • If there is a cycle, then: a) If resource types have multiple instances, then deadlock MAY exist. b) If each resource type has 1 instance, then deadlock has occurred. DEADLOCKS RESOURCE ALLOCATION GRAPH R3 Assigned to P3 Resource allocation graph P2 Requests P3
  • 56. DEADLOCKS RESOURCE ALLOCATION GRAPH Resource allocation graph with a deadlock. Resource allocation graph with a cycle but no deadlock.
  • 57. HOW TO HANDLE DEADLOCKS – GENERAL STRATEGIES There are three methods: Ignore Deadlocks: Ensure deadlock never occurs using either Prevention Prevent any one of the 4 conditions from happening. DEADLOCKS Strategy Most Operating systems do this!! Prevention Prevent any one of the 4 conditions from happening. Avoidance Allow all deadlock conditions, but calculate cycles about to happen and stop dangerous operations.. Allow deadlock to happen. This requires using both: Detection Know a deadlock has occurred. Recovery Regain the resources.
  • 58. Do not allow one of the four conditions to occur. Mutual exclusion: a) Automatically holds for printers and other non-sharables. b) Shared entities (read only files) don't need mutual exclusion (and aren’t susceptible to deadlock.) DEADLOCKS Deadlock Prevention susceptible to deadlock.) c) Prevention not possible, since some devices are intrinsically non-sharable. Hold and wait: a) Collect all resources before execution. b) A particular resource can only be requested when no others are being held. A sequence of resources is always collected beginning with the same one. c) Utilization is low, starvation possible.
  • 59. Do not allow one of the four conditions to occur. No preemption: a) Release any resource already being held if the process can't get an additional resource. b) Allow preemption - if a needed resource is held by another process, which is also waiting on some resource, steal it. Otherwise wait. DEADLOCKS Deadlock Prevention Circular wait: a) Number resources and only request in ascending order. EACH of these prevention techniques may cause a decrease in utilization and/or resources. For this reason, prevention isn't necessarily the best technique. Prevention is generally the easiest to implement.
  • 60. If we have prior knowledge of how resources will be requested, it's possible to determine if we are entering an "unsafe" state. Possible states are: Deadlock No forward progress can be made. Unsafe state A state that may allow deadlock. DEADLOCKS Deadlock Avoidance Unsafe state A state that may allow deadlock. Safe state A state is safe if a sequence of processes exist such that there are enough resources for the first to finish, and as each finishes and releases its resources there are enough for the next to finish. The rule is simple: If a request allocation would cause an unsafe state, do not honor that request. NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks.
  • 61. NOTE: All deadlocks are unsafe, but all unsafes are NOT deadlocks. DEADLOCKS Deadlock Avoidance SAFE DEADLOCK UNSAFE Only with luck will processes avoid deadlock. O.S. can avoid deadlock.
  • 62. A method used to determine if a particular state is safe. It's safe if there exists a sequence of processes such that for all the processes, there’s a way to avoid deadlock: The algorithm uses these variables: Need[I] – the remaining resource needs of each process. DEADLOCKS Safety Algorithm Deadlock Avoidance Need[I] – the remaining resource needs of each process. Work - Temporary variable – how many of the resource are currently available. Finish[I] – flag for each process showing we’ve analyzed that process or not. need <= available + allocated[0] + .. + allocated[I-1] Sign of success Let work and finish be vectors of length m and n respectively.
  • 63. Need an algorithm that determines if deadlock occurred. Also need a means of recovering from that deadlock. DEADLOCKS Deadlock Detection SINGLE INSTANCE OF A RESOURCE TYPE • Wait-for graph == remove the resources from the usual graph and collapse edges. • An edge from p(j) to p(i) implies that p(j) is waiting for p(i) to release.
  • 64. PROCESS TERMINATION: • Could delete all the processes in the deadlock -- this is expensive. • Delete one at a time until deadlock is broken ( time consuming ). • Select who to terminate based on priority, time executed, time to completion, needs for completion, or depth of rollback DEADLOCKS Deadlock Recovery completion, needs for completion, or depth of rollback • In general, it's easier to preempt the resource, than to terminate the process. RESOURCE PREEMPTION: • Select a victim - which process and which resource to preempt. • Rollback to previously defined "safe" state. • Prevent one process from always being the one preempted ( starvation ).
  • 65. COMBINED APPROACH TO DEADLOCK HANDLING: Type of resource may dictate best deadlock handling. Look at ease of implementation, and effect on performance. In other words, there is no one best technique. DEADLOCKS Deadlock Recovery In other words, there is no one best technique. Cases include: Preemption for memory, Pre allocation for swap space, Avoidance for devices ( can extract Needs from process. )