0% found this document useful (0 votes)
11 views

# Operating System (CH 2)

The document discusses processes and process management in operating systems, covering concepts such as process control blocks (PCBs), threads, and process scheduling. It explains the lifecycle of processes, including creation, execution states, and termination, as well as different scheduling algorithms and their criteria. Additionally, it highlights the importance of inter-process communication and the challenges of deadlock management.

Uploaded by

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

# Operating System (CH 2)

The document discusses processes and process management in operating systems, covering concepts such as process control blocks (PCBs), threads, and process scheduling. It explains the lifecycle of processes, including creation, execution states, and termination, as well as different scheduling algorithms and their criteria. Additionally, it highlights the importance of inter-process communication and the challenges of deadlock management.

Uploaded by

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

Operating System

By
Fikadu M.
[email protected]
Chapter Two
Processes and Process
Management
Lecture 2: Processes and Process Management 2/ 11/ 202
Outline
3

🠶 Process Concept
🠶 Process control block (PCB)
🠶 Thread concept
🠶 Process Scheduling
🠶 Inter-process Communication
🠶 Deadlock

Lecture 2: Processes and Process Management 2/ 11/ 202


4 2.1. Process Concept
Processes
🠶 Process: Program in execution
🠶 Address space (memory) the program can
use
🠶 State (registers, including program counter
& stack pointer)
🠶 OS keeps track of all processes in a process
table
🠶 Processes can create other
processes
🠶 Process tree tracks these relationships
🠶 A is the root of the tree
🠶 A created three child processes: B, C and D
🠶 C created two child processes: E and F
🠶 D created one child process: G
Lecture 2: Processes and Process Management 2/ 11/ 202
Process control blocks (PCBs) / Process descriptors
5

🠶 PCBs maintain information that the OS needs to manage the


process
🠶 Typically include information such as:
🠶Process identification number (PID)
🠶Process state
🠶Program counter
🠶Scheduling priority
🠶Credentials
🠶A pointer to the process’s parent process
🠶Pointers to the process’s child process
🠶Pointers to locate the process’s data and instruction in memory
🠶Pointers to allocated resources

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
6 …

🠶 Process Table
🠶The OS maintains pointers to each process’s PCB in a system wide
or per-user process table
🠶Allows for quick access to PCBs
🠶When a process is terminated, the OS removes the process from the
process table and frees all of the process’s resources

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
7 …

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
8 …
🠶 An operating system executes a variety of programs:
• Batch system – jobs
• Time-shared systems – user programs or tasks
🠶 Textbook uses the terms job and process almost interchangeably.

🠶 Process – a program in execution; process execution must progress


in sequential fashion.

🠶 A process includes:
• program counter
• stack
• data section

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
9 …
🠶 Processor – provides a set of instructions along with the capability of
automatically executing a series of those instructions.

🠶 Thread – A minimal software processor in whose context a series of instruction s can be


executed.
🠶 Analogous to the concept of a “procedure” that runs independently from its
main program.
🠶 Useful to structure large applications into parts that could logically be
executed at the same time.

🠶 Process – A software processor in whose context one or more threads may be


executed.
🠶 A program that is currently being executed on one of
the OS’s virtual processors.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
10 …
🠶 Let us see these two concepts: uni-programming and multiprogramming.

🠶 Uni-programming: only one process at a time.


🠶 Typical example: DOS. Problem: users often wish to perform more than one activity at
a time (load a remote file while editing a program, for example), and uniprogramming
does not allow this.

🠶 Multiprogramming: multiple processes at a time.


🠶 Typical of UNIX plus all currently envisioned new operating systems.
Allows system to separate out activities cleanly.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
1 …
1

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
1 …
2

Lecture 2: Processes and Process Management 2/ 11/ 202


2.2. Thread Concept
13

🠶 Why would anyone want to have a kind of process within a


process (thread)?

 The main reason for having threads is that in many applications, multiple
activities are going on at once. Some of these may block from time
to time. By decomposing such an application into multiple sequential
threads that run in quasi-parallel, the programming model becomes
simpler.

 A second argument for having threads is that since they are lighter weight
than processes, they are easier (i.e., faster) to create and destroy than
processes.
 A third reason for having threads is also a performance argument.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
14 …

🠶 A thread is again an execution stream in the context


of a thread state.

🠶 Key difference between processes and


threads is that multiple threads share
parts of their state.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
15 …

🠶 Thread Example

 Suppose that the word processor is written as a two threaded program.


One thread interacts with the user and the other handles reformatting in the
background.

 As soon as the sentence is deleted from page 1, the interactive thread tells the
