官术网_书友最值得收藏!

Pipes

We have already used pipes in many earlier sections. It is a tool for inter-process communication:

    $ command_1 | command_2

In this case, the output of command_1 will be sent as an input to command_2. The limitation is that the communication is half duplex. This means the data can flow in only one direction. Normally, for inter-process communication, you need to open files and then get the file descriptor. This will be used to write to the pipe file. Again, we need to create a Fifo file with special commands. The preceding technique simplifies this process. We only need to insert | in between the two processes. The operating system creates one intermediate buffer. This buffer is used for storing the data from one command and will be used again for the second command.

A simple example is as follows:

    $ who | wc

The preceding simple command will carry out three different activities. First, it will copy the output of the who command to the temporary file. Then the wc command will read the temporary file and display the result. Finally, the temporary file will be deleted.

Normally, there will be two processes. The first command is the writer process. The second process is the reader process. The writer process will write to temp_file and the reader will read from temp_file. Examples of writer processes are ps, ls, and date. Examples of reader processes are wc, cat, grep, and sort.

主站蜘蛛池模板: 兴海县| 察哈| 内乡县| 齐齐哈尔市| 读书| 萝北县| 湾仔区| 喀喇沁旗| 陕西省| 房山区| 英超| 崇文区| 边坝县| 荥阳市| 仙居县| 凤庆县| 永泰县| 湟源县| 昌乐县| 高雄县| 灵山县| 红河县| 铁岭市| 潜江市| 白河县| 凌海市| 林周县| 屏东县| 迁安市| 泰宁县| 聊城市| 许昌市| 宜良县| 五家渠市| 永嘉县| 宜丰县| 夏河县| 麻江县| 文山县| 简阳市| 金沙县|