Aren't pipes in UNIX supposed to be uni-directional?

后端 未结 3 1011
予麋鹿
予麋鹿 2021-01-02 12:30

Have a look at the following code:

#include
#include
#include
#include
#include

        
3条回答
  •  抹茶落季
    2021-01-02 12:41

    In POSIX.1-2001, pipes are unidirectional. From the man page:

    pipe() creates a pair of file descriptors, pointing to a pipe inode, and places them in the array pointed to by filedes. filedes[0] is for reading, filedes[1] is for writing.

    By the way, your use of fork is wrong: fork returns pid>0 for the parent and pid==0 for the child. pid<0 means there was an error.

提交回复
热议问题