Why do I need to close fds when reading and writing to the pipe?

后端 未结 5 813
迷失自我
迷失自我 2020-12-24 09:28

Here is an example to illustrate what I mean:

#include 
#include 
#include 

int main(void)
{
        int           


        
5条回答
  •  情深已故
    2020-12-24 09:51

    "The example above seems to work only for one write and one read."

    That is because after one read and write your code exits. You need to keep writing in a loop and reading in a loop to achieve continuity. It does not seem to have anything to do with the FD close. As mentioned in an earlier reply you need one end on each process so the other is closed.

    I hope I understand the query right.

提交回复
热议问题