Operating systems miscellaneous


Operating systems miscellaneous

  1. A certain computation generates two arrays a and b such that a[i] = f(i) for 0 ≤ i < n and b[i] = g(a[i]) for 0 ≤ i < n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array a and Y computed the array b. The processes employ two binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below.
    Process X:
    private i;
    for (i=0; ia[i] = f(i); ExitX(R, S);
    }
    Process Y:
    private i;
    for (i=0; iEntryY(R, S);
    b[i] = g(a[i]);
    }
    Which one of the following represents the correct implementations of ExitX and EntryY?









  1. View Hint View Answer Discuss in Forum

    Option (a) Suppose process X executes Exit X then it will wait for R, and then process Y executes Entry Y then it will wait for S. Since, initially both binary semaphores are 0, no one will increment it and both process will be stuck up in a deadlock.
    ∴ Option (a) is incorrect.
    Option (b) Here if process X executes for n times repeatedly it will set both semaphores to 1 (since only two values are possible) and after that process Y executes. First time it passes the Entry Y and make both semaphores to 0. And on second time it finds both semaphores to 0 and cannot pass the Entry Y barrier. Hence it will get stuck. So, option (b) is wrong. Option (c) Considering any sequence of operation of process X and process Y, first process X will wait for S which is increment by process Y and then process Y waits for R which is incremented by process X. There is no sequence of operation in which the value of R or S overlaps.
    ∴ Both processes execute one after another.
    So, option (c) is correct.
    Option (d) Suppose first process X executes it sets R = 1 and then waits for S. Now after that process Y executes. It first sets S = 1 and decrement R = 0. It comes again and then again sets S = 1 (i.e., it overlaps the value of S) and then again wait for R. Clearly hence one iteration of process X is lost due to overlapping of value of S, and after n – 1 iteration process X will be stuck.
    So option (d) is wrong.

    Correct Option: C

    Option (a) Suppose process X executes Exit X then it will wait for R, and then process Y executes Entry Y then it will wait for S. Since, initially both binary semaphores are 0, no one will increment it and both process will be stuck up in a deadlock.
    ∴ Option (a) is incorrect.
    Option (b) Here if process X executes for n times repeatedly it will set both semaphores to 1 (since only two values are possible) and after that process Y executes. First time it passes the Entry Y and make both semaphores to 0. And on second time it finds both semaphores to 0 and cannot pass the Entry Y barrier. Hence it will get stuck. So, option (b) is wrong. Option (c) Considering any sequence of operation of process X and process Y, first process X will wait for S which is increment by process Y and then process Y waits for R which is incremented by process X. There is no sequence of operation in which the value of R or S overlaps.
    ∴ Both processes execute one after another.
    So, option (c) is correct.
    Option (d) Suppose first process X executes it sets R = 1 and then waits for S. Now after that process Y executes. It first sets S = 1 and decrement R = 0. It comes again and then again sets S = 1 (i.e., it overlaps the value of S) and then again wait for R. Clearly hence one iteration of process X is lost due to overlapping of value of S, and after n – 1 iteration process X will be stuck.
    So option (d) is wrong.


  1. A shared variable x, initialised to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory and then terminates. Each process before reading x invokes the P operation (i.e. wait) on a counting semaphore S and invokes the V operation (i.e. signal) on the semaphore S after storing x to memory. Semaphore S is initialised to two. What is the maximum possible value of x after all processes complete execution?









  1. View Hint View Answer Discuss in Forum

    Each of the processes W and X reads x from memory and .increment x by .1.
    Each of the processes Y and Z reads x from memory, and decrement by 2.
    1. Start with X and perform P(S) then S = 1 read x = 0 x = x + 1 = 1
    2. Then Y will perform P(S) then S = 0 read X = 0 x = x–2 = –2 then store x. V(S),S = 1
    3. Then Z will perform P(S) then S = 0, read x = – 2 x = x – 2 = – 4 then store x, V(S).S = 1.
    4. Then x will store x.V(S), S = 2, X = 1
    5. Then W will perform P(S),S = 1, read x = 1 x = x + 1 = 2, store x, V(S),S = 2, x = 2
    Hence, answer is option (d)

    Correct Option: D

    Each of the processes W and X reads x from memory and .increment x by .1.
    Each of the processes Y and Z reads x from memory, and decrement by 2.
    1. Start with X and perform P(S) then S = 1 read x = 0 x = x + 1 = 1
    2. Then Y will perform P(S) then S = 0 read X = 0 x = x–2 = –2 then store x. V(S),S = 1
    3. Then Z will perform P(S) then S = 0, read x = – 2 x = x – 2 = – 4 then store x, V(S).S = 1.
    4. Then x will store x.V(S), S = 2, X = 1
    5. Then W will perform P(S),S = 1, read x = 1 x = x + 1 = 2, store x, V(S),S = 2, x = 2
    Hence, answer is option (d)



  1. Consider a typical disk that rotates at 150000 Rotations Per Minute (RPM) and has a transfer rate of 50 × 106 bytes/sec. If the average seek time of the disk is twice the average rotation delay and the controller's transfer time is 10 times the disk transfer time, the average time (in milliseconds) to read or write a 512-byte sector of the disk is _____.









  1. View Hint View Answer Discuss in Forum

    60sec → 15000 rotations

    1 sector →
    60
    = 4 ms ← 1 rotation
    15000

    ∴ Average rotational delay =
    1
    × 4 ms = 2 ms
    2

    ⇒ As per question, average seek time = 2 × Avg. rotational delay
    = 2 × 2 = 4ms

    ⇒ As per question, controller's transfer time is = 10 × 0.01 ms = 0.1 ms
    ∴ Avg. Time = 4ms + 0.1 ms + 2ms = 6.1 ms

    Correct Option: D

    60sec → 15000 rotations

    1 sector →
    60
    = 4 ms ← 1 rotation
    15000

    ∴ Average rotational delay =
    1
    × 4 ms = 2 ms
    2

    ⇒ As per question, average seek time = 2 × Avg. rotational delay
    = 2 × 2 = 4ms

    ⇒ As per question, controller's transfer time is = 10 × 0.01 ms = 0.1 ms
    ∴ Avg. Time = 4ms + 0.1 ms + 2ms = 6.1 ms


  1. Suppose the following disk request sequence (track numbers) for a disk with 100 tracks is given: 45, 20, 90, 10, 50, 60, 80, 25, 70. Assume that the initial position of the R/W head is on track 50. The additional distance that will be traversed by the R/W head when the Shortest Seek Time First (SSTF) algorithm is used compared to the SCAN (Elevator) algorithm (assuming that SCAN algorithm moves towards 100 when it starts execution) is ______ tracks.









  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    NA



  1. Consider a disk pack with a seek time of 4 milliseconds and rotational speed of 10000 Rotations Per Minute (RPM). It has 60 sectors per track and each sector can store 512 bytes of data. Consider a file stored in the disk. The file contains 2000 sectors. Assume that every sector access necessitates a seek, and the average rotational latency for accessing each sector is half of the time for one complete rotation. The total time (in milliseconds) needed to read the entire file is _______.









  1. View Hint View Answer Discuss in Forum

    Given that , Seek time = 4ms
    60s → 10000 rotations
    60s → 10000 rotations

    60
    = 6 ms ← 1 rotation time
    10000

    ∴ Rotational Latency =
    1
    × 6 ms = 3 ms
    2

    1 track → 600 sectors
    6ms ← 600 sectors (1 rotation means 600 sectors or 1 track)
    1 sector →
    6ms
    = 0.01 ms
    600

    2000 sector → 2000 (0.01) = 20 ms
    ∴ Total time needed to read the entire tile is = 2000 (4 + 3) + 20
    = 8000 + 6000 + 20 = 14020 ms

    Correct Option: C

    Given that , Seek time = 4ms
    60s → 10000 rotations
    60s → 10000 rotations

    60
    = 6 ms ← 1 rotation time
    10000

    ∴ Rotational Latency =
    1
    × 6 ms = 3 ms
    2

    1 track → 600 sectors
    6ms ← 600 sectors (1 rotation means 600 sectors or 1 track)
    1 sector →
    6ms
    = 0.01 ms
    600

    2000 sector → 2000 (0.01) = 20 ms
    ∴ Total time needed to read the entire tile is = 2000 (4 + 3) + 20
    = 8000 + 6000 + 20 = 14020 ms