reformatting thread to reformat the whole book.

 Meanwhile, the interactive thread continues to listen to the keyboard and mouse
and responds to simple commands like scrolling page 1 while the other thread is
computing madly in the background.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
16 …

🠶 While we are at it, why not add a third thread? Many


word processors have a feature of automatically saving the
entire file to disk every few minutes to protect the user against
losing a day's work in the event of a program crash, system
crash, or power failure.

🠶 The third thread can handle the disk backups without interfering
with the other two.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
1 …
7

Lecture 2: Processes and Process Management 2/ 11/ 202


2.3. Process Management
1
8

Lecture 2: Processes and Process Management 2/ 11/ 202


Process Creation
1
9

Lecture 2: Processes and Process Management 2/ 11/ 202


Process Termination
20

Lecture 2: Processes and Process Management 2/ 11/ 202


Process state
21

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


process.

🠶 terminated: The process has finished execution.

Lecture 2: Processes and Process Management 2/ 11/ 202


Diagram of process state
2
2

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
23 …
🠶new _ready
 Admitted to ready queue; can now be considered by CPU scheduler
🠶ready _ running
 CPU scheduler chooses that process to execute next, according to
some scheduling algorithm
🠶running _ready
 Process has used up its current time slice

🠶running _blocked
 Process is waiting for some event to occur (for I/O operation to
complete, etc.)
🠶blocked _ ready
 Whatever event the process was waiting on has occurred

🠶Running _ Terminated
 When the process completed

Lecture 2: Processes and Process Management 2/ 11/ 202


Five state process model
24

Lecture 2: Processes and Process Management 2/ 11/ 202


Scheduling: single blocked queue
25

Lecture 2: Processes and Process Management 2/ 11/ 202


2.4. Process Scheduling
26

 Back in the old days of batch systems with input in the form of card
images on a magnetic tape, the scheduling algorithm was simple: just
runs the next job on the tape.

 With multiprogramming systems, the scheduling algorithm became more


complex because there were generally multiple users waiting for service.

 When a computer is multi-programmed, it frequently has multiple


processes or threads competing for the CPU at the same time.

 This situation occurs whenever two or more of them are simultaneously


in the ready state.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
27

 Scheduling refers to a set of policies and mechanisms to control the order
of work to be performed by a computer system.

 Processor scheduling is the means by which OS allocate processor time


for processes.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
28

 When to schedule?

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
29

 When to schedule?
 First, when a new process is created,

 Second, a scheduling decision must-be made when a process exits. That


process can no longer run (since it no longer exists), so some other process
must be chosen from the set of ready processes.

 Third, when a process blocks on I/O, or for some other reason, another
process has to be selected to run. Sometimes the reason for blocking may play
a role in the choice.

 Fourth, when an I/O interrupt occurs, a scheduling decision may be made. If


the interrupt came from an I/O device that has now completed its work, some
process that was blocked waiting for the I/O may now be ready to run.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
30

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
3
1 …

Lecture 2: Processes and Process Management 2/ 11/ 202


Schedulers
32

 The OS makes three types of scheduling decision with respect


to execution of processes:

1. Long-term scheduler (or Job scheduler)

 It determines when new processes are admitted to the system

 It is performed when anew processes is created is and


admitted

New Ready

Blocked/suspend Ready/suspend

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
33

2. Medium-term scheduling

 The decision of which ready process to execute next

 It determines a program is brought partially or fully into main memory

so that it may be executed


 It is performed when swapping is done

Ready/suspend

Ready Blocked/suspend

Blocked
Lecture 2: Processes and Process Management 2/ 11/ 202
Cont’d
34

3. Short-term scheduling
 The decision of which ready process to execute next

 It determines which ready process will get processor time next

 It is performed when a ready process is allocated the processor(when it is

dispatched)

Ready _Running

Lecture 2: Processes and Process Management 2/ 11/ 202


CPU Scheduling
35

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
36

Lecture 2: Processes and Process Management 2/ 11/ 202


Scheduling Criteria
37

Lecture 2: Processes and Process Management 2/ 11/ 202


Scheduling Criteria
38

Lecture 2: Processes and Process Management 2/ 11/ 202


Scheduling Algorithms
39

Example:
🠶 Consider performance of FCFS algorithm for three compute-bound processes.

What if have 3 processes P1 (takes 24 seconds), P2 (takes 3 seconds) and P3


(takes 3 seconds). If arrive in order P1, P2, P3, what is :

Waiting Time? (0+24 + 27) / 3 = 17

