🎓 BookMCQ
← Back to 5. Process Synchronization

📝 Process synchronization in Linux (115 MCQs)

📖 From Operating System • 5. Process Synchronization • 115 questions available

What is Process synchronization in Linux?

Definition:
Linux process synchronization offers futexes, POSIX pthread primitives, and System V IPC mechanisms, with futexes providing fast-path user-space locking backed by kernel wait queues.

Example:
A pthread mutex uses FUTEX_WAITFUTEX\_WAIT syscall only on contention, keeping uncontended lock/unlocklock/unlock entirely in user space with atomic cmpxchgcmpxchg.

Reason:
Futex optimization minimizes syscall overhead for the common uncontended case, making Linux synchronization highly scalable for multi-core systems while maintaining POSIX compatibility.

50
Easy
50
Medium
15
Hard

📝 All Process synchronization in Linux MCQs

Q1. Before version 2.6, the Linux kernel was characterized as:

A.Fully preemptive
B.Non-preemptive in user mode only
C.Non-preemptive kernel ✅
D.Preemptive only on SMP systems
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The Linux kernel before version 2.6 was non-preemptive, meaning processes running in kernel mode could not be preempted even if higher-priority processes became available.

Q2. In the modern Linux kernel (2.6 and later), kernel preemption is:

A.Disabled by default
B.Fully enabled ✅
C.Enabled only on SMP systems
D.Enabled only for real-time processes
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The Linux kernel 2.6 and later is fully preemptive, allowing tasks to be preempted even when running in kernel mode, improving system responsiveness.

Q3. What happens to a higher-priority process in Linux 2.6 when a lower-priority process is executing in kernel mode?

A.It must wait until the process exits kernel mode
B.It can preempt the running process ✅
C.It is moved to a wait queue
D.It causes a kernel panic
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In the fully preemptive Linux kernel (2.6+), a higher-priority process can preempt a lower-priority process even when it is executing in kernel mode, unlike the older non-preemptive kernel.

Q4. The change from non-preemptive to preemptive kernel in Linux primarily improves:

A.Memory management efficiency
B.System responsiveness and real-time performance ✅
C.File system throughput
D.Network packet processing
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Preemptive kernels allow higher-priority processes to interrupt lower-priority kernel operations, improving system responsiveness and real-time performance characteristics.

Q5. Which of the following best describes the preemption capability of the Linux kernel before version 2.6?

A.Tasks could be preempted only when in user mode ✅
B.Tasks in kernel mode could be preempted
C.Preemption was controlled by user applications
D.The kernel was fully preemptive
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Before version 2.6, the Linux kernel was non-preemptive, meaning a process running in kernel mode could not be preempted. Preemption was only possible when tasks were executing in user mode.

Q6. The primary disadvantage of a non-preemptive kernel design is:

A.Increased memory consumption
B.Poor responsiveness to high-priority tasks ✅
C.More complex scheduling algorithms
D.Higher CPU utilization
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: In a non-preemptive kernel, high-priority tasks cannot interrupt lower-priority tasks running in kernel mode, leading to poor responsiveness and potential latency issues for time-sensitive operations.

Q7. How does the Linux kernel determine if a task can be safely preempted?

A.By checking the task priority
B.By examining the preempt_count variable ✅
C.By checking the CPU utilization
D.By examining the process state
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The Linux kernel uses the preempt_count counter in the task's thread-info structure to determine if preemption is safe. If preempt_count is greater than 0, the task holds locks and cannot be safely preempted.

Q8. A system administrator notices poor responsiveness in a Linux 2.4 kernel system. Which upgrade would most directly address this issue?

A.Upgrading to Linux 2.6 for preemptive kernel support ✅
B.Increasing CPU frequency
C.Adding more RAM
D.Upgrading to a faster storage device
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Upgrading to Linux 2.6+ provides a fully preemptive kernel, which directly addresses responsiveness issues by allowing higher-priority processes to preempt lower-priority kernel operations.

Q9. In the context of Linux kernel preemption, what does 'preemption' refer to?

A.Forcibly removing a process from memory
B.Interrupting a running process to schedule another ✅
C.Terminating a process that has exceeded its time quantum
D.Moving a process to a different CPU core
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Preemption refers to the involuntary interruption of a currently running process by the scheduler to allow another process to execute, typically based on priority or time quantum considerations.

Q10. Which scenario demonstrates the benefit of preemptive kernel design in Linux?

A.A CPU-intensive background process running in kernel mode delays a real-time audio application ✅
B.A user process cannot access kernel memory
C.Network packets are processed out of order
D.File system operations are slower than expected
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A preemptive kernel allows a high-priority real-time audio application to preempt a lower-priority background process even when the background process is executing in kernel mode, preventing unacceptable audio delays.

Q11. The transition to a preemptive kernel in Linux 2.6 primarily benefits which type of system?

A.Embedded systems with limited memory
B.High-performance computing clusters
C.Desktop and real-time systems ✅
D.Database servers
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Desktop and real-time systems benefit most from preemptive kernels as they require responsive interaction with users and time-sensitive applications, while server workloads may not show as dramatic improvements.

Q12. What architectural change was required to support full kernel preemption in Linux 2.6?

