- #include<sys/types.h>
- #include<sys/stat.h>
- #include<errno.h>
- #include<string.h>
- #include<stdio.h>
- #include<unistd.h>
- #include<fcntl.h>
- int
- main (void)
- {
- char buf[1024];
- char fn[] = "myfifo";
- int ret = mkfifo (fn, S_IRUSR | S_IWUSR);
- if (ret == -1)
- {
- printf ("mkfifo error:%s\n", strerror (errno));
- return 1;
- }
- int rd = open (fn, O_RDONLY | O_NONBLOCK);
- int fd = open (fn, O_WRONLY | O_NONBLOCK, S_IRWXU);
- if (fd == -1)
- {
- printf ("open error:%s\n", strerror (errno));
- return 1;
- }
- write (fd, "hello", 5);
- read (rd, buf, 5);
- write (1, buf, 5);
- close (fd);
- unlink (fn);
- return 0;
- }
有名管道的非阻塞设置
原文:http://www.cnblogs.com/dpf-learn/p/7700977.html