Task: Named Pipes
Navigate to labs/lab-10/tasks/named-pipes and run make to generate the support directory. In this exercise, you’ll implement client-server communication between two processes using a named pipe, also called FIFO. Both the sender and receiver are created from the same binary: run without arguments for a receiver, or with -s for a sender.
-
Use the
mkfifo()syscall to create a named pipe. If the FIFO already exists, useaccess()to check its permissions. If permissions are incorrect, or if it does not exist, recreate the FIFO. -
Complete the TODOs in
receiver_loop()andsender_loop()to enable communication. Ensure the FIFO is open before reading from or writing to it. Close the FIFO when you are done.Bonus: Run two receivers and a single sender in different terminals. You may notice some “strange” behavior due to how named pipes manage data with multiple readers. For more on this, see this Stack Overflow thread.
-
Inside the
tests/directory, you will need to runchecker.sh. The output for a successful implementation should look like this:
./checker.sh
Test for FIFO creation: PASSED
Test for send and receive: PASSED