A.Removal of all spinlocks
B.Implementation of preemption control mechanisms ✅
C.Increased kernel stack size
D.Disabling interrupt handling
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Full kernel preemption required implementing preemption control mechanisms including the preempt_disable() and preempt_enable() functions, and the preempt_count counter to track lock acquisition and ensure safe preemption points.

Q13. When a task running in kernel mode holds a lock in Linux, preemption is:

A.Always allowed
B.Disabled until the lock is released ✅
C.Enabled for higher priority tasks only
D.Controlled by user space
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a task holds a lock, preemption is disabled by incrementing the preempt_count. The kernel cannot be safely preempted while locks are held to prevent corruption and deadlocks.

Q14. Which of the following is NOT a characteristic of a preemptive kernel?

A.Higher system responsiveness
B.Better real-time capabilities
C.Processes can be interrupted in kernel mode
D.Simpler synchronization requirements ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: Preemptive kernels actually have more complex synchronization requirements because synchronization primitives must be designed to handle potential preemption at any point during critical section execution.

Q15. The Linux kernel's preemption model directly impacts which system characteristic?

A.Interrupt latency ✅
B.File system structure
C.Memory paging algorithm
D.Disk scheduling policy
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The preemption model directly impacts interrupt latency and system responsiveness, as preemptible kernels can respond more quickly to interrupts and high-priority tasks.

Q16. What data type does Linux use for atomic integer operations?

A.atomic_int
B.atomic_t ✅
C.atomic_type
D.atomic_integer
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Linux uses the opaque data type atomic_t for atomic integer operations. This type ensures all operations performed on it are executed without interruption.

Q17. Which function is used to set an atomic integer to a specific value in Linux?

A.atomic_set() ✅
B.atomic_init()
C.atomic_assign()
D.atomic_write()
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The atomic_set() function is used to assign a value to an atomic_t variable. For example, atomic_set(&counter, 5) sets the atomic integer counter to 5.

Q18. What is the primary advantage of using atomic integers over locking mechanisms?

A.They can handle multiple variables
B.They are more secure
C.They are more efficient with lower overhead ✅
D.They support all data types
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Atomic integers are more efficient than locking mechanisms because atomic operations are performed by the hardware without interruption, eliminating the overhead of acquiring and releasing locks.

Q19. Which operation adds a value to an atomic integer in Linux?

A.atomic_add() ✅
B.atomic_increment()
C.atomic_sum()
D.atomic_plus()
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The atomic_add() function adds a specified value to an atomic integer. For example, atomic_add(10, &counter) adds 10 to the counter variable.

Q20. What is the limitation of using atomic integers for synchronization?

A.They are slower than locks
B.They can only protect a single variable ✅
C.They require hardware support
D.They cannot be used in kernel space
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Atomic integers are limited to protecting a single integer variable. When multiple variables contribute to a possible race condition, more sophisticated locking mechanisms like mutexes or semaphores must be used.

Q21. In the Linux kernel, an atomic integer operation is guaranteed to be:

A.Atomic only on uniprocessor systems
B.Executed without interruption ✅
C.Faster than standard integer operations
D.Protected by a spinlock
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Atomic integer operations are guaranteed to be executed without interruption. This means the operation completes fully before any other process or interrupt can access the variable.

Q22. Given the following code sequence: atomic_set(&counter, 5); atomic_add(10, &counter); atomic_sub(4, &counter); atomic_inc(&counter); What is the final value of counter?

A.10
B.11
C.12 ✅
D.13
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Starting with counter=5: add 10 gives 15, subtract 4 gives 11, increment by 1 gives 12. The final value is 12.

Q23. Which function reads the current value of an atomic integer in Linux?

A.atomic_get()
B.atomic_value()
C.atomic_read() ✅
D.atomic_retrieve()
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: The atomic_read() function returns the current value of an atomic integer. For example, value = atomic_read(&counter) reads the current value of counter into the variable value.

Q24. Why are atomic integers considered opaque data types in Linux?

A.Their internal structure is hidden from developers ✅
B.They cannot be accessed directly
C.They are encrypted
D.They are only accessible in assembly
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Atomic integers are opaque data types, meaning their internal structure and representation are hidden. Developers must use the provided atomic operations functions rather than accessing the data directly.

Q25. What hardware feature enables atomic integer operations on most architectures?

A.DMA controllers
B.Atomic instructions in the ISA ✅
C.Cache coherency protocols
D.Virtual memory management
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Atomic integer operations rely on special atomic instructions provided by the CPU instruction set architecture, such as compare-and-exchange or test-and-set, which guarantee uninterruptible execution.

Q26. The atomic_inc() function performs which operation?

A.Increments the atomic integer by 1 ✅
B.Increments the atomic integer by 10
C.Doubles the atomic integer
D.Adds a specified increment value
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The atomic_inc() function increments an atomic integer by exactly 1. It is a convenience function equivalent to atomic_add(1, &counter).

Q27. In which scenario would atomic integers be inappropriate for synchronization?

A.Counting the number of active processes
B.Protecting a complex data structure with multiple variables ✅
C.Implementing a reference counter
D.Tracking page cache hits
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Atomic integers are inappropriate for protecting complex data structures with multiple variables because they can only provide atomicity for a single integer. Multiple variables require locks like mutexes or semaphores.

Q28. What is the correct way to decrement an atomic integer by 1 in Linux?

