//创建自己的管道
int pid = getpid();
char pipe_name[20]="/tmp/mypipe";
int client_pipe = mkfifo(pipe_name, 0777); //创建管道文件
if( client_pipe < 0 ){ //也可使用access(pipename,F_OK)测试文件是否存在,ret 0代表存在 -1代表不存在
printf("cannot create client pipe %s,error is %s", client_pipe_name,strerror(errno));
exit(-1);
}
int pipr_fd;
if( ( pipe_fd = open( pipe_name,O_RDONLY | O_NONBLOCK) ) < 0){
printf("cannot open client pipe\n");
exit(-1);
}
close(pipefd); //关闭管道文件
unlink(pipe_name); //释放一个管道文件的引用
管道的创建与读写
最新推荐文章于 2022-03-07 04:30:00 发布