Unit 3 - Practice Quiz

CSE316 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Processes that are in progress over the same period of time are known as:

Concurrent processes Easy
A. Concurrent processes
B. Child processes
C. Sequential processes
D. Idle processes

2 A process is considered a 'co-operating process' if it can:

Co-operating processes Easy
A. Run completely independent of all other processes
B. Affect or be affected by other executing processes
C. Only execute on a single-core CPU
D. Never share data with other processes

3 A segment of code in which a process accesses shared variables and resources is called a(n):

Critical Section Problem Easy
A. Critical Section
B. Remainder Section
C. Deadlock Section
D. Entry Section

4 Which of the following is a fundamental requirement for any solution to the Critical Section Problem?

Critical Section Problem Easy
A. Starvation
B. Mutual Exclusion
C. Deadlock
D. Race Condition

5 In the context of operating systems, a semaphore is essentially a(n):

Semaphores Easy
A. File pointer
B. Hardware interrupt
C. Integer variable
D. CPU register

6 The two primary atomic operations performed on a semaphore are wait() and ____.

Semaphores Easy
A. run()
B. check()
C. signal()
D. stop()

7 The Producer-Consumer problem is a classic example of a(n):

Producer consumer problem Easy
A. Synchronization problem
B. Memory fragmentation problem
C. File system management problem
D. CPU scheduling problem

8 In the Producer-Consumer problem, what is the primary role of the 'producer' process?

Producer consumer problem Easy
A. To generate data and place it into a shared buffer
B. To delete the shared buffer when it is empty
C. To remove data from a shared buffer
D. To determine the size of the shared buffer

9 In the classic Reader-Writer problem, which of the following scenarios is allowed?

Reader-writer Problem Easy
A. A writer process accessing data while another writer is waiting
B. One writer process and one reader process accessing the data at the same time
C. Multiple reader processes accessing the shared data at the same time
D. Multiple writer processes accessing the shared data at the same time

10 In the Dining Philosophers problem, what are the shared resources that the philosophers compete for?

Dining Philosopher Problem Easy
A. The table
B. Chopsticks
C. Bowls of rice
D. Chairs

11 What is the primary purpose of a Monitor as a synchronization tool?

Monitors Easy
A. To directly manage CPU registers for faster context switching
B. To provide a high-level, easy-to-use mechanism for ensuring mutual exclusion
C. To allocate physical memory to processes
D. To increase the priority of I/O bound processes

12 At any given moment, how many processes can be actively executing code inside a monitor?

Monitors Easy
A. An unlimited number
B. Exactly two
C. Only one
D. As many as there are CPU cores

13 Which of the following is a common hardware instruction used for implementing synchronization primitives?

hardware primitives for synchronization Easy
A. read()
B. TestAndSet()
C. fork()
D. exec()

14 Peterson's Solution is a classic software-based solution for the critical section problem involving how many processes?

classical two process and n-process solutions Easy
A. N processes
B. Only one process
C. Two processes
D. Three processes

15 A thread is often referred to as a:

Threads: Overview Easy
A. Kernel
B. Shell
C. Lightweight process
D. Heavyweight process

16 What is a major advantage of using threads compared to using multiple processes?

Threads: Overview Easy
A. Threads are more secure and isolated from each other
B. Threads always execute faster than processes
C. A crash in one thread never affects other threads in the process
D. Threads within the same process share memory and resources

17 In the 'one-to-one' multithreading model, each user-level thread is mapped to a unique:

Multithreading Models Easy
A. CPU core
B. Kernel thread
C. Group of kernel threads
D. Process

18 A significant disadvantage of the 'many-to-one' multithreading model is that:

Multithreading Models Easy
A. A blocking system call by one thread will block the entire process
B. It is very expensive to create new user threads
C. It requires special hardware support
D. It cannot be implemented on single-processor systems

19 In a precedence graph, a directed edge from process to signifies that:

Precedence graph Easy
A. A statement in must be executed before a statement in
B. is the parent process of
C. A statement in must be executed before a statement in
D. and can be executed concurrently