A.atomic_dec()
B.atomic_sub(1, &counter)
C.Both a and b ✅
D.atomic_minus()
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Both atomic_dec() and atomic_sub(1, &counter) correctly decrement an atomic integer by 1. Linux provides both the convenience function atomic_dec() and the more general atomic_sub() function.

Q29. How does Linux ensure atomic integer operations are thread-safe?

A.By disabling interrupts
B.By using hardware atomic instructions
C.By acquiring a kernel lock
D.By using atomic_t with compiler barriers ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: Linux combines hardware atomic instructions with compiler barriers to ensure atomic integer operations are thread-safe. The atomic_t type and its operations include the necessary memory barriers to prevent compiler optimizations from reordering operations.

Q30. Which of the following operations is NOT typically provided for atomic_t in Linux?

A.atomic_add()
B.atomic_sub()
C.atomic_multiply() ✅
D.atomic_read()
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Linux atomic_t operations do not include atomic_multiply(). The atomic operations are limited to addition, subtraction, increment, decrement, set, read, and various bit operations.

Q31. When using atomic integers, the operation is performed:

A.In user space only
B.Without the overhead of locking ✅
C.Using spinlocks internally
D.By the compiler
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Atomic integers perform operations without the overhead of locking mechanisms. They use hardware atomic instructions that guarantee uninterruptible execution without requiring locks.

Q32. What would happen if a standard integer operation is used instead of atomic_t in a critical path?

A.Race conditions could occur ✅
B.The kernel would panic
C.The operation would be slower
D.The compiler would generate a warning
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Using standard integer operations instead of atomic_t can lead to race conditions because the operation may be interrupted, leaving the variable in an inconsistent state. Atomic_t operations ensure atomicity.

Q33. The atomic_t data type in Linux is designed to be:

A.Platform-dependent ✅
B.Platform-independent
C.User-space only
D.Kernel-space only
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The atomic_t data type implementation is platform-dependent, with different CPU architectures providing different atomic instructions. However, the interface remains consistent across platforms.

Q34. What is the purpose of making atomic_t an opaque type?

A.To encourage good programming practices
B.To prevent direct manipulation that could bypass atomicity ✅
C.To improve performance
D.To support multiple data sizes
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Making atomic_t opaque prevents developers from directly accessing or modifying the underlying data, ensuring that all operations go through the atomic functions which maintain atomicity guarantees.

Q35. Which operation would you use to add 5 to an atomic integer named count?

A.atomic_add(5, &count) ✅
B.atomic_inc(&count, 5)
C.atomic_sum(&count, 5)
D.atomic_increment(&count, 5)
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The atomic_add(5, &count) function adds 5 to the atomic integer count. The function takes the value to add as the first parameter and a pointer to the atomic_t variable as the second.

Q36. What is the typical use case for atomic integers in the Linux kernel?

A.Implementing complex data structures
B.Managing reference counters ✅
C.Protecting critical sections
D.Synchronizing multiple variables
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Atomic integers are commonly used for reference counters, usage counters, and simple statistical counters where only a single integer needs to be updated atomically without the overhead of locks.

Q37. If atomic operations were not available, what would be the alternative for simple counter updates?

A.Using spinlocks
B.Using mutex locks
C.Both a and b ✅
D.Using standard operations with memory barriers
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Without atomic operations, simple counter updates would need protection using spinlocks or mutex locks. However, locks introduce significant overhead for what should be a simple operation, making atomic operations more efficient.

Q38. The atomic_sub() function in Linux:

A.Subtracts a value from an atomic integer ✅
B.Sets the atomic integer to zero
C.Performs a bitwise subtraction
D.Compares and subtracts
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The atomic_sub() function subtracts a specified value from an atomic integer. For example, atomic_sub(4, &counter) subtracts 4 from the counter variable.

Q39. Which of the following correctly declares an atomic integer in Linux?

A.atomic_t counter; ✅
B.atomic_t *counter;
C.int atomic counter;
D.atomic counter_t;
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: The correct declaration for an atomic integer in Linux is 'atomic_t counter;'. This declares a variable named counter of type atomic_t that can be used with atomic operations.

Q40. Why might atomic integers be insufficient for protecting a shared data structure?

A.They are too slow for complex operations
B.They cannot maintain consistency across multiple variables ✅
C.They require too much memory
D.They only work on 32-bit systems
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Atomic integers cannot maintain consistency across multiple variables. When multiple variables need to be updated together to maintain data structure integrity, locks like mutexes or spinlocks must be used.

Q41. In a multi-core system, how do atomic integer operations maintain consistency?

A.By locking the memory bus
B.Through cache coherency protocols ✅
C.By disabling all interrupts
D.By using mutexes
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Atomic integer operations on multi-core systems rely on cache coherency protocols and atomic instructions that ensure all CPU caches see the same value when an atomic operation is performed.

Q42. Which function must be called to acquire a mutex lock in the Linux kernel?

A.mutex_acquire()
B.mutex_lock() ✅
C.mutex_take()
D.mutex_obtain()
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The mutex_lock() function is used to acquire a mutex lock before entering a critical section in the Linux kernel. It handles blocking if the mutex is currently held by another task.

Q43. What happens when a task calls mutex_lock() and the mutex is already held by another task in Linux?

A.The task spins waiting for the lock
B.The task enters a sleep state and is awakened later ✅
C.The system panics
D.The task executes the critical section anyway
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a mutex is held by another task, calling mutex_lock() puts the calling task into a sleep state. The task is awakened when the lock's owner invokes mutex_unlock().

