【APUE】进程间通信之FIFO

FIFO也称为有名管道,它是一种文件类型,是半双工的。FIFO简单理解,就是它能把两个不相关的进程联系起来,FIFO就像一个公共通道,解决了不同进程之间的“代沟”。普通的无名管道只能让相关的进程进行沟通(比如父shell和子shell之间)。

创建FIFO类似于创建文件

#include <sys/stat.h>

int mkfifo(const char *pathname,mode_t mode);

//若成功则返回0,若出错返回-1

#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>

int main()
{
    int res=mkfifo("/tmp/my_fifo",0777);
    if(res==0)
        printf("FIFO Created\n");
    exit(EXIT_SUCCESS);
}

 

参考:

http://blog.csdn.net/MONKEY_D_MENG/article/details/5651430

posted @ 2014-07-20 15:41  合唱团abc  阅读(230)  评论(0编辑  收藏  举报