/*********************************************************************************

 *      Copyright:  (C) 2013 fulinux<​​fulinux@sina.com​​>

 *                  All rights reserved.

 *

 *       Filename:  mkfifo.c

 *    Description:  This file

 *                

 *        Version:  1.0.0(04/17/2013~)

 *         Author:  fulinux <​​fulinux@sina.com​​>

 *      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);

    }

}