Q44. Which function releases a mutex lock in the Linux kernel?

A.mutex_release()
B.mutex_unlock() ✅
C.mutex_free()
D.mutex_destroy()
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The mutex_unlock() function releases a mutex lock after a task exits its critical section. This function may wake up one of the tasks waiting on the mutex.

Q45. What is the primary advantage of mutex locks over spinlocks in Linux?

A.Mutex locks are faster
B.Mutex locks are better for long critical sections ✅
C.Mutex locks cannot deadlock
D.Mutex locks work on single-processor systems only
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Mutex locks are more appropriate for long critical sections because tasks waiting for a mutex enter a sleep state and do not consume CPU cycles, whereas spinlocks waste CPU cycles spinning.

Q46. A mutex lock in Linux is best suited for:

A.Short critical sections
B.Long critical sections ✅
C.Interrupt handlers
D.Hardware-level operations
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Mutex locks are appropriate when a lock must be held for a longer period. Tasks waiting for a mutex sleep rather than spin, making them efficient for longer-duration critical sections.

Q47. When a task holding a mutex invokes mutex_unlock(), what may occur?

A.The task continues execution
B.A waiting task may be awakened ✅
C.The mutex is destroyed
D.The system performs a context switch
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When mutex_unlock() is called, the mutex is released, and one of the tasks waiting on the mutex may be awakened to acquire the lock and enter its critical section.

Q48. Why are mutex locks inappropriate for use in interrupt handlers in Linux?

A.They are too slow
B.They might sleep, which is not allowed in interrupt context ✅
C.They require atomic operations
D.They cannot be used in kernel space
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Mutex locks should not be used in interrupt handlers because they can put the calling task to sleep, and interrupt handlers cannot sleep. Spinlocks are the preferred synchronization mechanism for interrupt context.

Q49. What does the Linux kernel do when a task attempts to acquire a held mutex?

A.The task busy-waits
B.The task is put to sleep and added to the mutex's wait list ✅
C.The operation fails with an error
D.The task preempts the current owner
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a mutex is held, the calling task is placed in a sleep state and added to the mutex's wait queue. The task will be awakened when the mutex becomes available.

Q50. In what context are mutex locks typically used in Linux?

A.Process context only ✅
B.Interrupt context only
C.Both process and interrupt context
D.User space only
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Mutex locks are designed for process context where tasks can sleep. They should not be used in interrupt context, atomic contexts, or contexts where sleeping is not permitted.

Q51. What happens to a task waiting on a mutex when the lock owner is preempted?

A.The waiting task is also preempted
B.The waiting task remains asleep until the owner resumes and releases the lock ✅
C.The lock is automatically transferred
D.The waiting task times out
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If the lock owner is preempted while holding a mutex, waiting tasks remain asleep. They will be awakened only when the owner resumes execution and calls mutex_unlock() to release the mutex.

Q52. Which synchronization primitive in Linux puts a task to sleep when the lock is unavailable?

A.Spinlock
B.Mutex lock ✅
C.Atomic integer
D.Read-copy-update
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Mutex locks put tasks to sleep when they attempt to acquire an already-held lock. This is in contrast to spinlocks, which busy-wait and consume CPU cycles.

Q53. How does a mutex compare to a binary semaphore in Linux?

A.They are identical
B.Mutexes have ownership tracking ✅
C.Semaphores are faster
D.Mutexes can be used in interrupt handlers
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Mutexes have ownership tracking, meaning they know which task holds the lock. This enables features like priority inheritance and ensures that only the owner can unlock the mutex. Binary semaphores do not track ownership.

Q54. What is a critical section in the context of Linux mutex locks?

A.A section of code that must be executed atomically ✅
B.A section of code that cannot be interrupted
C.A section of code with high priority
D.A section of code that runs in kernel mode
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: A critical section is a section of code that accesses shared resources and must be executed atomically to prevent race conditions. Mutex locks protect critical sections by ensuring mutual exclusion.

Q55. When using mutex locks, what is the correct order of function calls?

A.mutex_unlock() followed by mutex_lock()
B.mutex_lock() followed by mutex_unlock() ✅
C.mutex_lock() only
D.mutex_unlock() only
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The correct order is to call mutex_lock() before entering the critical section and mutex_unlock() after exiting. This ensures the critical section is protected and the mutex is properly released.

Q56. In the Linux kernel, mutex locks are preferred over spinlocks when:

A.The lock will be held for a long time ✅
B.The lock will be held briefly
C.Performance is critical
D.Running on a uniprocessor
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Mutex locks are preferred for long-duration locks because waiting tasks sleep rather than spin, conserving CPU resources. Spinlocks are preferred for short-duration locks.

Q57. What is the potential issue with holding a mutex lock for an extended period?

A.Increased memory usage
B.Starvation of waiting tasks ✅
C.Decreased cache efficiency
D.Higher interrupt latency
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Holding a mutex lock for an extended period can cause starvation of waiting tasks that need to access the protected resource. This is why mutex locks, while appropriate for longer durations, should still be held as briefly as possible.

Q58. Which statement about mutex locks and interrupts in Linux is correct?

A.Mutex locks automatically disable interrupts
B.Mutex locks can be used safely in interrupt handlers
C.Mutex locks should be used only in process context ✅
D.Mutex locks are faster in interrupt context
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Mutex locks should be used only in process context where sleeping is allowed. In interrupt context, spinlocks or other non-sleeping synchronization mechanisms must be used.