20 In a system with a process hierarchy, when a process creates a new process, the original process is called the:

Hierarchy of processes Easy
A. Parent process
B. Zombie process
C. Orphan process
D. Child process

21 A shared variable count is initialized to 0. A counting semaphore S is initialized to 1. Two processes, P1 and P2, concurrently execute the code below. P1 executes its loop 5 times, and P2 executes its loop 3 times. What is the final value of count?

P1 Code:
c
for (i = 0; i < 5; i++) {
wait(S);
count++;
signal(S);
}


P2 Code:
c
for (j = 0; j < 3; j++) {
wait(S);
count++;
signal(S);
}

Semaphores Medium
A. The value can be anything between 3 and 8.
B. The final value is non-deterministic and cannot be predicted.
C. The value is always 8.
D. The value is always 5.

22 Peterson's solution to the critical section problem requires two shared variables: int turn; and boolean flag[2];. Which of these statements accurately describes why both are necessary?

Critical Section Problem Medium
A. turn indicates which process has priority, while flag is used for deadlock prevention.
B. flag indicates a process's intent to enter the critical section, while turn resolves conflicts when both processes want to enter simultaneously.
C. flag ensures bounded waiting, while turn ensures mutual exclusion.
D. turn handles mutual exclusion, while flag handles progress.

23 What is the primary advantage of using a monitor for process synchronization over using semaphores directly?

Monitors Medium
A. Monitors are more efficient and result in less overhead than semaphores.
B. Monitors allow for more concurrency than semaphores by allowing multiple processes in the critical section.
C. Semaphores cannot solve complex synchronization problems like the Reader-Writer problem, whereas monitors can.
D. Monitors encapsulate synchronization logic, making concurrent code simpler and less error-prone by ensuring mutual exclusion is handled automatically.

24 A common deadlock-free solution to the Dining Philosophers problem involves allowing a philosopher to pick up their chopsticks only if both are available. This is an implementation of which deadlock prevention strategy?

Dining Philosopher Problem Medium
A. Breaking the Hold and Wait condition.
B. Breaking the No Preemption condition.
C. Breaking the Mutual Exclusion condition.
D. Breaking the Circular Wait condition.

25 In the first solution to the Reader-Writer problem (where readers have priority), which potential issue can arise?

Reader-writer Problem Medium
A. Starvation of readers.
B. Deadlock between readers and writers.
C. Starvation of writers.
D. A race condition that allows two writers in the critical section simultaneously.

26 Consider a system using the many-to-one multithreading model. Why is this model not well-suited for a multi-core processor architecture?

Multithreading Models Medium
A. It is complex for the kernel to manage.
B. Context switching between user threads is slow.
C. Creating user-level threads is a high-overhead operation.
D. It cannot take advantage of multiple cores since only one kernel thread can run at a time.

27 The TestAndSet() hardware instruction is defined as follows. How does it primarily ensure mutual exclusion?

c
boolean TestAndSet(boolean target) {
boolean rv =
target;
*target = TRUE;
return rv;
}

hardware primitives for synchronization Medium
A. By requiring a while loop to repeatedly check the lock.
B. By setting the lock to TRUE after checking its value.
C. By being an atomic, non-interruptible operation.
D. By returning the initial value of the lock.

28 In a bounded-buffer producer-consumer problem implemented with semaphores, what is the initial value of the semaphore full and what does it represent?

Producer consumer problem Medium
A. full is initialized to 0 and represents the number of items in the buffer.
B. full is initialized to 0 and represents the number of empty slots in the buffer.
C. full is initialized to n (buffer size) and represents the number of empty slots in the buffer.
D. full is initialized to n (buffer size) and represents the number of items in the buffer.

29 Consider the following set of statements with dependencies:
S1: a = 1;
S2: b = a + 2;
S3: c = 3;
S4: d = b + c;
S5: e = d + 1;

Which of the following represents a valid precedence relationship in the precedence graph for these statements?

