mkfifo()函数

/*********************************************************************************
 *      Copyright:  (C) 2013 fulinux<[email protected]>
 *                  All rights reserved.
 *
 *       Filename:  mkfifo.c
 *    Description:  This file
 *                
 *        Version:  1.0.0(04/17/2013~)
 *         Author:  fulinux <[email protected]>
 *      ChangeLog:  1, Release initial version on "04/17/2013 03:31:24 PM"
 *                
 ********************************************************************************/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define FIFO "fifo"

main()
{
    char buffer[80];
    int fd;
    unlink(FIFO);
    mkfifo(FIFO,0666);
    if(fork()>0)
    {
        char s[] = "hello\n";
        fd = open(FIFO,O_WRONLY);
        write(fd,s,sizeof(s));
        close(fd);
    }
    else
    {
        fd = open(FIFO,O_RDONLY);
        read(fd,buffer,80);
        printf("%s",buffer);
        close(fd);
    }
}

 

mkfifo()函数_第1张图片

 

 

你可能感兴趣的:(函数)