Q59. What happens if a task tries to unlock a mutex it does not own in Linux?

A.The unlock operation succeeds
B.The operation results in an error or panic ✅
C.The mutex becomes unlocked
D.The mutex ownership is transferred
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If a task attempts to unlock a mutex it does not own, the kernel will generate an error, potentially causing a kernel panic. Mutex locks enforce ownership to prevent unauthorized unlocking.

Q60. Which function is used to conditionally acquire a mutex without blocking in Linux?

A.mutex_trylock() ✅
B.mutex_poll()
C.mutex_check()
D.mutex_test()
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: mutex_trylock() attempts to acquire the mutex and returns immediately regardless of whether the mutex is available. It returns 0 if the mutex was acquired and a negative value if the mutex is held by another task.

Q61. How does Linux handle priority inversion with mutex locks?

A.By ignoring priorities
B.By using priority inheritance ✅
C.By increasing the priority of all tasks
D.By using spinlocks instead
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Linux mutexes implement priority inheritance to handle priority inversion. If a high-priority task is blocked on a mutex held by a low-priority task, the low-priority task inherits the high priority until the mutex is released.

Q62. On an SMP machine, what is the fundamental locking mechanism in Linux?

A.Mutex locks
B.Spinlocks ✅
C.Atomic integers
D.Reader-writer locks
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: On SMP machines, spinlocks are the fundamental locking mechanism in the Linux kernel. The kernel is designed so spinlocks are held only for short durations.

Q63. Why are spinlocks unsuitable for use on single-processor machines in Linux?

A.They are not implemented
B.They cause busy-waiting without benefit ✅
C.They are slower than alternatives
D.They require atomic hardware support
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: On single-processor machines, spinlocks are unsuitable because a task holding a spinlock cannot be preempted, so other tasks spinning for the lock waste CPU cycles without any chance of the lock being released.

Q64. How does Linux handle the equivalent of spinlocks on single-processor systems?

A.By using mutex locks
B.By enabling and disabling kernel preemption ✅
C.By using semaphores
D.By using atomic integers
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: On single-processor systems, spinlocks are replaced by disabling and enabling kernel preemption. Rather than acquiring a spinlock, the kernel disables preemption; and rather than releasing a spinlock, it enables preemption.

Q65. What is the primary characteristic of a spinlock in Linux?

A.The task sleeps while waiting
B.The task busy-waits until the lock is available ✅
C.The lock is always available
D.The lock is only for user space
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A spinlock causes the task to busy-wait (spin) until the lock becomes available. This spinning consumes CPU cycles but can be efficient for very short critical sections.

Q66. In Linux, spinlocks should be held only for:

A.Long periods of time
B.Short durations ✅
C.An unlimited time
D.As long as needed
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Spinlocks in Linux should be held only for short durations because tasks waiting on a spinlock busy-wait, consuming CPU cycles. Holding spinlocks for extended periods wastes CPU resources.

Q67. What replaces a spinlock on a single-processor Linux system?

A.A mutex lock
B.Kernel preemption disabled ✅
C.A semaphore
D.An atomic integer
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: On single-processor systems, spinlocks are replaced by disabling kernel preemption. The kernel disables preemption instead of acquiring a spinlock and enables preemption instead of releasing the spinlock.

Q68. When a spinlock is held on an SMP system, what is the state of the tasks waiting for the lock?

A.They are sleeping
B.They are busy-waiting ✅
C.They are executing other code
D.They are preempted
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Tasks waiting for a spinlock on an SMP system enter a busy-wait (spin) state. They continuously check the lock variable until it becomes available, consuming CPU cycles in the process.

Q69. Which Linux synchronization primitive is most efficient for protecting short critical sections on a multi-core system?

A.Mutex lock
B.Spinlock ✅
C.Semaphore
D.Atomic integer
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Spinlocks are most efficient for short critical sections on multi-core systems because the overhead of acquiring and releasing spinlocks is minimal, and waiting tasks can quickly acquire the lock when released.

Q70. What is the relationship between kernel preemption and spinlocks in Linux?

A.Spinlocks automatically disable preemption ✅
B.Spinlocks require preemption to work
C.Preemption is independent of spinlocks
D.Spinlocks are disabled when preemption is disabled
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Spinlocks in Linux automatically disable kernel preemption when acquired. This ensures the task holding the spinlock cannot be preempted, preventing deadlocks and ensuring the lock is released quickly.

Q71. Which of the following scenarios would best use a spinlock in Linux?

A.Protecting a large data structure being modified
B.Protecting a single variable being updated ✅
C.Implementing a file system operation
D.Managing user-space process scheduling
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Spinlocks are best for protecting short operations like updating a single variable. For operations involving large data structures or longer durations, mutex locks or semaphores would be more appropriate.

Q72. Why must spinlocks be held only for short durations in Linux?

A.To prevent CPU overheating
B.To avoid wasting CPU cycles on busy-waiting ✅
C.To maintain cache coherence
D.To prevent memory leaks
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Spinlocks must be held for short durations to avoid wasting CPU cycles on busy-waiting. When a spinlock is held, other tasks waiting for the lock continuously consume CPU cycles, reducing overall system performance.