Precedence graph Medium
A. S5 can execute concurrently with S4.
B. S4 must execute before S2.
C. S1 and S3 can execute concurrently.
D. S3 must execute before S2.

30 Which multithreading model provides the best balance between concurrency and resource efficiency, and is adopted by modern operating systems like Linux, Windows, and Solaris?

Multithreading Models Medium
A. One-to-One Model
B. Single-Threaded Model
C. Many-to-One Model
D. Many-to-Many Model (or Two-Level Model)

31 Two processes, P1 and P2, share a memory segment. P1 writes a value to the segment, and P2 reads it. This interaction is an example of co-operating processes. What is the primary reason these processes need a synchronization mechanism?

Co-operating processes Medium
A. To allow P1 and P2 to have the same process ID.
B. To increase the execution speed of both processes.
C. To prevent the OS from deallocating the shared memory.
D. To ensure P2 does not read the value before P1 has finished writing it.

32 Lamport's Bakery Algorithm for the n-process critical section problem has a key property that distinguishes it from many semaphore-based solutions. What is this property?

classical two process and n-process solutions Medium
A. It guarantees that processes enter the critical section in a last-in, first-out (LIFO) order.
B. It does not require a shared variable to be read and written in a single atomic instruction.
C. It is immune to process failure inside the critical section.
D. It requires special hardware instructions.

33 When a process creates a new thread, which of the following is typically NOT shared between the parent process's thread and the new thread?

Threads: Overview Medium
A. The stack
B. The file descriptors
C. The heap memory
D. The global variables

34 A process executes wait(S) on a counting semaphore S whose current value is -2. What happens to the process?

Semaphores Medium
A. The process continues execution and the value of S becomes -3.
B. The process continues execution, but the value of S remains -2.
C. The process is blocked and placed in the semaphore's wait queue, and the value of S becomes -3.
D. It causes a runtime error, as semaphore values cannot be negative.

35 Inside a monitor, a process calls x.wait(). What is the state of the monitor lock at this point?

Monitors Medium
A. The monitor lock is released, allowing another process to enter the monitor.
B. The monitor lock is passed to the next process in the condition variable's queue.
C. The system deadlocks because a process cannot wait inside a monitor.
D. The process continues to hold the monitor lock while it is waiting.

36 How does the CompareAndSwap(int *value, int expected, int new_value) instruction provide a more powerful synchronization mechanism than TestAndSet()?

hardware primitives for synchronization Medium
A. It allows for general, non-binary updates to a shared variable in one atomic step, preventing the lost update problem.
B. It avoids the busy-waiting problem that TestAndSet causes.
C. It solves the ABA problem by preventing a value from being changed.
D. It is faster because it doesn't need to return a value.

37 What is the primary goal of using scheduler activations as a communication mechanism between the kernel and the user-level thread library?

scheduler activations Medium
A. To maintain the one-to-one mapping between user and kernel threads.
B. To eliminate the need for kernel threads entirely.
C. To allow user threads to directly schedule themselves on the CPU core.
D. To inform the user-level scheduler about kernel events (like blocking I/O) so it can make better scheduling decisions.

38 In a UNIX-like operating system, a process creates a child process using fork(). If the parent process terminates before the child process, and the child continues to run, what does the child process become?

Hierarchy of processes Medium
A. A session leader
B. A zombie process
C. A daemon process
D. An orphan process

39 Which of the following statements best distinguishes concurrent execution from parallel execution?

Concurrent processes Medium
A. Concurrency is when multiple tasks are making progress over time by interleaving, while parallelism is when multiple tasks are executing simultaneously.
B. There is no difference; the terms are interchangeable.
C. Parallelism is a software concept, while concurrency is a hardware concept.
D. Concurrency is only possible on multi-core systems, while parallelism is possible on single-core systems.

40 A modern web server often uses a multithreaded architecture where a master thread listens for requests and dispatches each new connection to a worker thread. What is the primary advantage of this model over a single-threaded, iterative server?

