📝 Synchronization and signals in The Linux System (8 MCQs)
Coordinating Processes with Signals and Synchronisation
Linux provides signals and synchronisation mechanisms for different forms of process coordination. Signals notify a process that an event has occurred, while mutexes, semaphores, condition variables, and futex-based facilities coordinate access to shared state. These mechanisms support asynchronous event handling, thread cooperation, process control, and protection against race conditions.
Why Event Notification and Shared Data Need Different Mechanisms
Processes and threads must respond to events and coordinate operations without corrupting shared resources. Signals provide lightweight notifications but are not general-purpose mutual exclusion tools. Synchronisation primitives protect critical sections and manage waiting, while correct design must account for concurrency, interruption, and the possibility of deadlock.
Signal Delivery and Synchronisation Operations
A signal is generated for a process or thread and becomes pending until delivered according to its mask and disposition. The process may handle, ignore, or use the default action where permitted. Separately, a thread acquires a mutex or waits on a condition variable to coordinate access to shared data.
Example of SIGCHLD and a Shared Counter
A parent process starts a child and receives SIGCHLD when the child changes state, allowing the parent to collect its status using waitpid(). Meanwhile, two worker threads update a shared counter under a mutex. The signal communicates an event; the mutex protects concurrent data modification.
Reliable Notification and Concurrency Safety
Signals support process control, timers, and notification of exceptional events. Synchronisation primitives preserve shared-state consistency among threads and processes. Signals may be coalesced rather than queued individually in traditional cases, and unsafe operations inside handlers can cause corruption. Lock contention and incorrect ordering can also reduce performance or cause deadlock.
Misconceptions About Linux Signals and Synchronisation
'A signal is a mutual exclusion lock' is false because it notifies about events. 'Every generated signal is delivered immediately' ignores masking and pending states. 'A mutex sends a notification to another process' confuses locking with event signalling; condition variables and signals have distinct roles.
Exam Focus: Signal Handling and Mutex Protection
Trace signal generation, pending state, masking, delivery, and handler execution. Distinguish SIGCHLD, SIGTERM, and SIGKILL, noting that SIGKILL cannot be caught or ignored. Explain how mutexes protect critical sections and why signal handlers must restrict themselves to async-signal-safe operations.
Key Terms of Linux Synchronisation and Signals
- Signal - Asynchronous process event notification.
- Signal handler - Function responding to a signal.
- Mutex - Lock providing mutual exclusion.
- Semaphore - Synchronisation counter controlling access.
- Futex - Kernel-assisted user-space locking mechanism.
📝 All Synchronization and signals in The Linux System MCQs
Q1. What is the standard Linux mechanism for informing a process that an event has occurred?
📖 Explanation: The correct answer is Signal because Linux uses signals as the built‑in way to notify a process that something happened. Semaphores, message queues, and pipes are synchronization or communication tools, but they do not serve as the primary notification mechanism. A signal carries only the fact that an event occurred, which matches the definition. Understanding this distinction helps students choose the right primitive when designing interprocess communication, ensuring they do not mistakenly use a pipe for simple notifications.
Q2. Why are Linux signals unable to carry additional information beyond the fact that an event occurred?
📖 Explanation: The correct answer is that signals are delivered asynchronously without a data channel. Linux signals are designed only to indicate that something happened; they do not include a payload area for extra data. Options A and B suggest artificial limits that are not the primary reason, and D is incorrect because even real‑time signals still have very limited data. Recognizing this limitation prevents developers from trying to encode complex information in ordinary signals.
Q3. How does the kernel avoid using signals for communication between kernel‑mode processes?
📖 Explanation: The kernel uses wait queue structures to coordinate kernel‑mode processes, not signals. Wait queues, combined with scheduling states, allow a process to sleep until an event occurs and then be awakened. Shared memory and message queues are user‑space mechanisms and do not directly handle kernel‑mode event notification. This answer highlights the kernel’s internal design, helping students understand why signals are unsuitable for kernel‑mode synchronization and why wait queues are preferred.
Q4. A parent process needs to be notified automatically when one of its child processes terminates. Which signal should it rely on?
📖 Explanation: The correct answer is SIGCHLD because the kernel sends this signal to a parent when a child exits or stops. SIGTERM and SIGKILL are used to request termination of a process, while SIGHUP traditionally indicates a terminal hangup. Knowing that SIGCHLD is the dedicated notification signal enables developers to write correct handlers for child‑process cleanup, avoiding missed terminations or unnecessary polling.
Q5. When a process wants to wait for a disk read to complete, which structure should it use to block efficiently?
📖 Explanation: The appropriate structure is a wait queue, which lets a process sleep until the I/O event finishes. Semaphores and mutexes are primarily for mutual exclusion, and condition variables require a separate lock and predicate, making them less direct for kernel‑driven I/O completion. Using a wait queue aligns with how the Linux kernel wakes all waiting processes once the disk data is ready, leading to efficient resource use.
Q6. Several server processes are blocked waiting for incoming network data. Which mechanism ensures all of them are awakened when the data arrives?
📖 Explanation: The correct mechanism is a wait queue because it allows the kernel to place each blocked process on a queue associated with the network event and wake them all when data arrives. A signal handler would require separate signals per process and does not scale well. Polling loops waste CPU cycles, and a shared memory flag lacks the wake‑up semantics needed for asynchronous events. Understanding this design helps students build scalable network servers.
Q7. What is the primary advantage of using a wait queue over a busy‑wait loop when multiple processes need to wait for a single event?
📖 Explanation: A wait queue reduces CPU usage because processes are removed from the run queue and placed in a sleep state until the event occurs. Busy‑wait loops continuously consume CPU cycles while checking a condition, which is inefficient and can starve other tasks. The other options describe unrelated benefits. Recognizing this advantage guides students to design low‑overhead synchronization in kernel and user space.
Q8. A developer tries to send a numeric value from one user process to another using SIGUSR1. What problem will they encounter?
📖 Explanation: The issue is that the receiving process cannot retrieve the numeric value from the signal because standard signals carry no payload beyond the signal number. Signals are not designed for data transfer; they only indicate that an event occurred. Options A and B describe behavior that does not occur for SIGUSR1, and D is inaccurate because signals do not truncate values—they simply lack a data field. This answer reinforces why other IPC mechanisms are needed for transmitting data.