Q73. On a single-processor system, what is the effect of disabling kernel preemption instead of acquiring a spinlock?

A.The system becomes unresponsive
B.The current task cannot be preempted ✅
C.All interrupts are disabled
D.The system switches to user mode
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Disabling kernel preemption on a single-processor system prevents the current task from being preempted by the scheduler, achieving the same mutual exclusion effect as a spinlock without busy-waiting.

Q74. What happens when a spinlock is acquired and the CPU is interrupted on an SMP system?

A.The interrupt handler can also acquire the same spinlock
B.The spinlock may deadlock if the interrupt handler also tries to acquire it ✅
C.The spinlock is automatically released
D.The system crashes
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: If an interrupt handler attempts to acquire a spinlock already held by the interrupted task, a deadlock can occur. This is why spinlocks in interrupt context require careful design, often using spin_lock_irqsave() to disable interrupts.

Q75. Which variant of spinlock is most appropriate for use in an interrupt handler in Linux?

A.spin_lock()
B.spin_lock_bh()
C.spin_lock_irq()
D.spin_lock_irqsave() ✅
💡 Difficulty: hard | ✅ Correct: D

📖 Explanation: spin_lock_irqsave() is the most appropriate variant for interrupt handlers because it disables interrupts on the local CPU and saves the interrupt flags. This prevents deadlocks that could occur if the handler were interrupted by another interrupt.

Q76. What is the advantage of spinlocks over mutex locks in the Linux kernel?

A.They never deadlock
B.They don't sleep, making them suitable for interrupt context ✅
C.They are easier to implement
D.They work on all CPU architectures
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Spinlocks are suitable for interrupt context because they don't sleep. Mutex locks cannot be used in interrupt context as they may block, which is not permitted in interrupt handlers.

Q77. On an SMP system, what is the process for acquiring a spinlock?

A.The task checks the lock and puts itself to sleep if unavailable
B.The task checks the lock and busy-waits if unavailable ✅
C.The task checks the lock and continues execution
D.The task checks the lock and disables interrupts
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: On SMP systems, tasks acquiring a spinlock check the lock variable and enter a busy-wait loop if the lock is held by another task. They keep checking the variable until it becomes available.

Q78. What is the primary drawback of using spinlocks in the Linux kernel?

A.They are complex to implement
B.They waste CPU cycles when waiting ✅
C.They require hardware support
D.They cannot protect critical sections
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The primary drawback of spinlocks is that waiting tasks consume CPU cycles while spinning, which wastes CPU resources. This is why spinlocks should only be used for very short critical sections.

Q79. In the Linux kernel, semaphores are most appropriate for:

A.Short critical sections
B.Interrupt handlers
C.Long critical sections ✅
D.Atomic operations only
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Semaphores in Linux are appropriate for critical sections that must be held for longer periods. When a task cannot acquire a semaphore, it can sleep, making semaphores efficient for longer-duration locks.

Q80. Which synchronization primitives in Linux have reader-writer versions?

A.Only spinlocks
B.Only mutexes
C.Spinlocks and semaphores ✅
D.Only semaphores
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Linux provides reader-writer versions of both spinlocks and semaphores. These allow multiple readers to access a resource concurrently while providing exclusive access for writers.

Q81. What distinguishes reader-writer semaphores from regular semaphores in Linux?

A.They can only be used in user space
B.They allow multiple readers but only one writer ✅
C.They are faster than regular semaphores
D.They work only on SMP systems
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Reader-writer semaphores allow multiple readers to hold the lock concurrently while providing exclusive access for writers. This improves concurrency when read operations are more frequent than write operations.

Q82. Why are semaphores preferred over spinlocks for long critical sections?

A.Semaphores are simpler to implement
B.Semaphores allow tasks to sleep while waiting ✅
C.Semaphores never deadlock
D.Semaphores are faster than spinlocks
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Semaphores allow tasks that cannot acquire the lock to sleep, not consuming CPU cycles while waiting. This makes them more efficient for long critical sections compared to spinlocks, which busy-wait.

Q83. Which of the following is NOT a use case for semaphores in the Linux kernel?

A.Protecting a shared data structure
B.Limiting access to a resource
C.Implementing a counting semaphore for multiple resources
D.Protecting a single variable being incremented ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: While semaphores could protect a single variable, atomic integers are more efficient for this use case. Semaphores are overkill for simple variable updates and are better suited for complex resource management.

Q84. What is the primary difference between a mutex lock and a counting semaphore in Linux?

A.Mutexes are for mutual exclusion; semaphores can also count ✅
B.Mutexes are faster than semaphores
C.Semaphores cannot be used in kernel space
D.Mutexes support reader-writer variants
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Mutex locks are designed for mutual exclusion with a binary lock state, while counting semaphores maintain a counter that can be used to manage multiple resources, allowing multiple concurrent users up to the counter value.

Q85. In Linux, a reader-writer lock is most beneficial when:

A.There are many writers and few readers
B.There are many readers and few writers ✅
C.The critical section is very short
D.The system has a single CPU
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Reader-writer locks are most beneficial when there are many readers and few writers. Multiple readers can access the resource concurrently, increasing parallelism and performance for read-heavy workloads.

Q86. What happens when a task attempts to acquire a semaphore with a count of zero in Linux?

