📝 IPC systems examples shared memory message passing (35 MCQs)
Two Fundamental Models of Interprocess Communication
Shared memory and message passing are fundamental IPC models used by processes to exchange data while maintaining separate execution contexts. Shared memory allows multiple processes to access a common mapped region, whereas message passing transfers information through send and receive operations. The operating system provides the required mapping, communication facilities, and protection controls, while applications choose appropriate synchronisation and data-exchange procedures.
Performance and Isolation Requirements Behind Both Models
Cooperating processes need efficient data exchange without unrestricted access to one another's private memory. Shared memory minimises repeated transfer operations for large data volumes but requires explicit coordination. Message passing provides controlled communication through defined interfaces, although copying, kernel involvement, and scheduling may introduce additional overhead. These trade-offs influence the choice of mechanism.
Shared Memory Mapping and Message Exchange Procedures
For shared memory, the operating system creates a region and maps it into participating processes' address spaces. Processes read and write the common region while using mutexes or semaphores for synchronisation. In message passing, a sender places data into a communication mechanism and a receiver retrieves it through corresponding operations, which may be blocking or non-blocking.
Transferring a 4-KiB Data Block Using Both Models
Suppose producer P sends a 4-KiB block to consumer C. With shared memory, P writes the block into a mapped region and signals C using a semaphore. With message passing, P sends the block through a communication channel and C receives it. Shared memory avoids repeated message transfer, while message passing provides a more explicit exchange boundary.
Throughput, Data Copying, and Synchronisation Trade-offs
Shared memory often suits high-volume local communication because processes can access common data without repeatedly transferring complete messages through the kernel. However, incorrect locking can cause race conditions or deadlocks. Message passing simplifies ownership and isolation but may require copying and additional transitions. Actual performance depends on implementation, buffer management, message size, and scheduling behaviour.
Misconceptions About Shared Memory and Message Passing
'Shared memory eliminates all kernel involvement' is incorrect because creation, mapping, and protection require operating system support. 'Message passing always copies data between processes' is incorrect because some implementations use shared buffers or zero-copy techniques. 'Both processes can safely modify shared data simultaneously' is incorrect because unsynchronised updates can cause race conditions.
Exam Focus: Comparing Shared Memory with Message Passing
Compare both models by setup, data transfer, protection, synchronisation, and communication overhead. Trace how a producer writes data and how a consumer receives it. Understand blocking and non-blocking message operations, shared-region mapping, semaphore coordination, and race conditions. Questions may ask you to select a suitable IPC model for high-throughput local communication or loosely coupled services.
Key Terms of Shared Memory and Message Passing
- Shared region - Memory accessible to multiple processes.
- Mapping - Connecting memory into an address space.
- Send - Operation transmitting a message.
- Receive - Operation accepting a message.
- Blocking - Waiting until an operation progresses.
- Semaphore - Variable coordinating concurrent access.
📝 All IPC systems examples shared memory message passing MCQs
Q1. Which interprocess communication example allows only related processes, such as a parent and its child, to communicate through a kernel buffer?
📖 Explanation: An anonymous pipe has no name in the file system, so the communicating processes must inherit its file descriptors from a common ancestor, typically through fork. It is a unidirectional kernel buffer, and its simplicity suits producer-consumer chains between related processes such as a parent and child.
Q2. Which mechanism is a kernel-managed list of messages in which each message carries a type field that the receiver can use for selection?
📖 Explanation: A message queue stores messages in the kernel until a receiver takes them. Each message carries a type value, so a receiver can request messages of a particular type rather than strictly the oldest one. This makes queues useful when different kinds of requests must be handled differently.
Q3. Which network-oriented communication endpoint is identified by an IP address together with a port number?
📖 Explanation: A socket is an endpoint for communication, identified by a host address and a port. The IP address locates the machine and the port selects the service or process on that machine. Clients connect to a server's address and port, which is the standard way networked processes find each other.
Q4. Which POSIX-style call maps a shared memory object into the address space of a process so that it can be accessed directly?
📖 Explanation: The mmap call maps a file or shared memory object into a process's virtual address space, after which the process reads and writes the region like ordinary memory. Once mapped, changes are visible to every process that maps the same object, which is the essence of shared memory communication.
Q5. Which type of pipe persists as an entry in the file system, allowing processes that are not related to communicate through it?
📖 Explanation: A named pipe, also called a FIFO, has a name in the file system, so any process that knows the name can open it. Unlike an anonymous pipe, it does not require a parent-child relationship, which makes it useful for coordinating unrelated programs on the same machine.
Q6. A student believes that any two processes can use a pipe without any setup. Which correction is most accurate?
📖 Explanation: Anonymous pipes are created by a process and then inherited by children, so the communicating processes must share the descriptors. Two unrelated processes cannot simply open an anonymous pipe. The misconception mistakes an anonymous pipe for a named one, which avoids this restriction through a file-system name.
Q7. Why can a named pipe connect unrelated processes while an anonymous pipe cannot?
📖 Explanation: The file-system name gives a well-known rendezvous point, so unrelated processes can find the same pipe and open it. An anonymous pipe is accessible only through inherited descriptors, which limits it to related processes. The difference is therefore one of discoverability rather than capacity or speed.
Q8. Why must a POSIX-style shared memory object be sized before it is mapped and used?
📖 Explanation: The object is created empty, and its length is set explicitly before mapping. Without this step, the mapping would refer to no usable storage, so accesses would fail. This two-part setup, creating and then sizing, is a common source of errors for those new to shared memory APIs.
Q9. Why do message queues allow a receiver to choose messages by type rather than only taking the oldest message?
📖 Explanation: The type field lets the receiver select messages that match its current need, which is useful when different kinds of requests have different priorities or handlers. This flexibility distinguishes message queues from a simple first-in first-out pipe, where data is read strictly in arrival order.
Q10. Why does a socket address combine an IP address with a port number?
📖 Explanation: A single host may run many network services, so the IP address alone cannot distinguish them. The port number selects the intended service or process, and together the pair uniquely identifies an endpoint. This combination is what allows many clients and servers to share one network connection.
Q11. Why is a TCP connection described as connection-oriented while UDP is not?
📖 Explanation: TCP performs a handshake and then manages delivery, ordering and retransmission over the established connection. UDP simply sends datagrams with no such setup, which reduces overhead and latency but leaves reliability to the application. The distinction is important when designing a client-server service.
Q12. Why does a pipe transfer data through a kernel buffer, unlike shared memory which is accessed directly?
📖 Explanation: Pipe writes and reads cross the kernel boundary, so the data is copied twice, once in and once out. Shared memory maps the same physical pages into both processes, so reads and writes need no kernel copy after setup. This difference explains why shared memory usually performs better for large data volumes.
Q13. Why must a network server bind its socket to a known port before clients can reach it?
📖 Explanation: A client can only reach a service if it knows the address and port where the server is listening. Binding to a fixed, well-known port lets clients locate the service reliably. Random or unpublished ports would make the service impossible to discover without additional coordination.
Q14. Why might a message queue be preferred over a raw pipe when messages of different priority must be handled differently?
📖 Explanation: A pipe is a byte stream read in order, so it gives no way to prioritise particular messages. A message queue with type fields lets the receiver pick the kind it needs, which supports priority-based handling. Choosing the right mechanism depends on whether ordering by arrival or selection by type is required.
Q15. A parent creates a pipe, then forks a child. The child writes data and the parent reads it. Which pipe type is being used?
📖 Explanation: The pipe is created before fork, so both parent and child inherit its descriptors, which makes it an anonymous pipe. No file-system name is needed because the processes are related. This classic pattern of parent and child communicating through an inherited pipe is an everyday example of anonymous pipes.
Q16. Two unrelated programs on the same machine must exchange status messages through an entry visible in the file system. Which mechanism best fits this requirement?
📖 Explanation: A named pipe provides a file-system name that both unrelated programs can open, meeting the requirement for a visible rendezvous point. Anonymous pipes need a common ancestor, and private variables cannot be shared at all, so the named pipe is the appropriate choice here.
Q17. A producer writes a large image into a POSIX-style shared memory object, and a consumer maps it. Which sequence correctly sets up the shared region for the producer?
📖 Explanation: The object must exist before it can be sized, sizing must happen before mapping gives a usable region, and writing comes last. Reversing these steps would either fail or write to a region that has no storage. The correct order reflects the dependency of each step on the previous one.
Q18. A client wants to reach a web server running on host 10.0.0.5 on port 80. Which socket address should the client use?
📖 Explanation: The client needs the host's IP address to find the machine and the port to reach the service listening there. Port 80 is the conventional port for web traffic, so the full endpoint is 10.0.0.5:80. The order and the pairing matter, since swapping the two values gives an invalid address.
Q19. A server listens on port 8080 with one listening socket. Four clients connect at the same time, and the server accepts all four. How many socket endpoints does the server hold in total?
📖 Explanation: The listening socket remains open to accept further connections, and each accepted connection creates a separate socket. Four accepted sockets plus the one listening socket give endpoints on the server. Forgetting the listening socket, or counting only the accepted ones, produces the incorrect totals in the other options.
Q20. A pipe transfers 1000 KB of data, and copying takes 1 ms per 100 KB. The data is copied twice, once into the pipe and once out of it. What is the total copying time?
📖 Explanation: Splitting 1000 KB into 100 KB blocks gives 10 blocks, so one full copy takes 10 ms. Because the data crosses the kernel boundary both into and out of the pipe, the total is ms. Recognising that each transfer is copied twice explains why pipes cost more than shared memory for bulk data.
Q21. A student says that anonymous pipes can connect any two unrelated processes because they are stored in the file system. What is the error?
📖 Explanation: An anonymous pipe is an in-kernel buffer accessed through inherited descriptors, with no visible name. The student confuses it with a named pipe. The error matters because it leads to wrong designs for communication between unrelated programs, which need the named form.
Q22. A student says that a socket is identified by the IP address alone, so multiple network services on one host need no port numbers. What is wrong with this claim?
📖 Explanation: A single IP address may host many services such as web, mail and file transfer. The port selects which service a connection targets, so the address alone is insufficient to identify the intended endpoint. The student overlooks the second half of the socket address.
Q23. A student says that shared memory is slower than pipes because shared data must be copied twice. Which correction is most accurate?
📖 Explanation: Pipes copy data into and out of a kernel buffer for each transfer, while shared memory maps the same pages into both processes, requiring no per-transfer copy. The student reverses this relationship. Shared memory does need synchronisation, but its data path is usually cheaper.
Q24. A student says that UDP guarantees delivery and order, so it is the default for transferring important files. What is the flaw?
📖 Explanation: UDP sends datagrams without retransmission or ordering, which suits applications that tolerate loss or prefer low latency. Reliable file transfer needs the guarantees that TCP provides, so the student's default choice would risk missing or reordered data.
Q25. A student says that a message queue always delivers messages in strict arrival order, so the type field has no real use. What is the correction?
📖 Explanation: Message queues let a receiver request a specific type, which can deliver a later message before earlier ones of other types. The student assumes the queue behaves like a plain first-in first-out pipe, overlooking the selection capability that the type field provides.
Q26. A bar chart compares throughput for pipes and shared memory at transfer sizes of 1 KB, 64 KB and 1 MB. The gap between the two grows as the size increases. What is the best inference?
📖 Explanation: The widening gap shows that copying costs accumulate with data volume in pipes, while shared memory avoids these copies. The inference follows directly from the trend across sizes and explains why shared memory suits large transfers, although the chart alone does not identify the exact cause.
Q27. A table compares TCP and UDP when packets are dropped under congestion: TCP delivers all data but with retransmission delays, while UDP loses about 5 percent of datagrams. Which conclusion is best supported?
📖 Explanation: The table shows TCP sacrifices speed for completeness, while UDP keeps timing but loses some data. Applications such as live video or games may prefer that trade, which is the conclusion the table supports. The inference depends on the application's tolerance for loss, which the data itself illustrates.
Q28. A graph shows the number of connection endpoints on a server over time. A single listening socket is present throughout, and one accepted socket is added each time a client connects. After four clients have connected, what is the server's total count?
📖 Explanation: The listening socket is constant and each of the four clients adds one accepted socket, so the total is . Reading the graph correctly means recognising that the baseline does not disappear when connections are accepted, which is the same reasoning used when counting server endpoints.
Q29. A graph shows the depth of a message queue over time. The depth reaches its limit and stays there, after which the sender's requests are rejected. What does this suggest?
📖 Explanation: A depth that stays at its limit while sends fail indicates that messages arrive faster than the receiver removes them. The queue is saturated, and the rejections are the visible consequence. Diagnosing the cause requires comparing the production and consumption rates, which the plateau reveals.
Q30. Which combination correctly describes a mechanism that lets unrelated processes communicate through a persistent name in the file system?
📖 Explanation: A named pipe is visible in the file system, so unrelated processes can find and open it by name. Anonymous pipes and inherited descriptors depend on a common ancestor, and private variables are not shared at all, so only the named pipe fits the description.
Q31. Which pairing correctly matches an IPC mechanism with its defining property?
📖 Explanation: A socket is defined by an IP address and port, which uniquely identify a network endpoint. Shared memory avoids kernel copies rather than relying on them, message queues carry typed messages rather than an unordered byte stream, and anonymous pipes have no file-system name, so only the first pairing is accurate.
Q32. A message queue holds messages arriving in the order 3, 1, 2, 2, 1, where each number is the message type. A receiver then removes both messages of type 2 while leaving the rest. What order remains in the queue?
📖 Explanation: Removing both type-2 messages leaves the messages of types 3, 1 and 1 in their original arrival order, which gives 3, 1, 1. Keeping the relative order of the remaining messages is essential here, since the type field determines selection but not the order of the messages that stay.
Q33. A shared memory object of size bytes is mapped using pages of bytes each. How many pages does the mapping occupy?
📖 Explanation: The number of pages is . Expressing the sizes as powers of two makes the division a subtraction of exponents, which is a neat shortcut. The result shows how memory regions are divided into pages for mapping and management.
Q34. A message queue can hold at most 20 messages. A sender posts 45 messages while the receiver takes none. How many messages cannot be held in the queue at once and must be rejected or made to wait?
📖 Explanation: The queue holds 20 messages, so the remaining messages cannot be stored and must be rejected or delayed by the sender. Computing the overflow from capacity and offered load is a basic step in designing message-based systems that must avoid losing work under bursts.
Q35. Which combination describes a network-based, connection-oriented form of interprocess communication?
📖 Explanation: A TCP socket establishes a connection with a handshake before any data is exchanged, which makes it connection-oriented. UDP sends datagrams without such setup, shared memory is local and has no network handshake, and named pipes are confined to a single machine, so only the first option matches the requested description.