Linux - Having fun with Pipes
1) what is pipe?
Pipe man page :
«pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication. The array pipefd is used to return two file descriptors referring to the ends of the pipe. pipefd[0] refers to the read end of the pipe. pipefd[1] refers to the write end of the pipe. Data written to the write end of the pipe is buffered by the kernel until it is read from the read end of the pipe. For further details, see pipe(7).»
2)Creating half-duplex communication between parent and child:
the code and output:
description:
The child closes it’s write (fd[1]) and then reads from fd[0] into readForChild buffer and prints the output.
The parent closest it’s read(fd[0]) and then writes into writeForParent buffer and then passes the address to the fd[1].
More complicated Half-Duplex communication:
read comments for better undrstanding.