pipe

来源:互联网 发布:证件照ps软件 编辑:程序博客网 时间:2024/05/29 09:41
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>

int main()
{
    int fd,fp,fp1;
    char buf[100]={0};
    int res = mkfifo("data",0777);
    if(res == 0)
    {
        printf("FIFO created!\n");
    }
    else
    {
        perror("fifo error\n");
    }
    fp = fork();
    if(fp<0)
    {
        perror("fork error");
        exit(1);
    }
    if(0 == fp)
    {
        fd = open("data",O_WRONLY);
        if(fd == -1)
        {
            perror("open error");
            exit(1);
        }
        else
        {
            write(fd,"hello",sizeof("hello"));
            printf("open success\n");
        }
        exit(0);
    }
    
}
原创粉丝点击