Homework 4 – Deadlock and File Management

COP 4610/CGS5765, Introduction to Operating Systems, Fall 2003, Florida State University

¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾

Points: 100 points

Due: Week 12, Thursday, November 13, 2003

1.       (10 pnts) Problem 6 in the textbook on page 411.

A safe state is one in which if every process were to exercise its maximum claim, there would be a sequence of transitions leading to the idle state. If we assume that the maximum claim of p0and p1 are both 2 (a natural assumption given the problem statement), then s00, s01, s02, s03, s04, s10, s11, s12, s20, s21, s30, s31, s40, and s41 are safe states.

S22, s23, and s32 are unsafe states.

S33 is a deadlock state.

2.      (20 pnts) Problem 7 in the textbook on page 411.

1.                  P2 can exercise its full claim and releases resources so that the rest may also.

Initial resource assignments and availability:

`Total Assigned = <5, 3, 2, 2>`
`Available = <1, 1, 2, 0>`
` `
`P2 meets need, Available = <2, 2, 2, 0>`
`P0 meets need, Available = <4, 2, 3, 1>`
`P3 meets need, Available = <5, 2, 4, 1>`
`P4 meets need, Available = <5, 3, 4, 2>`
`P1 meets need, Available = <6, 4, 4, 2>`

Since all may complete, the state is safe.

3.      (10 pnts) Problem 8 in the textbook on page 412.

`Figure 10.7 represents two processes. The three process diagram can be constructed from the "plane" shown in the figure, but with infeasible states eliminated. For example, State 000 represents the case where p_i is holding no units and requesting no units of the resource. State 100 represents the case in which p_1 and p_2 are in the same state as 000, but p_0 has requested one unit of resource. State 330 represents the case in which p_0 holds 1 unit and requests 1 unit, p_1 holds 1 unit and requests 1 unit, and p_2 holds no units and requests no units. Notice that 322 is not feasible, since that would mean p_0 holds 1 unit and requests 1 unit, p_1 holds 1 unit and requests no units, and p_2 holds 1 units and requests no units (i.e., three units are allocated). The diagram shown below is an approximation. There are six deadlock states: 330, 331, 303, 313, 033, and 133.  Here is a picture of the diagram:`

4.      (10 pnts) Problem 9 in the textbook on pages 412.

`This deadlock can be prevented by forcing all processes to acquire resources in the same order (p_1 obtains lock_1, and then lock_2; p_2 obtains lock_2, and then lock_1). An easy solution is to change, say, p_2 so that it obtains locks in the same order as p_1, i.e., it obtains lock_1, and then lock_2. `
` `

5.      (20 pnts) Problem 11 in the textbook on page 412.

`Reduce by p4, then by p2, and then by p1 and p3 in either order. The graph is completely reducible, thus the state is not deadlocked. `

6.      (10 pnts) Problem 6 in the textbook on page 559.

Here is a solution:

a.                   First-fit: The 13-block fragment will be used since it is the first one encountered when the list is traversed.

b.                  Best-fit: The 11-block fragment will be used since it is the smallest fragment that contains at least 10 blocks.

c.                   Worst-fit: The 20-block fragment will be used since it is the largest fragment available.

7.      (10 pnts) Problem 10 in the textbook on page 559.

The file blocks are organized as:

` File Descriptor`
`  ...`
`  [to index 0]`
`     |`
`     v`
`     Index Block 0`
`      [to block 0]`
`      ...`
`      [to block 248]`
`      [to index 1]`
`         |`
`         v`
`         Index Block 1`
`          [to block 249]`
`          ...`
`          [to block 597]`
`          [to index 2]`
`             |`
`             v`
`             Index Block 2`
`              [to block 598]`
`              ...`
`              [to block 846]`
`              [to index 3]`
`                 |`
`                 v`
`                 Index Block 3`
`                  [to block 847]`
`                  ...`
`                  [to block 1095]`
`                  [to index 4]`
`                     |`
`                     v`
`                     Index Block 4`
`                      [to block 1096]`
`                      ...`
`                      [to block 1344]`
`                      [to index 5]`
`                         |`
`                         v`
`                         Index Block 5`
`                          [to block 1345]`
`                          ...`
`                          [to block 1593]`
`                          [to index 6]`
`                             |`
`                             v`
`                             Index Block 6`
`                              [to block 1594]`
`                              ...`
`                              [to block 1842]`
`                              [to index 7]`
`                                 |`
`                                 v`
`                                 Index Block 7`
`                                  [to block 1843]`
`                                  ...`
`                                  [to block 2010] ---> Block 2010`
`                                  ...`
`                                  [to block 2091]`
`                                  /to index 8]`

Assume that the file descriptor has already been read from the disk and is resident in memory. Then the file system must read block Index 0, Index 1 and finally access block 308; this is 2 reads of index blocks and 1 read of block 308.

8.      (10 pnts) Problem 11 in the textbook on page 559.

Note that the following solution assumes that the block size is 4 KB. You may have different answers of you assumed a different block size. However, in terms of blocks, the answer is unique.

With 2048 (2K) addresses per block, we have:

·        Direct: 12 blocks x 4 KB/block = 48 KB = 12 blocks

·        1-Level Indirect: 48 KB + 2K x 4KB = 48 KB + 8 MB  = (12 + 2 K) blocks

·        2-Level Indirect: 48 KB + 8 MB + 2K(2K x 4KB) = 48 KB + 8 MB + 16 GB = (12 + 2K + 4 M) blocks

·        2-Level Indirect: 48 KB + 8 MB + 16 GB + 2K(2K(2K x 4KB)) = 48 KB + 8 MB + 16 GB + 32 TB = (12 + 2 K + 4 M + 8 G) blocks