Great!
Here's a simple, exam-friendly explanation of all three major Inter-Process Communication (IPC) topics in Unit 4:
1. Message Queues – (10 Marks Answer)
Definition:
Message Queues are a method of communication between processes using messages. Messages are stored in a queue, and processes can
send and receive messages through this queue, even if they are running at different times.
Features:
Communication is asynchronous (doesn’t happen at the same time).
Messages are sent and received in FIFO (First In, First Out) order.
Every message has an ID and can be read by any process with access.
Works between related or unrelated processes.
Important System Calls:
Function Purpose
msgget() Create or access a message queue
msgsnd() Send a message to the queue
msgrcv() Receive a message from the queue
msgctl() Control operations (delete, set perms)
Structure:
struct msgbuf {
long mtype; // Message type
char mtext[100]; // Message data
};
Advantages:
Easy to use
Messages can be prioritized using mtype
Works even if the sender and receiver run at different times
Disadvantages:
Message size is limited
Slower than shared memory
Needs careful error checking
2. Shared Memory – (10 Marks Answer)
Definition:
Shared Memory is the fastest method of inter-process communication. A memory segment is created which can be shared by multiple
processes, so they can read and write directly to the same memory area.
Features:
Communication is very fast (no copying of data).
Both processes access the same memory location.
Needs synchronization (like semaphores) to avoid conflict.
Important System Calls:
Function Purpose
shmget() Create a shared memory segment
shmat() Attach shared memory to a process
shmdt() Detach shared memory
shmctl() Control operations (delete, set perms)
Advantages:
Fastest communication method
Efficient for large data sharing
Easy to use between related processes
Disadvantages:
Requires synchronization (like semaphores)
Risk of race conditions (if not managed properly)
Not suitable for unrelated processes
3. Semaphores – (10 Marks Answer)
Definition:
Semaphores are used to synchronize processes and control access to shared resources. They prevent race conditions by allowing only one
process to access a resource at a time.
Types of Semaphores:
1.
Counting Semaphore – allows access to a resource with multiple instances.
2.
Binary Semaphore – works like a lock (0 or 1), allowing only one process at a time.
Important System Calls:
Function Purpose
semget() Create or access a semaphore set
semctl() Control operations (like delete)
semop() Perform wait (P) and signal (V)
Operations:
Wait (P) – Decreases the semaphore value. If it becomes < 0, the process waits.
Signal (V) – Increases the semaphore value. If processes are waiting, one gets access.
Advantages:
Prevents data corruption in shared memory
Allows safe multi-process synchronization
Flexible for many situations
Disadvantages:
Complex to implement
Deadlocks may occur if used improperly
Not suitable for data transfer, only for control
Summary Table:
Topic Used For Speed Data Transfer Needs Sync? Key Functions
Message Queue Sending messages between procs Medium Yes No msgget, msgsnd, msgrcv
Shared Memory Sharing large data directly Very Fast Yes Yes shmget, shmat, shmdt
Semaphore Synchronizing access N/A No Yes semget, semctl, semop
Let me know if you want diagrams or short example programs for these topics!