#include <stdio.h>
#include <fcntl.h>
int main(void)
{
const char *pipe_name = ".luther.gliethtttp.0";
int fd;
unlink(pipe_name);
mkfifo(pipe_name, 0666);
fd = open (pipe_name, O_RDWR | O_NDELAY);
if (fd < 0) {
printf("Error to open pipe!\n");
return -1;
}
for (;;) {
static int count = 0;
char buf[20];
int len;
len = sprintf(buf, "%d\n", count++);
write(fd , buf, len);
sleep(1);
}
return 0;
}
|
luther@gliethttp:/vobs/tmp$ gcc mkfifo_pipe.c
luther@gliethttp:/vobs/tmp$ ./a.out
打开另一个terminal,运行cat读取.
luther@gliethttp:/vobs/tmp$ cat .luther.gliethtttp.0 // 读取.luther.gliethtttp.0管道发过来的数据.
0
1
2
3
4
5
6
7
阅读(1642) | 评论(0) | 转发(0) |