A.The task busy-waits
B.The task enters a sleep state ✅
C.The task continues execution
D.The semaphore is destroyed
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a task attempts to acquire a semaphore with a count of zero, the task enters a sleep state until the semaphore is released by another task, increasing its count.

Q87. When should a spinlock be used instead of a semaphore in the Linux kernel?

A.For protecting operations that can sleep
B.For protecting very short operations ✅
C.For protecting operations that may block
D.For protecting user-space memory
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Spinlocks should be used for protecting very short operations that cannot sleep, such as simple data structure updates. Semaphores should be used for longer operations or when sleeping is acceptable.

Q88. What is the primary advantage of reader-writer semaphores in Linux?

A.They are faster than regular semaphores
B.They allow greater concurrency for read operations ✅
C.They never cause deadlocks
D.They work in interrupt context
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Reader-writer semaphores allow greater concurrency because multiple readers can hold the lock simultaneously. This improves performance when read operations are frequent and write operations are rare.

Q89. Which system call disables kernel preemption in Linux?

A.preempt_stop()
B.preempt_disable() ✅
C.preempt_off()
D.preempt_block()
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The preempt_disable() system call disables kernel preemption in Linux. When preemption is disabled, the current task cannot be preempted, even if higher-priority tasks become available.

Q90. Which system call enables kernel preemption in Linux?

A.preempt_start()
B.preempt_enable() ✅
C.preempt_on()
D.preempt_resume()
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The preempt_enable() system call enables kernel preemption in Linux. When preemption is enabled, the scheduler is allowed to preempt the current task if a higher-priority task is available.

Q91. What does the preempt_count variable in Linux track?

A.The number of CPU cores
B.The number of locks held by a task ✅
C.The number of running processes
D.The number of interrupts
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The preempt_count variable tracks the number of locks held by a task. When preempt_count is greater than 0, the kernel cannot be safely preempted because the task holds one or more locks.

Q92. When is it safe to preempt the kernel in Linux?

A.When preempt_count equals 0 ✅
B.When preempt_count is greater than 0
C.When a higher-priority task is available
D.When interrupts are disabled
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: It is safe to preempt the kernel when preempt_count equals 0, indicating the task holds no locks and there are no outstanding calls to preempt_disable(). In this state, the kernel can be safely interrupted.

Q93. What happens when a task acquires a lock in Linux regarding preemption?

A.preempt_count is incremented ✅
B.preempt_count is decremented
C.preemption is automatically enabled
D.preempt_count is set to zero
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: When a task acquires a lock, preempt_count is incremented to indicate that the task holds a lock and should not be preempted. The counter is decremented when the lock is released.

Q94. What is the purpose of the thread-info structure in Linux?

A.To store information about a process's threads
B.To track locks held by a task ✅
C.To maintain CPU scheduling information
D.To store file system data
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The thread-info structure contains the preempt_count counter that tracks the number of locks held by a task. This information is used to determine whether it is safe to preempt the kernel.

Q95. If preempt_count is greater than 0 for a task in the Linux kernel, what does this indicate?

A.The task can be preempted safely
B.The task holds at least one lock ✅
C.The task has the highest priority
D.The task is in user mode
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A preempt_count greater than 0 indicates the task holds at least one lock. The kernel cannot be safely preempted while the task holds locks, as this could lead to corrupted data or deadlocks.

Q96. Which of the following would cause the kernel to NOT be preemptible in Linux?

A.A task in user mode
B.A task holding a lock ✅
C.A task with low priority
D.A task waiting on I/O
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The kernel is not preemptible when a task holds a lock (preempt_count > 0). This ensures that critical sections are not interrupted, preventing race conditions and maintaining data integrity.

Q97. What is the relationship between preempt_disable() calls and preempt_count?

A.preempt_disable() decrements preempt_count
B.preempt_disable() increments preempt_count ✅
C.preempt_disable() sets preempt_count to zero
D.preempt_disable() reads preempt_count
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Each call to preempt_disable() increments preempt_count. Multiple calls allow nested disabling of preemption, with preemption only being re-enabled when the number of enable calls matches the number of disable calls.

Q98. What does a call to preempt_enable() check after decrementing preempt_count?

A.The task's CPU time
B.If preempt_count is zero, it checks for pending reschedules ✅
C.The task's priority
D.The number of running tasks
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: After decrementing preempt_count, preempt_enable() checks if the counter has reached zero. If preempt_count is zero and there are pending reschedule requests, preempt_enable() invokes the scheduler to preempt the current task if appropriate.

Q99. Why does Linux maintain preempt_count per task rather than globally?

A.To reduce memory usage
B.To track individual task's lock holdings ✅
C.To improve cache efficiency
D.To simplify scheduler implementation
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: preempt_count is maintained per task because each task independently holds locks and controls its own preemption state. This allows the kernel to determine on a per-task basis whether preemption is safe.

Q100. If a task has preempt_count = 2, and then releases one lock, what is the new value of preempt_count?

A.0
B.1 ✅
C.2
D.3
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a lock is released, preempt_count is decremented. Starting from 2 and decrementing by 1 gives 1. The kernel can be preempted only when preempt_count reaches 0, so preemption remains disabled.

Q101. What is the implication of nested calls to preempt_disable() in Linux?

A.They are not allowed
B.They require matching calls to preempt_enable() ✅
C.They cause a kernel panic
D.They are ignored
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Nested calls to preempt_disable() are allowed and each call increments preempt_count. Each preempt_disable() must be matched with a corresponding preempt_enable() call to properly re-enable preemption.

