Navid Malekghaini's Personal Blog

My personal weblog for sharing and storing some of my activities related to computer science over the internet

Navid Malekghaini's Personal Blog

My personal weblog for sharing and storing some of my activities related to computer science over the internet

Navid Malekghaini's Personal Blog

Navid Malekghaini

Software Engineer @ Intelligent Cloud Infrastructure Laboratory
Prev. ML Researcher @ University of Waterloo x Orange Telecom

University of Waterloo
Department of computer science
200 University Ave W, Waterloo, ON N2L 3G1, Canada
cs.uwaterloo.ca

contact me
navidmalekedu (AT) gmail (DOT) com [ Primary Email ]
nmalekgh (AT) uwaterloo (DOT) ca

Linux - Having fun with Pipes

Sunday, 13 August 2017، 10:21 AM

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.