examples of threaded programs Medium
A. It guarantees that requests are served in the exact order they are received.
B. It uses less memory because threads are lightweight.
C. It simplifies the code by removing the need for a listening socket.
D. It prevents the server from blocking while waiting for a slow client, allowing it to serve other clients concurrently.

41 Two processes, P1 and P2, share a counting semaphore S initialized to 1 and a variable x initialized to 0. The code for the processes is as follows:

P1: wait(S); x=x+1; wait(S); x=x+5; signal(S);
P2: signal(S); x=x*2; signal(S); x=x-2; wait(S);

If P2 starts first and is preempted immediately after executing x=x*2, then P1 runs to completion, and finally P2 resumes and runs to completion, what is the final value of x?

Semaphores Hard
A. 5
B. 6
C. -1
D. 4

42 In a monitor implementation using Mesa semantics, a thread T1 is waiting on a condition variable cond. Another thread T2 executes cond.signal() and then continues to modify the shared state within the monitor before finally exiting. When thread T1 is eventually rescheduled and acquires the monitor lock, what is the most critical action it must perform immediately upon waking?

Monitors Hard
A. Release the monitor lock to allow other threads to proceed.
B. Assume the condition is now true and proceed.
C. Re-evaluate the condition it was waiting for in a loop.
D. Immediately signal another waiting thread to prevent starvation.

43 A deadlock-free solution to the Dining Philosophers problem with philosophers is implemented where each philosopher must acquire both forks simultaneously via a single atomic operation within a critical section. If the operation fails (because one or both forks are unavailable), the philosopher waits. This prevents deadlock. However, which concurrency problem is still a significant risk in this specific implementation?

Dining Philosopher Problem Hard
A. Livelock
B. Circular wait
C. Starvation
D. Violation of mutual exclusion

44 You are implementing a lock-free stack using an atomic CompareAndSwap(CAS) operation. The pop operation is implemented as follows:
c
loop {
top_ptr = head.load();
if (top_ptr == null) return null;
next_ptr = top_ptr->next.load();
} until (CAS(&head, top_ptr, next_ptr));
return top_ptr->data;

Another thread performs a rapid sequence of operations: push(A), push(B), pop() (returns B), pop() (returns A), then push(B) again, where the newly pushed B happens to be allocated at the same memory address as the original B. What problem can cause the first pop thread to fail catastrophically if it was preempted after reading the original head?

hardware primitives for synchronization Hard
A. The lost update problem
B. A deadlock due to CAS failure
C. The ABA problem
D. Instruction reordering by the CPU

45 In a reader-writer solution that gives strong preference to writers, a writer W1 is waiting for the current reader R1 to finish. While W1 is waiting, a stream of new readers (R2, R3) and writers (W2, W3) arrive. According to a typical writer-preference algorithm, what is the guaranteed order of execution after R1 finishes?

Reader-writer Problem Hard
A. W1, W2, W3 will execute before R2, R3.
B. W1 will execute, followed by all waiting readers (R2, R3), then the remaining writers.
C. All waiting writers (W1, W2, W3) and readers (R2, R3) will compete, and the winner is non-deterministic.
D. W1 will execute, then R2, R3, W2, W3 will compete.

46 A process on a system uses a many-to-many threading model, mapping user-level threads to kernel-level threads, where . If exactly of the user-level threads execute blocking system calls simultaneously, what is the most precise implication for the remaining user-level threads?

Multithreading Models Hard
A. The remaining threads continue to be scheduled by the user-level scheduler, sharing the remaining processor time.
B. The operating system migrates the process to a different CPU core with available kernel threads.
C. The kernel automatically creates new kernel threads to service the remaining user threads.
D. The remaining threads are unable to run on a CPU until at least one of the blocking calls completes.

47 Scheduler activations are a sophisticated mechanism to implement user-level threads. What is the primary function of the kernel's upcall to the user-level thread library when an event like a blocking I/O call occurs?

