This project focuses on developing a strong understanding of Linux interprocess communication mechanisms. The task involves creating two programs, P1 and P2. P1 generates an array of 50 random strings and sends groups of five consecutive elements to P2 along with their corresponding IDs. P2 accepts the strings, prints the IDs and strings, and sends back the highest received ID to acknowledge the strings. The communication needs to be implemented using three techniques: Unix domain sockets, FIFOs, and message passing queues.
There are three folders for the following project, with each folder containing versions of programs P1 and P2
- Part 1 - Unix Domain Socket Variant : Implements interprocess communication using Unix domain sockets.
- Part 2 - FIFO Variant : Implements interprocess communication using FIFOs.
- Part 3 - Message Passing Queue Variant : Implements interprocess communication using message passing queues.
- Strings are passed between processes P1 and P2 using sockets.
- P1 generates random strings using the
rand()
function. - The
sockaddr_un
struct is created and filled with the necessary variables usingmemset
. - A connection is established using the
connect
function. - Messages are sent between P1 and P2 using the
read
andwrite
system calls. - P1 sends messages to P2, which reads the messages, prints the strings, and sends back the index with the maximum value.
- P1 prints the index.
- After sending 50 strings, the socket closes.
- Strings are passed between processes P1 and P2 using message queues.
- P1 generates random strings using the
rand()
function. - Two message queues are created, one for sending data from P1 to P2 and the other for sending data from P2 to P1.
- P1 sends messages to P2 using
mq_send
, and P2 reads the messages usingmq_receive
. - P2 prints the strings it receives, sends back the index with the maximum value to P1, and prints the index.
- After sending 50 strings, the message queue closes.
Please refer to the individual program files for more detailed implementation.
To use the IPC Sockets project, follow the steps below:
- Clone the repository
- Navigate to the project directory
- Build the programs using the provided Makefile:
make
- Run the P1 program to generate random strings and send them to P2:
./P1
- Run the P2 program to receive the strings and acknowledge them:
./P2
- P2 will print the received strings and their corresponding IDs on the console.
Note: Make sure to run P2 after starting P1 to ensure successful communication.