Linux进程间管道通信
Linux进程间管道通信
mkfifo()
//创建有名管道(FIFO special file),创建完了就像普通文件一样open(),再读写,成功返回0,失败返回-1设errno。VS$man 3 mkfifo #include <sys/types.h> #include <sys/stat.h> int mkfifo(const char *pathname, mode_t mode);
pathname:the FIFO special file's name
mode :the FIFO's permissions.
//创建FIFO管道文件 int res=mkfifo(“./a.fifo”,0664); if(-1==res) perror("mkfifo"),exit(-1); res=open(“./a.fifo”,O_RDONLY); if(-1==res) perror(“open”),exit(-1);
pipe()
//创建无名管道,相当于直接把open()返回的fd直接放到形参中,而不需额外的变量接收管道文件的描述符,用于父子进程间通过管道进行IPC通信,,成功返回0,失败返回-1设errno #include <unistd.h> int pipe(int pipefd[2]);
pipefd :return two fds referring to the ends of the pipe.
- pipefd[0] :read end,读端
- pipefd[1] :write end,读端.
fork()创建的child也会文件描述符总表也会复制一份So,对于child, 应该先关闭读端, 再写,对于parent,应该先关闭写端, 再读
相关推荐
Sabrina 2019-12-22
咏月东南 2019-10-29
GeorgeTH 2019-10-26
宁静致远 2011-04-23
wpeng 2011-03-21
PpikachuP 2019-07-01
azhedashuaibi 2019-06-21
zyccsdn 2019-05-12
FruitDrop 2018-09-23
chuangjinweilai 2018-11-07
chuangjinweilai 2018-04-17
heiworld 2018-03-08
YoungkingWang 2018-04-02
wking 2018-04-02
wutongyuq 2018-02-05
Hamlee 2014-02-19
zjwpython 2017-08-28
zhenyaqi 2014-06-17