Codementor Events

See code run - Understand later - 4

Published May 28, 2021
See code run - Understand later - 4

We have taken some time to understand about the pipe.
With the expert like you, it should take more time.
In this post, we continue to focus on the pipe to know what it is.

pipe2.png

pipe() is system function. It is run in the kernel mode. When the function is called, a pair of file descriptors are returned: one for reading, one for writing.

The pipe we are using is unnamed pipe.
If the mkfifo() is called, it is named pipe. For example,

int ret = mkfifo("a_pipe", 0777);

Then other processes can open, read, write a_pipe as the normal file.

When researching, we can easily create a pipe by running the command line in terminal:

cat myfile.txt | less

The output of the cat command (open file and read the content) is the input of the less (use arrow keys or page up/down). The pile is created automatically ???
In fact, '|' is processed by the terminal program only. When user uses '|', it creates pipe(s) by using fork(), pipe(), dup(), dup2()...We will discuss and write the command line program like terminal later.

So there are two pipes only: named or unnamed pipe.

...updating soon...

Discover and read more posts from Duc Duy Bui
get started
post commentsBe the first to share your opinion
Show more replies