Turnaround Time? (24 + 27 + 30)/3 = 27.

Throughput? 30 / 3 = 10.

Lecture 2: Processes and Process Management 2/ 11/ 202


Scheduling Algorithms
40

 There are two main characteristics of short-term scheduling algorithms:

1. Selection function
 It determines which process, among ready processes, is selected for execution
 It may be based on:
 Priority
 Resource requirement
 Execution behavior: time spent in system so far(waiting and executing),time
spent in execution so far, total service time required by the process

Lecture 2: Processes and Process Management 2/ 11/ 202


Scheduling Algorithms
4
1
2. Decision mode
 It specifies the instants in time at which the selection function is exercised

 There are two types of decision modes:

1. Preemptive
 The strategy of allowing processes that is logically runnable to be temporarily suspended and be
moved to the ready state.

 Events that may result pre-emption are arrived of new processes, occurrence of an interrupt
that moves blocked process to ready state and clock interrupt

2. Non-preemptive
Run to completion method: once a process is in running state ,it continues to execute until it terminates
or
blocks itself to wait for some event
Simple and easy to implement

Efficiency can be attained but response time is very high

Lecture 2: Processes and Process Management 2/ 11/ 202


1. First-Come First-Served
42 (FCFS) Scheduling

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
43

 Case i. if they arrive in order of p1,p2,p3

 Turn around time(Tr) p1=24,p2=27,p3=30

 Waiting time for P1 = 0; P2 = 24; P3 = 27

 Tr/Ts p1=1,p2=9, p3=10

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

 Average turn around time:(24+27+30)/3=27

 Throughput =3/30=1/10

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
44

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
45

Consider the following processes arrive at time 0,1,2,3 respectively
 Process p1 p2 p3 p4
 Arrival time(Ta) 0 1 2 3

 Service Time (Ts) 1 100 1 100

 Turnaround time (Tr)

 Response time

 Tr/Ts

 Average response time =

 Average turnaround time =


Lecture 2: Processes and Process Management 2/ 11/ 202
Cont’d
46

Consider the following processes arrive at time 0,1,2,3 respectively
 Process p1 p2 p3 p4
 Arrival time(Ta) 0 1 2 3

 Service Time (Ts) 1 100 1 100

 Turnaround time (Tr) 1 100 100 199

 Response time 0 0 99 99

 Tr/Ts 1 1 100 1.99

 Average response time = (0+0+99+99)/4=49.5

 Average turnaround time = (1+100+100+199)/4=100

 Throughput =4/202

Lecture 2: Processes and Process Management 2/ 11/ 202


2. Shortest Job First (SJF)
47
Scheduling

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
48

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
49

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
50

Example
🠶Consider the following processes arrive at time 0
Process p1 p2 p3
Cpu burst(in ms) 24 3
3

Case i. SJFS

Process p3 p2 p1
Turn around time 3 6 30
Response time 0 3 6
Average response time =(0+3+6)/3=3
Average turn around time =(3+6+30)/3=13
Throughput =3/30

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
5
1 …
SJF (non-preemptive)

Process Arrival Burst Time


Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
52

P1 P3 P2 P4

0 3 7 8 12
16

Average waiting time = (0 + 6 + 3 + 7)/4 - 4

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
53

Example #: Non-Preemptive SJF (simultaneous
arrival)

Process Arrival Time Burst Time


P1 0.0 6
P2 0.0 4
P3 0.0 1
P4 0.0 5

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
54

🠶 SJF (non-preemptive, simultaneous


arrival)

P3 P2 P4 P1

0 1 5 10 16

🠶 Average waiting time = (0 + 1 + 5 + 10)/4 =


4
🠶 Average turn-around time = (1 + 5 + 10 + 16)/4
=
8
Lecture 2: Processes and Process Management 2/ 11/ 202
Cont’d
55

Example of Preemptive SJF

Process Arrival Burst Time


Time
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
56

🠶 SJF
(preemptive)

P1 P2 P3 P2 P4 P1

0 11 16
2 4 5 7

Average time = (9 + 1 + 0 +2)/4


waiting –3
Lecture 2: Processes and Process Management 2/ 11/ 202
3. Shortest Remaining Time Scheduling
57
(SRTS)
🠶 the process that has the shortest expected remaining process
time.
🠶 its selection function is remaining
execution time and uses preemptive decision mode.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
58

Example #: Preemptive (Shortest-remaining-
time-first)

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
59

🠶 consider the following processes arrive at time 0,2,4,6,8
respectively