scheduler activations Hard
A. To transfer the entire process's memory space to a new kernel thread.
B. To notify the user-level scheduler that a kernel thread is now blocked, allowing it to schedule another user thread on the activation.
C. To bypass the kernel for all future system calls made by that user thread.
D. To terminate the user thread that made the blocking call and report an error.

48 Consider four processes and four semaphores, S1, S2, S3, S4, all initialized to 0.
P1: ...; signal(S1); signal(S3);
P2: ...; wait(S1); signal(S2);
P3: ...; wait(S2); wait(S4); ...
P4: ...; wait(S3); signal(S4);

Which precedence relationship is enforced by this synchronization scheme?

Precedence graph Hard
A. P2's signal(S2) must happen before P4's signal(S4).
B. P3 can only run after P2 and P4 have both completed specific signaling actions.
C. P1 must complete before P2, P3, or P4 can begin.
D. P2 and P4 can run concurrently without any ordering constraints between them.

49 In a bounded-buffer problem with a buffer of size , three semaphores mutex=1, empty=N, full=0 are used. A producer has the following flawed code structure:
c
wait(mutex);
wait(empty);
// add item to buffer
signal(full);
signal(mutex);

Under what specific condition will this code lead to a system-wide deadlock?

Producer consumer problem Hard
A. When two producers attempt to add items simultaneously.
B. When a producer tries to add an item to a full buffer.
C. When a consumer tries to take an item from an empty buffer.
D. When multiple consumers and producers are running and context switches happen frequently.

50 Lamport's Bakery Algorithm provides a solution to the n-process critical section problem. A key part of the algorithm involves each process checking two conditions for every other process before entering the critical section: while (choosing[j]) and while ((number[j] != 0) && ((number[j], j) < (number[i], i))). What is the primary purpose of the first check, while (choosing[j])?

classical two process and n-process solutions Hard
A. To ensure strict First-In-First-Out (FIFO) ordering among all processes.
B. To resolve a race condition where is in the process of picking a ticket number which might be smaller than 's.
C. To satisfy the bounded waiting condition by giving priority to processes that have been waiting longer.
D. To prevent two processes, and , from picking the exact same ticket number.

51 A system's counting semaphore S is observed to have a value of -4. What is the most precise interpretation of this state?

Semaphores Hard
A. No processes are blocked, and the next four wait(S) operations will not block.
B. The semaphore is in an illegal state, as its value cannot be negative.
C. The semaphore has had four more signal operations than wait operations.
D. Four processes are currently blocked in a queue waiting on semaphore S.

52 On a single-core (uniprocessor) system running an OS with a non-preemptive scheduler, how does the nature of the critical section problem change for user-level processes?

Critical Section Problem Hard
A. The system is immune to deadlock but highly susceptible to livelock.
B. The critical section problem is entirely eliminated, as no two pieces of code can ever execute concurrently.
C. Software solutions like Peterson's algorithm are still required because logical race conditions can occur.
D. Mutual exclusion between user-level processes is guaranteed by the scheduler, but race conditions involving interrupt service routines are still possible.

53 A parent process on a UNIX-like system creates a child using fork(). The parent then opens a file, receiving file descriptor fd=5. Subsequently, the child, executing its own code, opens a completely different file and also happens to receive file descriptor fd=5. What is the outcome if the parent now writes to its fd=5?

Hierarchy of processes Hard
A. The write is redirected to the file opened by the child process.
B. The write fails with an error because the child's fd=5 is now the active one.
C. The behavior is undefined, as the kernel is in an inconsistent state.
D. The write succeeds and data goes to the file originally opened by the parent.

54 A monitor is implemented under Hoare semantics (signal-and-urgent-wait). What is a potential major inefficiency or problem if a signaling process does not immediately exit the monitor after a cond.signal() call, but instead continues to perform more computations on the shared monitor state?

Monitors Hard
A. It will cause a deadlock because the signaled process immediately gets the lock.
B. It violates the mutual exclusion property of the monitor.
C. It causes two context switches (signaler -> waiter, waiter -> signaler) instead of one.
D. It may alter the state such that the condition for which the waiting process was awakened is no longer true when it eventually runs.

