Operating Systems u0026 Concurrency Quiz Quiz

  1. Fork System Call Output

    Consider the following C code fragment: if fork equals zero, a equals a plus five, print a and the address of a. Else, a equals a minus five, print a and the address of a. Let u and v be the values printed by the parent process, and x and y be the values printed by the child process. Which one of the following is true?

    1. u = x + 10 and v = y
    2. u = x + 10 and v != y
    3. u + 10 = x and v = y
    4. u + 10 = x and v != y
    5. u = x - 10 and v != y
  2. Atomic Fetch-and-Set Implementation

    The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to one and fetches the old value of x in y without allowing any intervening access to the memory location x. Consider the given implementation of P and V functions on a binary semaphore. Which statement is true?

    1. The implementation may not work if context switching is disabled in P.
    2. Instead of using fetch-and-set, a pair of normal load/store can be used
    3. The implementation of V is wrong
    4. The code does not implement a binary semaphore
    5. The implementation of P is wrong
  3. Concurrent Processes and Semaphores - Maximum Value

    A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, and Z. W and X increment x by one. Y and Z decrement x by two. Each process uses a counting semaphore S (initialized to two) before and after modifying x. What is the maximum possible value of x after all processes complete execution?

    1. -2
    2. -1
    3. 1
    4. 2
    5. 0
  4. Concurrent Processes and Semaphores - Maximum Value (Repeated Question)

    A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, and Z. W and X increment x by one. Y and Z decrement x by two. Each process uses a counting semaphore S (initialized to two) before and after modifying x. What is the maximum possible value of x after all processes complete execution?

    1. -2
    2. -1
    3. 1
    4. 2
    5. Tree
  5. Concurrent Processes and Semaphores - Correct Implementation

    A computation generates arrays a and b, where a[i] = f(i) and b[i] = g(a[i]). Processes X and Y compute a and b respectively, using semaphores R and S (both initialized to zero). Array a is shared. Which code block shows the correct implementation of ExitX and EntryY?

    1. ExitX(R, S) { P(R); V(S); } EntryY(R, S) { P(S); V(R); }
    2. ExitX(R, S) { V(R); V(S); } EntryY(R, S) { P(R); P(S); }
    3. ExitX(R, S) { P(S); V(R); } EntryY(R, S) { V(S); P(R); }
    4. ExitX(R, S) { V(R); P(S); } EntryY(R, S) { V(S); P(R); }
    5. ExitX(R, S) { V(S); P(R); } EntryY(R, S) { V(R); P(S); }
  6. Deadlock-Free Semaphore Operations

    Three concurrent processes X, Y, and Z execute code segments accessing shared variables. Each process uses P and V operations on semaphores a, b, c, and d (all binary semaphores initialized to one). Which order of P operations is deadlock-free?

    1. X: P(a) P(b) P(c) Y: P(b) P(c) P(d) Z: P(c) P(d) P(a)
    2. X: P(b) P(a) P(c) Y: P(b) P(c) P(d) Z: P(a) P(c) P(d)
    3. X: P(b) P(a) P(c) Y: P(c) P(b) P(d) Z: P(a) P(c) P(d)
    4. X: P(a) P(b) P(c) Y: P(c) P(b) P(d) Z: P(c) P(d) P(a)
    5. X: P(a) P(c) P(b) Y: P(b) P(c) P(d) Z: P(a) P(d) P(c)
  7. Concurrent Processes and Semaphores

    A shared variable x initialized to zero, is operated on by four concurrent processes W, X, Y, Z. W and X increment x by one, while Y and Z decrement x by two. Each process uses a counting semaphore S initialized to two. What's the maximum possible value of x?

    1. -2
    2. -1
    3. 1
    4. 2
    5. 3
  8. Semaphore Implementation (Again)

    A computation generates two arrays a and b, with a[i] = f(i) and b[i] = g(a[i]). Processes X and Y compute these, respectively, using shared array 'a' and binary semaphores R and S (initialized to zero). Which of the following shows the correct ExitX and EntryY procedures?

    1. ExitX(R, S) {P(R); V(S);} EntryY(R, S) {P(S); V(R);}
    2. ExitX(R, S) {V(R); V(S);} EntryY(R, S) {P(R); P(S);}
    3. ExitX(R, S) {P(S); V(R);} EntryY(R, S) {V(S); P(R);}
    4. ExitX(R, S) {V(R); P(S);} EntryY(R, S) {V(S); P(R);}
    5. ExiteX(R, S) {V(R); P(S);} EntryY(R, S) {V(S); P(R);}
  9. Fork System Call Count

    A process executes the following code three times: fork. What is the total number of child processes created?

    1. 3
    2. 4
    3. 7
    4. 8
    5. 9
  10. Fetch and Add Lock Implementation

    Fetch_And_Add(X, i) is an atomic instruction. It reads the value of X, increments it by i, and returns the old value. It's used below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to zero. What statement is true about this implementation?

    1. Fails as L can overflow
    2. Fails as L can take on a non-zero value when the lock is actually available.
    3. Works correctly but may starve some processes
    4. Works correctly without starvation
    5. Is an unnessecary complex lock
  11. Process Management

    Regarding OS process management, which of the following is generally NOT a responsibility of the operating system?

    1. Process creation and deletion
    2. Resource allocation
    3. Inter-process communication
    4. Ensuring data security within a process's memory space
    5. Deciding which process gets access to the CPU at any given time
  12. Threads vs Processes

    What is the key difference between threads and processes?

    1. Threads have their own address space, while processes share a single address space.
    2. Processes have their own address space, while threads share an address space.
    3. Threads are heavier weight than processes.
    4. Processes are generally easier to create than threads.
    5. Threads can exist independently without a parent process.
  13. CPU Scheduling Algorithms

    Which CPU scheduling algorithm can lead to starvation?

    1. First-Come, First-Served (FCFS)
    2. Shortest Job First (SJF)
    3. Round Robin
    4. Priority Scheduling
    5. Last Come, First Served (LCFS)
  14. Deadlock Conditions

    Which of the following is NOT a necessary condition for deadlock to occur?

    1. Mutual Exclusion
    2. Hold and Wait
    3. No Preemption
    4. Circular Wait
    5. Process Aging
  15. Virtual Memory

    What is the primary purpose of virtual memory?

    1. To increase the speed of the CPU
    2. To allow processes to use more memory than is physically available
    3. To protect the operating system from user processes
    4. To simplify memory management for programmers
    5. To reduce power consumption