process p1 p2 p3 p4 p5
arrival time(Ta) 0 2 4 6 8
service time(Ts) 3 6 4 5 2
turn around time(Tr) 3 13 4 14 2
response time 0 1 0 9 0

average response time = (0+1+0+9+0)/5=2


average turn around time =
(3+13+4+14+2)/5=7.2 Lecture 2: Processes and Process Management 2/ 11/ 202
4. Priority Scheduling
60

🠶 A priority number (integer) is associated with each process

🠶 The CPU is allocated to the process with the highest priority


(smallest integer  highest priority).
🠶 Preemptive
🠶 nonpreemptive

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
61

 consider the following processes arrive at time 0

process p1 p2 p3 p4 p5
priority 2 4 5 3 1
service time(Ts) 3 6 4 5 2
turn around time 18 10 4 15 20
response time 15 4 0 10 18

average response time


=(0+15+4+10+18)/5=9.4 average turn around time
=(18+10+4+15+20)/5=13.4 throughput = 5/20=0.25
Lecture 2: Processes and Process Management 2/ 11/ 202
Cont’d
62

🠶 SJF is a priority scheduling where priority is the predicted next
CPU burst time.

🠶 Problem  Starvation – low priority processes may never


execute.

🠶 Solution  Aging – as time progresses increase the priority of


the process.

Lecture 2: Processes and Process Management 2/ 11/ 202


5. Round Robin (RR) Scheduling
63

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
64

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
65

Lecture 2: Processes and Process Management 2/ 11/ 202


Class exercise
66

🠶 Example of RR with Time Quantum = 20

Process Burst Time


P1 53
P2 17
P3 68
P4 24

Lecture 2: Processes and Process Management 2/ 11/ 202


Class exercise
67

🠶 The grant chart


is?

Lecture 2: Processes and Process Management 2/ 11/ 202


Class exercise
68

🠶 The grant chart


is?

P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 5 77 97 117 121 134 154


37 7 162

Typically, higher average turnaround than SJF, but better


response.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
69

Lecture 2: Processes and Process Management 2/ 11/ 202


Multiple processor scheduling
70

🠶 CPU scheduling more complex when multiple CPUs are available.

🠶 Homogeneous processors within a multiprocessor (CPUs must be the same).

🠶 Load sharing - use a common ready queue.

🠶 Each processor schedules itself, or one processor is used for scheduling

Lecture 2: Processes and Process Management 2/ 11/ 202


Real time scheduling
7
1

Lecture 2: Processes and Process Management 2/ 11/ 202


Algorithm Evaluation
72

🠶 Deterministic modelling - takes a particular predetermined workload and defines


the performance of each algorithm for that workload.

🠶 Queuing models - make a mathematical model based on the distributions of


job start times and burst times.

🠶 Simulation - write a program to schedule imaginary tasks using various


algorithms.

🠶 Implementation - code the algorithms into the OS

Lecture 2: Processes and Process Management 2/ 11/ 202


summar
73
y
🠶 2 queues - ready and I/O request.

🠶 FCFS simple but causes short jobs to wait for long jobs.

🠶 SJF is optimal giving shortest waiting time but need to know length of next burst.

🠶 SJF is a type of priority scheduling - may suffer from starvation - prevent using
aging

🠶 RR is gives good response time, it is preemptive. FCFS is non-preemptive,


priority algorithms can be both. Problem selecting the quantum.

🠶 Algorithms may be evaluated by deterministic methods, mathematical models


and
implementation

Lecture 2: Processes and Process Management 2/ 11/ 202


2.5. Inter-process Communication
74

🠶 Mechanism for processes to communicate and to synchronize


their
actions.
🠶 Processes frequently need to communicate with other processes.

🠶 Very briefly, there are three issues here:


 The first was alluded to above: how one process can pass information to
another.
 The second has to do with making sure two or more processes do
not get in each other's way,
 for example, two processes in an airline reservation system each trying to grab the last seat on
a plane for a different customer.
 The third concerns proper sequencing when dependencies are present:
 if process A produces data and process B prints them, B has to wait until A has produced
some data before starting to print.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
75

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
76

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
7
7 …

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
78

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
79

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
80

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
81

🠶 Below we will discuss the problem in the context of processes,
🠶 but please keep in mind that the same problem and solution also apply to threads.

1. Race condition

🠶 In some operating systems, processes that are working


together may share some common storage that each one can
read and write.
🠶 The shared storage may be in main or it may be a shared file;
🠶 the location of the shared memory does not change the nature of
the communication or the problems that arise.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
82