Q102. What prevents the kernel from being preempted when a task holds locks in Linux?

A.The scheduler ignores the task
B.preempt_count is non-zero ✅
C.The task runs at maximum priority
D.Interrupts are disabled
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a task holds locks, preempt_count is non-zero, indicating that the kernel cannot be safely preempted. The scheduler respects this by not preempting tasks with preempt_count > 0.

Q103. How does Linux ensure that a task holding a spinlock is not preempted?

A.By disabling interrupts
B.By incrementing preempt_count ✅
C.By setting the task to real-time priority
D.By moving the task to a different CPU
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Spinlocks in Linux increment preempt_count when acquired, ensuring the task cannot be preempted. This prevents the task from being interrupted while it holds the spinlock, maintaining data integrity.

Q104. What is the preempt_count value when a task holds a mutex lock in Linux?

A.0
B.1 (incremented) ✅
C.0 (decremented)
D.2
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When a task holds a mutex lock, preempt_count is incremented (typically to 1 or higher). This indicates the task holds a lock and should not be preempted until the lock is released.

Q105. In the Linux kernel, preemption is disabled when:

A.The task is in user mode
B.The task has preempt_count > 0 ✅
C.The task has low priority
D.The task is not running
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Preemption is disabled when a task has preempt_count > 0, indicating it holds locks. The kernel cannot be safely preempted in this state, as the task needs to complete its critical section without interruption.

Q106. Which of the following correctly describes the preemption state when a task holds a spinlock?

A.Preemption is disabled ✅
B.Preemption is enabled
C.Preemption is unaffected
D.Preemption is handled by user space
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: When a task holds a spinlock, preemption is disabled. This prevents the task from being interrupted while in the critical section protected by the spinlock, avoiding race conditions.

Q107. The thread-info structure in Linux contains the preempt_count counter. What is the significance of this structure being per-task?

A.It allows independent preemption control per task ✅
B.It reduces memory overhead
C.It simplifies the scheduling algorithm
D.It improves interrupt handling
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The per-task preempt_count allows independent preemption control for each task. This means each task can independently disable preemption without affecting other tasks, providing fine-grained control.

Q108. What is the purpose of the preempt_count counter being updated on lock acquisition and release?

A.To maintain a count of active locks
B.To determine if preemption is safe ✅
C.To track lock usage statistics
D.To identify lock owners
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: preempt_count is updated to track the number of locks held by a task. This information determines whether the kernel can be safely preempted: preemption is safe only when preempt_count is zero.

Q109. How does Linux handle preemption when a task has preempt_count > 0 and a higher-priority task becomes available?

A.The task is preempted immediately
B.The task is not preempted until preempt_count becomes 0 ✅
C.The higher-priority task waits for the lock
D.The system changes priority
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: If preempt_count > 0, the task holds locks and cannot be safely preempted. The higher-priority task must wait until preempt_count returns to 0, at which point preemption becomes safe and the scheduler can act.

Q110. What is the purpose of the preempt_disable() system call in Linux?

A.To disable all interrupts
B.To prevent the current task from being preempted ✅
C.To prevent other tasks from executing
D.To disable the scheduler
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: preempt_disable() is used to prevent the current task from being preempted. This is useful when executing code that cannot be interrupted, such as critical sections protected by locks.

Q111. When a task with preempt_count = 0 is running in the kernel, what can occur?

A.The task cannot be preempted
B.The task can be safely preempted ✅
C.The task is in a critical section
D.The task is sleeping
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: When preempt_count = 0, the task holds no locks and the kernel can be safely preempted. This allows higher-priority tasks to preempt the current task even when it's running in kernel mode.

Q112. What is the relationship between lock acquisition and preempt_count in Linux?

A.Lock acquisition decrements preempt_count
B.Lock acquisition increments preempt_count ✅
C.Lock acquisition has no effect on preempt_count
D.Lock acquisition sets preempt_count to zero
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: In Linux, lock acquisition increments preempt_count. This ensures that when a task holds locks, the kernel cannot be preempted, preventing race conditions and maintaining data integrity during critical sections.

Q113. Which scenario would not prevent kernel preemption in Linux?

A.A task holding a spinlock
B.A task holding a mutex lock
C.A task with preempt_count = 0 ✅
D.A task within a preempt_disable() block
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A task with preempt_count = 0 does not prevent kernel preemption. This means the kernel can be safely preempted even if the task is running in kernel mode, as it holds no locks.

Q114. When multiple locks are held by a task in Linux, how does this affect preempt_count?

A.preempt_count equals the number of locks held ✅
B.preempt_count is always set to 1
C.preempt_count is set to 0
D.preempt_count is decremented for each lock
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: preempt_count tracks the exact number of locks held by a task. When a task holds multiple locks, preempt_count equals the total number of locks held, ensuring preemption remains disabled until all locks are released.

Q115. What would happen if the Linux kernel allowed preemption while a task holds a lock?

A.Race conditions and data corruption ✅
B.Better system performance
C.Increased responsiveness
D.No impact on system stability
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Allowing preemption while a task holds a lock could lead to race conditions and data corruption. The lock's critical section would be interrupted, potentially leaving shared data in an inconsistent state and causing crashes or data corruption.

🔗 Related Topics (MCQs)