🎓 BookMCQ
← Back to 3. Processes in Operating System

📝 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.
5
Easy
16
Medium
14
Hard

📝 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?

A.Anonymous pipe ✅
B.Named pipe
C.Socket
D.Shared memory segment
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.Message queue ✅
B.Shared memory segment
C.Semaphore
D.Signal
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.Socket ✅
B.Anonymous pipe
C.Shared memory segment
D.Mutex
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.fork
B.mmap ✅
C.wait
D.exec
💡 Difficulty: easy | ✅ Correct: B

📖 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?

A.Anonymous pipe
B.Named pipe ✅
C.Shared memory segment
D.Socket pair created inside a process
💡 Difficulty: easy | ✅ Correct: B

📖 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?

A.The student is correct because pipes are always global.
B.An anonymous pipe must be created and its descriptors shared with the processes that use it, which normally means they are related through a common ancestor. ✅
C.Pipes cannot be used on any system.
D.Pipes exist only in printers.
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.Because a named pipe has a name in the file system that any process can open, whereas an anonymous pipe has no name to look up. ✅
B.Because named pipes are stored on the printer.
C.Because anonymous pipes are faster and cannot be shared.
D.Because named pipes never use the kernel.
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.A newly created shared memory object starts with zero size, so it must be set to the required length before the mapped region can hold data. ✅
B.Shared memory objects are always fixed at one byte.
C.Sizing is needed only for pipes.
D.Sizing prevents the object from being read by other processes.
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.Because each message carries a type value, so a receiver can request a specific kind of message that it is ready to handle. ✅
B.Because message queues have no ordering at all.
C.Because the receiver is allowed to edit the messages before reading them.
D.Because types are only used in shared memory.
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.The IP address identifies the host machine, and the port identifies the particular service or process endpoint on that machine. ✅
B.The port identifies the keyboard, and the IP address identifies the printer.
C.The address is used only to store passwords.
D.Both values are always identical on any system.
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.TCP establishes a connection before data transfer and provides reliable ordered delivery, while UDP sends independent datagrams without setting up a connection. ✅
B.UDP always establishes connections, while TCP never does.
C.TCP is used only on printers.
D.Both protocols are identical except for their names.
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.Because the kernel mediates each pipe transfer, copying data into and out of its buffer, whereas shared memory is mapped into both address spaces. ✅
B.Because pipes use no memory at all.
C.Because shared memory must always be copied by the printer.
D.Because the kernel is absent for shared memory.
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.Clients need a well-known address to contact, so the server must publish a stable port on which it listens. ✅
B.Clients can only connect to ports chosen randomly on each request.
C.Servers never need to be found by clients.
D.The port is required only for printers.
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.Because a message queue lets the receiver select messages by their type field, while a raw pipe delivers bytes in strict arrival order. ✅
B.Because pipes cannot carry any data at all.
C.Because message queues never store messages.
D.Because raw pipes always reorder messages randomly.
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.Named pipe
B.Anonymous pipe ✅
C.Socket
D.Shared memory segment
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.Named pipe ✅
B.Anonymous pipe
C.Inherited descriptor
D.Private memory variable
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.Create or open the object, set its size, map it into the address space, then write the data. ✅
B.Write the data first, then map the object, then create it.
C.Map the object, write the data, then delete the object.
D.Set the size after the consumer has already read the data.
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.10.0.0.5 with port 80 ✅
B.80 with port 10.0.0.5
C.10.0.0.5 with port 8080 only
D.Port 80 with no address
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.1
B.4
C.5 ✅
D.8
💡 Difficulty: hard | ✅ Correct: C

📖 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 4+1=54 + 1 = 5 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?

A.5 ms
B.10 ms
C.20 ms ✅
D.40 ms
💡 Difficulty: hard | ✅ Correct: C

📖 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 2×10=202 \times 10 = 20 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?

A.There is no error, because all pipes are stored in the file system.
B.Anonymous pipes have no file-system name, so unrelated processes cannot find them; only named pipes provide that visibility. ✅
C.Anonymous pipes are stored only on the printer.
D.Pipes never transfer any data.
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.Nothing is wrong, since one address is enough.
B.Several services can run on one host, so the port number is needed to distinguish the endpoint that a connection should reach. ✅
C.Sockets do not use addresses at all.
D.Port numbers are used only in printers.
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.The claim is correct because shared memory always copies data twice.
B.Shared memory avoids the per-transfer kernel copies that pipes require, so it is typically faster for large data, although it needs synchronisation. ✅
C.Shared memory and pipes are identical in every respect.
D.Shared memory cannot transfer data.
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.There is no flaw, because UDP guarantees delivery.
B.UDP does not guarantee delivery or ordering, so reliable file transfer usually relies on TCP, which provides those guarantees. ✅
C.UDP is a file format.
D.UDP only works on printers.
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.The claim is correct because the type field is ignored.
B.The type field allows receivers to select particular message types, so the queue does not force strict arrival order when selection is used. ✅
C.Message queues never carry data.
D.Types are only used in printers.
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.Shared memory's advantage grows with transfer size because it avoids the per-transfer copying that pipes perform. ✅
B.Pipes outperform shared memory increasingly at large sizes.
C.Transfer size has no effect on either mechanism.
D.Both mechanisms have identical throughput at every size.
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.UDP is the right choice for applications where some loss is acceptable and low latency matters more than completeness. ✅
B.TCP loses more data than UDP under congestion.
C.Retransmission delays make TCP unusable in all cases.
D.Packet loss is identical for both protocols.
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.4
B.5 ✅
C.6
D.8
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The listening socket is constant and each of the four clients adds one accepted socket, so the total is 1+4=51 + 4 = 5. 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?

A.The receiver is consuming messages more slowly than the sender produces them, so the queue saturates. ✅
B.The receiver is consuming messages faster than they arrive.
C.The queue has no limit and cannot be full.
D.The sender has stopped sending entirely.
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.A named pipe. ✅
B.An anonymous pipe.
C.A private variable.
D.An inherited descriptor.
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.Socket with an IP address and a port number ✅
B.Shared memory with a kernel buffer that copies every byte
C.Message queue with an unordered single-byte stream only
D.Anonymous pipe with a file-system name visible to all users
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.36951 ✅
B.37622
C.36952
D.36924
💡 Difficulty: hard | ✅ Correct: A

📖 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 2202^{20} bytes is mapped using pages of 2122^{12} bytes each. How many pages does the mapping occupy?

A.128
B.256 ✅
C.512
D.1024
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The number of pages is 220/212=28=2562^{20} / 2^{12} = 2^{8} = 256. 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?

A.20
B.25 ✅
C.45
D.0
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The queue holds 20 messages, so the remaining 45−20=2545 - 20 = 25 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?

A.A TCP socket that performs a connection setup before data flows. ✅
B.A UDP socket that performs a connection setup before data flows.
C.Shared memory that performs a handshake between processes.
D.A named pipe that is carried across the network automatically.
💡 Difficulty: medium | ✅ Correct: A

📖 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.

🔗 Related Topics (MCQs)