12 Difference Between PIPE And FIFO Inter-Process Communication
Table of Contents
What Is PIPE?
A pipe is a mechanism for inter-process communication; data written to the pipe by one process can be read by another process. The data is handled in a first-in, first-out (FIFO) order. The pipe has no name; it is created for one use and both ends must be inherited from the single process which created the pipe.
In PIPES when we use fork () it creates a process like a duplicate of main. That means when we use fork there are two processes that are generated, one is referred to as parent process and another one is referred to as child process. Fork returns -1 when forking is failed, and when it returns 0 that means its child process and when fork return a positive value that means it is a parent process.
If child process exit before parent process, it referred to as Zombie process whereas if parent process exit before child process then its referred to as orphan process. In this case child is managed by Init process, pipe function is declared in header file #include.
What You Need To Know About PIPE
- They are un-named IPC Object.
- FIFO is capable of communicating across different computers and network.
- PIPE does not exist in the file system.
- In PIPE, data transfer takes place between the child process and parent process.
- PIPE is created by pipe () function.
- In PIPE, reader and writer operation is done at same time.
- PIPE vanishes as soon as it is closed, or one of the processes (parent or child) completes execution.
- PIPE has no control over ownership and permissions.
- PIPE is unidirectional.
- PIPE provides simplex data flow.
- In PIPE, communication is among the process having a common ancestor (related process).
FIFO
A FIFO is a special kind of file on the local storage which allows two or more processes to communicate with each other by reading or writing to or from the file. It is similar to a pipe, but instead of being an anonymous, temporary connection, a FIFO has a name or names like any other file. Processes open the FIFO by name in order to communicate through it.
A FIFO special file is entered into the file system by calling mkfifo() in C. once we have created a FIFO special file in this way, any process can open it for reading or writing, in the same way as an ordinary file. However, it has to be open at both ends simultaneously before you can proceed to do any input or output operation on it.
What You Need To Know About FIFO
- They are named IPC Object.
- PIPE is local to the system and cannot be used for communication across the network.
- FIFO exists in the files system.
- FIFO have multiple processes communicating through it, like multiple client-server application.
- FIFO is created by mkfifo () function.
- In FIFO, it does not require that both read and write operation to occur at the same time.
- FIFO exists even when calling process exit. They remain till system reboots.
- Given that FIFO is a file, you can control ownership and permissions.
- FIFO is bi-directional. The same FIFO can be used for reading and writing.
- FIFO provides half duplex data flow.
- In FIFO, it is not necessary for the process having a common ancestor for communication (unrelated process).
Also Read: Difference Between Calloc () And Malloc ()
Difference Between PIPE And FIFO Inter-Process Communication
BASIS OF COMPARISON | PIPE | FIFO |
Description | They are un-named IPC Object. | They are named IPC Object. |
Communication | FIFO is capable of communicating across different computers and network. | PIPE is local to the system and cannot be used for communication across the network. |
Existence | PIPE does not exist in the file system. | FIFO exists in the files system. |
Processes | In PIPE, data transfer takes place between the child process and parent process. | FIFO have multiple processes communicating through it, like multiple client-server application. |
Creation | PIPE is created by pipe () function. | FIFO is created by mkfifo () function. |
Read And Write Operation | In PIPE, reader and writer operation is done at same time. | In FIFO, it does not require that both read and write operation to occur at the same time. |
Existence | PIPE vanishes as soon as it is closed, or one of the processes (parent or child) completes execution. | FIFO exists even when calling process exit. They remain till system reboots. |
Control Over Ownership And Permissions | PIPE has no control over ownership and permissions. | Given that FIFO is a file, you can control ownership and permissions. |
Nature | PIPE is unidirectional. | FIFO is bi-directional. The same FIFO can be used for reading and writing. |
Mode Of Communication | PIPE provides simplex data flow. | FIFO provides half duplex data flow. |
Communication | In PIPE, communication is among the process having a common ancestor (related process). | In FIFO, it is not necessary for the process having a common ancestor for communication (unrelated process). |
ncG1vNJzZmiumauupbXFn5yrnZ6YsrR6wqikaJyZm7OmvsSnmp5lkprBuLHEp2SpoaCaeqK6w2adop6fYravwMSrZKmqn5iytL%2BMnKampaWjtqSt06Kmp2c%3D