2. Critical Region
How do we avoid race conditions?

🠶 The key to preventing trouble here and in many other


situations involving shared memory, shared files, and shared
everything else is to find some way to prohibit more than one
process from reading and writing the shared data at the same
time.
🠶 Put in other words, what we need is mutual exclusion, that is,
some way of making sure that if one process is using a shared
variable or file, the other processes will be excluded from
doing the same thing.
Lecture 2: Processes and Process Management 2/ 11/ 202
Cont’d
83

🠶 That part of the program where the shared memory is accessed is
called the critical region or critical section.

🠶 We need four conditions to hold to have a good solution:

1. No two processes may be simultaneously inside their critical regions.

2. No assumptions may be made about speeds or the number of CPUs.

3. No process running outside its critical region may block other processes.

4. No process should have to wait forever to enter its critical region.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
84

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
85

3. Mutual exclusion with busy waiting
🠶 In this section we will examine various proposals for achieving mutual exclusion, so
that while one process is busy updating shared memory in its critical region, no other
process will enter its critical region and cause trouble.

🠶 while while (TRUE)


(TRUE) { while { while (turn !
(turn != 0) critical =1)
_region(); turn = 1; critical_region();
noncritical_region(); turn = 0;
noncritical_
region();
} }
/* loop */;
(a) . (b)

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
86

4. Sleep and Wakeup

🠶 In essence, what these solutions do is this:


🠶 when a process wants to enter its critical region, it checks to see if the entry is allowed.
🠶 If it is not, the process just sits in a tight loop waiting until it is.

🠶 Not only does this approach waste CPU time, but it can also have unexpected
effects.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
87

5. Semaphores: synchronization tool that does not require busy waiting.

🠶 This was the situation in 1965, when E. W. Dijkstra (1965) suggested using an
integer variable to count the number of wakeups saved for future use.

🠶 In his proposal, a new variable type, which he called a semaphore, was introduced.

🠶 A semaphore could have the value 0, indicating that no wakeups were saved, or
some positive value if one or more wakeups were pending.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
88

6. Mutexes

🠶 When the semaphore's ability to count is not needed, a simplified


version of the semaphore, called a mutex, is sometimes used.
🠶 Mutexes are good only for managing mutual exclusion to some
shared resource or piece of code.
🠶 They are easy and efficient to implement, which makes
them especially useful in thread packages that are implemented
entirely in user space.

Lecture 2: Processes and Process Management 2/ 11/ 202


2.6. Deadlock
89

🠶 A set of blocked processes each holding a resource and waiting


to acquire a resource held by another process in the set.

🠶 Example

🠶 System has 2 tape drives.


🠶 P1 and P2 each hold one tape drive and each needs another one.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
90

🠶Deadlock can arise if four conditions hold simultaneously.

 Mutual exclusion: only one process at a time can use a resource.


 Hold and wait: a process holding at least one resource is waiting to acquire
additional resources held by other processes.
 No preemption: a resource can be released only voluntarily by the process
holding it, after that process has completed its task.
 Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that
P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is
held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting
for a resource that is held by P0.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
9
1 …

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
92

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
93

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
94

🠶 Deadlock Prevention
🠶 Mutual Exclusion – not required for sharable
resources; must hold for nonsharable resources.
🠶 Hold and Wait – must guarantee that whenever a process
requests a
resource, it does not hold any other resources.
🠶 Low resourc e utilization; starvation possible.

🠶 No Preemption -
🠶 If a process that is holding some resources requests another resource that cannot
be immediately allocated to it, then all resources currently being held are
released.

🠶 Circular Wait - impose a total ordering of all resource types, and require
that each
🠶 process requests resources in an increasing order of enumeration.

Lecture 2: Processes and Process Management 2/ 11/ 202


Cont’d
95

🠶 Recovery from Deadlock
🠶 Process termination
🠶 Abort all deadlocked processes.
🠶 Abort one process at a time until the deadlock cycle is eliminated.
🠶 In which order should we choose to abort?
🠶 Priority of the process.

🠶 How long process has computed, and how much longer to completion.

🠶 Resources the process has used.

🠶 Resources process needs to complete.

🠶 How many processes will need to be terminated

🠶 Resource Preemption
🠶 Selecting a victim - minimize cost.
🠶 Rollback - return to some safe state, restart process from that state.
🠶 Starvation - same process may always be picked as victim; include number
of rollback in cost factor.

Lecture 2: Processes and Process Management 2/ 11/ 202


End of Chapter Two

Lecture 2: Processes and Process Management 2/ 11/ 202

You might also like