Pipe is a symbol used to provide output of one command as input to another command. The output of the command to the left of the pipe is sent as input to the command to the right of the pipe. The symbol is
Pipes are useful to chain up several programs, so that multiple commands can execute at once without using a shell script.
how to create?
Creates a pipe using pipe() system call. pipe create two file descriptor
fd refers to the read end of the pipe.
fd refers to the write end of the pipe.
To create a simple pipe with C, we make use of the pipe() system call. It takes a single argument, which is an array of two integers, and if successful, the array will contain two new file descriptors to be used for the pipeline. After creating a pipe, the process typically spawns a new process (remember the child inherits open file descriptors).
int fd, nbytes;
char string = "Hello, world!\n";
if((childpid = fork()) == -1)
if(childpid == 0)
/* Child process closes up input side of pipe */
/* Send "string" through the output side of pipe */
write(fd, string, (strlen(string)+1));
/* Parent process closes up output side of pipe */
/* Read in a string from the pipe */
nbytes = read(fd, readbuffer, sizeof(readbuffer));
printf("Received string: %s", readbuffer);
the difference between half duplex and full duplex pipes?
Half-Duplex allows for communication in one direction at one time then can switch to the opposite direction.
Full-Duplex allows for communication in either direction at any time.
Historically, pipes have been half duplex (i.e., data flows in only one direction). Some systems now provide full-duplex pipes.