Palindrome Checking Using Message Queue
MESSAGE QUEUE – STRING REVERSAL & PALINDROME CHECK
1. AIM
To implement interprocess communication using System V Message Queues, where:
-
Process 1 (Sender) sends a string to Process 2 (Receiver).
-
Process 2 reverses the string and sends it back.
-
Process 1 compares the original and reversed strings to determine whether the string is a palindrome.
2. THEORY
Message queues allow processes to exchange structured messages. They support:
-
Bidirectional communication
-
Asynchronous message transfer
-
Typed messages (each message has a type)
System V message queue APIs used:
| Function | Purpose |
|---|---|
msgget() | Create or access a message queue |
msgsnd() | Send a message |
msgrcv() | Receive a message |
msgctl() | Control operations (delete queue) |
Communication steps:
-
Process 1 → sends string (
msgsnd) -
Process 2 → receives string, reverses it, sends back
-
Process 1 → receives reversed string and checks palindrome
3. ALGORITHM
Process 1 (Sender)
-
Create message queue using
msgget(). -
Read a string from the user.
-
Send the string to Process 2 (
msgsnd). -
Wait and receive the reversed string (
msgrcv). -
Compare original and reversed string.
-
Print whether the string is a palindrome.
-
Remove the message queue (
msgctl).
Process 2 (Receiver)
-
Access the same message queue using
msgget(). -
Receive string sent by Process 1.
-
Reverse the string.
-
Send reversed string back.
4. PROGRAM
File 1: sender.c (Process 1)
File 2: receiver.c (Process 2)
5. COMPILATION & EXECUTION
Open two terminals:
Terminal 1 – Run Receiver
Terminal 2 – Run Sender
6. SAMPLE OUTPUT
Sender Terminal
Receiver Terminal
7. RESULT
The program successfully demonstrates interprocess communication using System V Message Queues, where:
-
One process sends a string,
-
Another process reverses it and sends it back,
-
The first process checks if it is a palindrome.
Comments
Post a Comment