Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
2 views10 pages

Unit IV

The document provides an overview of three major Inter-Process Communication (IPC) methods: Message Queues, Shared Memory, and Semaphores. Message Queues allow asynchronous communication with FIFO message handling, while Shared Memory offers the fastest data sharing method requiring synchronization. Semaphores are used for process synchronization to prevent race conditions, with various advantages and disadvantages outlined for each IPC method.

Uploaded by

nousenamae
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Unit IV

The document provides an overview of three major Inter-Process Communication (IPC) methods: Message Queues, Shared Memory, and Semaphores. Message Queues allow asynchronous communication with FIFO message handling, while Shared Memory offers the fastest data sharing method requiring synchronization. Semaphores are used for process synchronization to prevent race conditions, with various advantages and disadvantages outlined for each IPC method.

Uploaded by

nousenamae
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

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!

You might also like