55 The 'Test-and-Test-and-Set' (TTAS) spinlock is an optimization over a simple TestAndSet (TAS) spinlock. What is the primary source of this optimization's performance gain on modern, cache-coherent multi-core systems?

hardware primitives for synchronization Hard
A. It consumes less power by putting the CPU into a low-power state during the spin.
B. It reduces interconnect bus traffic by spinning on a locally cached, read-only copy of the lock until it is released.
C. It guarantees fairness and prevents starvation, which a simple TAS lock does not.
D. It uses fewer CPU instructions to acquire the lock.

56 When designing a high-performance server application, what is a primary motivation for using a thread pool instead of creating a new thread for each incoming request?

examples of threaded programs Hard
A. To bypass the operating system's thread scheduler for better performance.
B. To ensure that all requests are processed in a strict first-in, first-out order.
C. To allow the application to run on systems that do not support kernel-level threads.
D. To amortize the high overhead of thread creation and destruction over many requests.

57 Three processes P1, P2, and P3 are synchronized using three binary semaphores S0, S1, and S2, all initialized to 0. An external event signals S0 exactly once to start the system. The code is:

P1: loop { wait(S0); print("A"); signal(S1); signal(S2); }
P2: loop { wait(S1); print("B"); signal(S0); }
* P3: loop { wait(S2); print("C"); }

What is the long-term behavior of this system?

Semaphores Hard
A. The system prints "C" exactly once, then continues printing a sequence of "A"s and "B"s while P3 remains permanently blocked.
B. The system prints the sequence "ABC" repeatedly.
C. The system prints an arbitrary interleaving of "A", "B", and "C" indefinitely.
D. The system deadlocks immediately after printing "A".

58 Two processes, P1 and P2, use strict alternation with a shared variable turn to access a critical section. P1 can only enter if turn == 1, and after exiting it sets turn = 2. P2 can only enter if turn == 2, and after exiting it sets turn = 1. This solution provides mutual exclusion. However, it violates the Progress requirement. Why?

Co-operating processes Hard
A. The turn variable is not protected by a lock, creating a race condition.
B. If P1 wants to enter the critical section but P2 is in its remainder section (not interested in entering), P1 is still blocked.
C. If P1 is much faster than P2, it can enter the critical section multiple times before P2 gets a turn.
D. A deadlock occurs if both processes try to enter the critical section at the same time.

59 In the monitor-based solution to the Dining Philosophers problem (using state array and condition variables), the putdown(i) function, called when philosopher i finishes eating, is responsible for calling test((i-1)%N) and test((i+1)%N). What is the fundamental reason for this design?

Dining Philosopher Problem Hard
A. To wake up a potentially waiting neighbor whose ability to eat was dependent on philosopher i's forks being available.
B. To ensure philosopher i does not immediately re-acquire the forks and starve its neighbors.
C. To check for a potential deadlock condition that may have arisen while philosopher i was eating.
D. To force a context switch, giving other philosophers a chance to run on the CPU.

60 Peterson's two-process solution is correct. However, a naive attempt using only a shared boolean flag array (flag[i] = true means process i wants to enter) fails. The entry code is flag[i] = true; while (flag[j]);. What is the precise interleaving of operations for Process 0 (P0) and Process 1 (P1) that violates mutual exclusion?

classical two process and n-process solutions Hard
A. P0 executes while(flag[1]), sees it's false, and is preempted. P1 then runs, sets flag[1]=true, and enters its CS. P0 resumes and enters its CS.
B. P0 sets flag[0]=true, enters its CS, and stays there indefinitely, starving P1.
C. P0 sets flag[0]=true, but due to a cache coherence issue, P1 reads the old value of flag[0] as false.
D. P0 sets flag[0]=true and is preempted. P1 sets flag[1]=true. Both processes now spin on their while loops, causing deadlock.