In this post, let’s set up a scenario using two FIFOs and a client-server model to demonstrate a deadlock situation.
The server waits for the client to send a message on one ππ°ππΆ (πππ’π ππππ ππ πππππ). At the same time, the client waits for a message from the server on another ππ°ππΆ (πππππ). This creates a situation where both are waiting for each other to send a message, thus causing a deadlock.
The server expects the client to write to πππππand then πππππ. The client, however, writes to πππππ first and then tries to write to πππππ. Both processes end up waiting for each other to read from the FIFOs they wrote to, resulting in a deadlock.
What to expect when you run it?
1. When you run the ππππππ.π Β program, it will first try to read from πππππ. Since nothing has been written to πππππ yet, it will block and wait for some data to be written.

2. When you run the ππππππ.π program, it will immediately try to write to πππππ. However, the server is not reading from πππππ yet; it’s still waiting on πππππ. So, the client will block at this point too.

3. As a result, both the server and the client will be stuck (deadlocked). (Picture 3) Neither will proceed, and you won’t see any output from either program.

So, how to we know if we are getting what we were expecting?
We can do this by echo “Test message” > πππππ Β in another terminal.
(Picture 4)

What do you expect after the above?
1. The server successfully read from πππππ and printed the message “Text message”. This means something (or someone) wrote to πππππ before or while the server was waiting to read from it. It could have been an external input, like using the echo command previously seen, or perhaps from a previous run of the client.
2. After reading from πππππ, the server moved on to read from πππππ.
3. When you run the client, it successfully wrote the message “Hello from client on fifo2!” to πππππ, which the server then read and printed.
4. Both programs completed their main execution flow after this, so they both exited. (Picture 4)
There was no deadlock in this scenario because the condition for the deadlock (server waiting on πππππ while the client writes to πππππ first) wasn’t met. Instead, the server was able to read from πππππ Β and then move on to read from πππππ.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An Article by: Yashwanth Naidu Tikkisetty
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
