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.

  1. Use the mkfifo() syscall to create a named pipe. If the FIFO already exists, use access() to check its permissions. If permissions are incorrect, or if it does not exist, recreate the FIFO.

  2. Complete the TODOs in receiver_loop() and sender_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.

  3. Inside the tests/ directory, you will need to run checker.sh. The output for a successful implementation should look like this:

./checker.sh
Test for FIFO creation: PASSED
Test for send and receive: PASSED