📝 Passing of data among processes in The Linux System (8 MCQs)
Interprocess Communication Mechanisms in Linux
Linux provides interprocess communication mechanisms that allow processes to exchange data and coordinate activity despite having separate address spaces. Common methods include pipes, named pipes, message queues, shared memory, sockets, and signals. Each mechanism has different communication patterns, data-copying costs, persistence characteristics, and synchronisation requirements.
Why Separate Process Memory Requires Communication Channels
Process isolation prevents one process from directly reading or modifying another process's private memory. Applications nevertheless need to exchange results, coordinate work, and access shared services. IPC mechanisms provide controlled communication paths that preserve process boundaries while supporting different data sizes and communication patterns.
Choosing Pipes, Message Queues or Shared Memory
Anonymous pipes commonly connect related processes through byte streams, while FIFOs provide named communication paths. Message queues preserve message boundaries, and shared memory maps a common region into multiple processes. Sockets support local or network communication, while semaphores or other locks coordinate safe access to shared data.
Example of Producer and Consumer Processes
A producer writes 1024 bytes into a pipe, and a consumer reads the available data from the other end. The kernel manages the pipe buffer and synchronises blocking reads and writes when necessary. The consumer receives the byte stream without directly accessing the producer's private memory.
Data Transfer Costs and Synchronisation Risks
Pipes and message queues offer convenient kernel-managed communication but may involve data copying and queue limits. Shared memory can provide high throughput for large transfers, but requires explicit synchronisation to avoid race conditions. Sockets support communication across machines but introduce network latency and connection failures.
Misconceptions About Linux IPC
'Shared memory automatically synchronises processes' is false because locks or other coordination are still required. 'A pipe preserves every application message boundary' is incorrect because ordinary pipes are byte streams. 'Signals are suitable for transferring large data blocks' ignores their notification-oriented design.
Exam Focus: Comparing Linux IPC Mechanisms
Compare pipes, FIFOs, message queues, shared memory, sockets, and signals by data model and use case. Trace producer-consumer communication and identify where buffering occurs. Questions may ask which mechanism is efficient for large shared data or why shared memory requires separate synchronisation.
Key Terms of Linux IPC
- IPC - Interprocess communication.
- Pipe - Kernel-managed byte stream between processes.
- FIFO - Named pipe for process communication.
- Message queue - Kernel-managed collection of messages.
- Shared memory - Memory mapped into multiple processes.
📝 All Passing of data among processes in The Linux System MCQs
Q1. What is the primary characteristic of a Unix signal in interprocess communication?
📖 Explanation: The correct answer is B because a signal merely notifies a process that something happened; it does not include additional information. Option A is wrong since signals cannot transport arbitrary data. Option C describes synchronization primitives, not signals. Option D refers to a communication channel like a socket, which is unrelated. Understanding that signals are simple notifications helps students choose the right mechanism when only event awareness is needed.
Q2. In Linux kernel programming, what best describes a wait queue?
📖 Explanation: Option C is correct because a wait queue holds processes that have voluntarily blocked and will be awakened once a particular event finishes. Option A describes the run queue, not a wait queue. Option B sounds like a message queue, which holds data, not sleeping processes. Option D is about semaphores, which control access rather than block for events. Recognizing the purpose of wait queues is essential for kernel‑mode synchronization.
Q3. Why does the Linux kernel avoid using signals to notify kernel‑mode processes about events?
📖 Explanation: The kernel chooses option C because kernel‑mode code uses wait queues and scheduling states to sleep and wake, providing efficient event handling without the overhead of signals. Option A is inaccurate; speed is not the main issue. Option B is false—signals can be sent to any process, but the kernel prefers other mechanisms for internal events. Option D mischaracterizes signals, which also serve user‑space purposes. Knowing the kernel's preferred mechanisms guides developers in writing efficient kernel code.
Q4. A server process needs to be notified when incoming data is ready on a network socket. Which IPC mechanism should it rely on to efficiently wait for this event?
📖 Explanation: Option B is correct because the kernel places the server process on a wait queue associated with the socket, allowing it to sleep until data arrives, which is more efficient than polling or using signals that cannot carry the data. Option A (signals) cannot convey the arrival of data and would require extra handling. Option C (shared memory) is for data exchange, not event notification. Option D (message queue) adds unnecessary overhead for a simple readiness event. Selecting wait queues matches the kernel’s design for asynchronous I/O.
Q5. When a parent process wants to detect that one of its child processes has finished execution, which signal is typically delivered by the kernel?
📖 Explanation: The correct answer is C because the kernel sends SIGCHLD to the parent whenever a child terminates, allowing the parent to reap the child’s status. SIGKILL (A) forcibly terminates a process and is not used for notifications. SIGSTOP (B) stops a process, not a termination notice. SIGUSR1 (D) is a user‑defined signal without a specific meaning for child termination. Understanding SIGCHLD helps developers implement proper child‑process handling and resource cleanup.
Q6. Three processes issue read requests for the same file on disk. After the I/O completes, which statement accurately reflects how the kernel wakes the waiting processes?
📖 Explanation: Option B is correct because the kernel’s wait queue mechanism awakens every process that was sleeping on that event once the disk I/O finishes, ensuring all readers can proceed. Option A is wrong; the kernel does not limit wake‑ups to a single process. Option C is inaccurate; wake‑ups are not random. Option D describes inefficient polling, which the wait queue avoids. This behavior demonstrates how wait queues enable coordinated access to shared resources.
Q7. A programmer needs to transfer a small amount of data from one user process to another without creating a temporary file. Which IPC method is most suitable given that signals cannot carry payloads?
📖 Explanation: The best choice is B because a pipe provides a unidirectional byte stream that can carry the required data between processes without needing a file. Option A is impossible since signals lack payload capacity. Option C (semaphore) only synchronizes access and does not transmit data. Option D (shared memory) could work but requires additional coordination and is more complex for small transfers. Knowing that pipes are designed for simple data flow helps developers select the most straightforward solution.
Q8. How do signals and wait queues complement each other in Linux interprocess communication?
📖 Explanation: Option C correctly captures the relationship: signals give a lightweight notification that something happened, whereas wait queues let a process block until a specific condition, such as I/O completion, is met. Option A is false because signals cannot replace the blocking behavior of wait queues. Option B misstates the domain of each mechanism; both exist in kernel space. Option D incorrectly claims they are the same. Understanding this complementarity lets developers combine both tools for efficient event handling.