A pipe connects the output of one process to the input of another process.

In UNIX systems

We rely primarily on the pipe syscall to create a pipe. The pipe syscall takes an array that’s 2 elements wide. The first element fds[0] is the read end of the pipe, and the second element is the write end of the pipe fds[1]. It then sets the file descriptor ID into the array, which means we can operate on each end as we do with file descriptors.

Pipe returns a file descriptor, so we can operate on the pipes as

  • int pipe(int pipefd[2]): forms a one-way communication channel using two file descriptors.
    • This takes a 2-sized integer array pipefd. pipefd[0] is the “read” end of the pipe, and pipefd[1] is the “write” end of the pipe.
    • This is effectively a buffer managed by the kernel.
    • We can take advantage of process forking to allow two processes to effectively communicate via the two ends.