#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<string.h>
int main (int argc, char *argv[])
{
int status = -1;
int fd[2]={0};
char buf[20]={0};
pid_t pid;
mkfifo(myfifo, 00777);
pid = fork();
if(0 == pid)
{
close(fd[0]); //关闭读口
if(0 == strcmp("write", argv[1]))
{ //write
printf("write...\n");
write(fd[1], "hello myfifo", 13);
}
}
if(0 < pid)
{
close(fd[1]);// 关闭写口
if(0 == strcmp("read", argv[1]))
{ //read
printf("read..");
read(fd[0], buf, sizeof(buf));
printf("buf=%s\n",buf);
}
wait(&status);// 等待子进程结束
}
return 0;
}