FIFO也称为有名管道,它是一种文件类型,在文件系统中可以看到。程序中可以查看文件stat结构中st_mode成员的值来判断文件是否是FIFO文件。创建一个FIFO文件类似于创建文件,FIFO文件就像普通文件一样
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include "clist.h" #include "clist.c" int main(int argc, char *argv[]) { if(mkfifo(argv[1], 0666) == -1) { if(EEXIST == errno) goto l; else { perror("mkfifo"); exit(-1); } } l; int my_fd; my_fd=open(argv[1], O_RDONLY); if(NULL == my_fd) { perror("open"); exit(-1); } int my_service; my_service=open(argv[1],O_RDONLY); if(NULL == my_service) { perror("my_service"); exit(-1); } void *fun(void * a) { ; } head_online= pthread_t pid; if(pthread_create(&pid, NULL, fun, &my_fd) < 0) { perror("pthread_creat"); exit(-1); } MSG buf; sprintf(buf, "hello!"); write(my_service, buf, sizeof buf); }
如果觉得本文对您有帮助,请点击‘顶’支持一下,您的支持是我写作最大的动力,谢谢。
原文:http://blog.csdn.net/u010236550/article/details/19170291