COMP 252 Operating Systems - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

COMP 252 Operating Systems

Description:

Consider the dining-philosophers problem Where ... Hold-and-wait occurs where a car holds onto their place in the roadway while ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 34
Provided by: course2
Category:

less

Transcript and Presenter's Notes

Title: COMP 252 Operating Systems


1
COMP 252Operating Systems
  • Review Question week 9

2
Q. 1
  • (a) List and briefly describe the four necessary
    conditions for deadlocks
  • Mutual exclusion
  • at least one resource must be held in a
    non-sharable mode.
  • Hold and wait
  • a process must be holding at least one resource
    and waiting to acquire additional resources that
    are currently being held by other processes.

3
Q. 1
  • No preemption
  • a resource can be released only voluntarily by
    the process holding it.
  • Circular wait
  • A set P0, P1, , Pn of waiting process must
    exist such that
  • P0 is waiting for a resource held by P1,
  • P1 is waiting for a resource held by P2,
  • Pn-1 is waiting for a resource held by Pn,
  • and Pn is waiting for a resource held by P0.

4
Q. 1
  • (b) Consider the following snapshot of a system

5
Answer the following questions using the bankers
algorithm
  • What is the content of the matrix Need denoting
    the number of resources needed by each process?
  • Max Allocation Need (maxtrix)

6
Answer the following questions using the bankers
algorithm
  • Is the system in a safe state? Why?
  • The allocation should be safe right now, with a
    sequence of process execution.
  • Yes, with ltP0, P3, P4, P1, P2gt

7
Answer the following questions using the bankers
algorithm
  • If a request from process P2 arrives for (0, 1,
    2, 0), can the requested be granted immediately?
    Why?
  • No, this can not be allocated.
  • If this is allocated, the resulting Available()
    is (2, 0, 0, 0), there is no sequence of the
    process execution order that lead to the
    completion of all processes. This is an unsafe
    state.

8
Q. 2
  • A system is composed of four processes
  • P1, P2, P3, P4
  • And three types of resources
  • R1, R2, R3
  • The number of units of the resources are
  • C lt3, 2, 2gt

9
Q. 2
  • System state
  • process P1 holds 1 unit of R1 and requests 1 unit
    of R2.
  • P2 holds 2 units of R2 and requests 1 unit each
    of R1 and R3.
  • P3 holds 1 unit of R1 and requests 1 unit of R2.
  • P4 holds 2 units of R3 and requests 1 unit of R1.

10
Q. 2
  • Show the resource graph to represent the system
    state.
  • Consider a sequence of processes executions
    without deadlock.

11
  • Sequence of processes executions is
  • P4 gets the unit of R1 and finishes,
  • P2 gets 1 unit of R1 and 1 unit of R3 and
    finishes,
  • then P1 and P3 can finish.
  • There is no deadlock in this situation.

12
Q. 3
  • Recall there are four necessary conditions for a
    deadlock to happen, namely
  • mutual exclusion
  • hold-and-wait
  • no preemption
  • circular wait
  • One way to ensure no deadlock is to break one of
    the conditions.

13
Q. 3
  • For example, we can design an OS that requires a
    process
  • either to acquire all its needed resources before
    execution,
  • or wait until all its required resources to
    become available.
  • What are the main disadvantages of this approach?

14
Q. 3
  • The process might have to wait a long time before
    it can acquire all resources.
  • The process does not need to use all the
    resources it holds at the same time, thus
    resulting in a waste and other process(es) cannot
    use them.

15
Q. 3
  • The process might not know prior that all the
    resources it needs before its execution.
  • Starvation.

16
Q. 4
  • Is it possible to have a deadlock involving only
    one single process?
  • Explain your answer.

17
Q. 4
  • No.
  • This follows directly from the hold-and-wait
    condition.

18
Q. 5
  • Consider a system consisting of four resources of
    the same type that are shared by three processes
  • Each process needs at most two resources
  • Show that the system is deadlock-free

19
Q. 5
  • Consider that all three processes simultaneously
    request resources.
  • One of them will be able to get 2 resources,
    finish its computation and return the resources
    to the system.
  • Then, others can proceed and finish their
    computations also.

20
Q. 6
  • A system consists of 3 types of resources
  • (A, B and C)
  • 8 instances of A
  • 10 instances of B
  • 5 instances of C.
  • These resources are used by five processes (P0,
    P1, P2, P3 and P4).

21
Q. 6
  • If the current state of the system is given below

22
Q. 6
  • Show that the system is in a safe state by
    finding a safe sequence whereby all processes
    would eventually be able to finish (ie. no
    deadlock).
  • You should show the allocation strategy and the
    order of process completion.

23
Q. 6
  • The system is in a safe state
  • the safe sequence (P3, P1, P4, P0, P2) or (P3,
    P1, P4, P2, P0) will allow all processes to
    finish execution.
  • Initially, available vector
  • number of each resource available for
    allocation
  • (3, 3, 1)

24
Q. 6
  • This is greater than the need of P3 so we can
    allocate enough resources to P3 to allow it to
    finish.
  • When P3 finishes, it will release all its
    resources. Thus, Available become (5, 3, 1).
  • This is greater than the need of P1 which can
    therefore finish and release its resources.

25
Q. 6
  • Available then becomes (6, 6, 3) which is greater
    then the need of P4.
  • P4 can therefore finish and release its
    resources.
  • Available then becomes (6, 8, 4) which is greater
    than the need of P0 or P2.
  • Either one of them can finish, say P0, making
    Available (8, 8, 5) which will allow P2 to
    finish.

26
Q. 7
  • Consider the dining-philosophers problem Where
  • the chopsticks are placed at the center of the
    table
  • and any two of them could be used by a
    philosopher
  • Assume that requests for chopsticks are made one
    at a time.

27
Q. 7
  • Describe a simple rule for determining whether a
    particular request could be satisfied without
    causing deadlock.

28
Q. 7
  • when a philosopher makes a request for the first
    chopstick, do not satisfy the request only
  • if there is no other philosopher with two
    chopsticks and if there is only one chopstick
    remaining.

29
Q. 8
  • Consider the traffic deadlock

30
Q. 8
  • Show that the four necessary conditions for
    deadlock indeed hold in this example.
  • State a simple rule for avoiding deadlocks in
    this system.

31
Q. 8
  • The mutual exclusion condition holds as only one
    car can occupy a space in the roadway.
  • Hold-and-wait occurs where a car holds onto their
    place in the roadway while they wait to advance
    in the roadway.

32
Q. 8
  • A car cannot be removed (i.e. preempted) from its
    position in the roadway.
  • Lastly, there is indeed a circular wait as each
    car is waiting for a subsequent car to advance.

33
Q. 8
  • A simple rule to avoid this traffic deadlock
  • a car may not advance into an intersection if it
    is clear they will not be able to immediately
    clear the intersection.
Write a Comment
User Comments (0)
About PowerShow.com