 Hi everyone in this video we will learn about inter-process communication so there are various mechanisms using which two processes can interact with each other but what we'll use here is the named pipes so we will run one process process one and we'll run another process called process two and we will send some messages from process one to process two using a named pipe and then we'll have another pipe using which we'll send messages back from process two to process one so let's look at the code so this is code for process one so we will open two pipes between process one and process two one is for writing and one is for reading so process one will write in one pipe from which process two will read and there will be another pipe in which process one will write and process two will read so we have two file descriptors what is for writing one is for reading we print this opening fee for a name pipe is also called FIFO in Linux so this FIFO is just like a normal file and we can see that in file explorer but it acts like a named pipe so we first define just two paths this is the path for our FIFO file so this is inside m folder we have my FIFO one and my FIFO two we use this MKFIFO function to create the FIFO file its first argument is the part to the file and second is the permission so if we check if the return value is equal to minus one that means there was some error and here we are checking if the error number is not e exist so if it is e exist so that would mean that this FIFO was already there and we do not worry because we just want that there is a FIFO at this particular path which we can use we similarly create the another FIFO file and then we open both these files so in process one we open FIFO one for writing and we open FIFO two for reading so we give the respective file descriptor to these variables and if we look at process two's code we have similar code till this point where we define this my FIFO one my FIFO two we make these both FIFO's but here we use my FIFO one for reading and my FIFO two for writing so let's continue so we print that FIFO was opened and then we have two buffers one is for process one messages and another is for process two messages now we execute this while loop and we first read the message from fd read which means we want first message from process two and we read it in this buffer we check if the message length is not zero then we continue and we print that this was the message received from process two we reset this message from process two buffer and then we take in input some new message from the terminal for process one and we write it to the fd write file descriptor so here we are reading a message from the first pipe and here we are writing to the second pipe using the write function then we reset this message from process one buffer so this will execute in a while loop and in the end we close both the file descriptors and we print FIFO closed and return zero and in process two's code we have a similar code till this point but here first we take in input some message from the user and then we write it to fd write so we send some message from pipe one to process one and process two reads that message and then we read a reply from process one using this read function and we print out that message and then we again take in input this message from process two and this we continue till we get a buy in process two and finally we write an empty message to fd write so that in process one this while loop can exit so the length of message from process two will be zero and it will break and then we close both this file descriptors and we print out FIFO closed so let's compile both of these programs and see the output let's open two terminals alright I'll compile process one and named executable process one I will similarly compile process 2.c okay and now I run process one so here if we see this process one is stuck at opening FIFO let's try to understand why it is stuck after opening FIFO let's have a look at the code again so what we are doing in process one is we are creating two FIFO files we then open both these files one for writing another for reading and then we print FIFO open but it didn't print FIFO open which means that it is stuck somewhere here so it is stuck because in case of FIFO the open code blocks until there is another open for reading so it is stuck after this point so if we look at the man page of open man to open and if we scroll down so here it is mentioned that opening the read or write end of FIFO blocks until the other end is also opened so here this open call is blocking till we also open reading end of this pipe in some other process so now if I execute process two only then can process one go ahead so let's again open these terminals all right so here I'll execute process two and once I press enter then you will see that it will print out open FIFO so we have both the FIFO open in both the processes and process two is showing us this cursor for input so let's send some message hello from process two and we receive that message here in process one so here we can send messages back and forth between process one and process two using two named pipes we can in fact see these FIFO files in the TMP folder so let's execute this LSTMP so here you can see these two files my FIFO one and my FIFO two so these are those two FIFO files so that's it for this video thanks and have a nice day