//pipe.c
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int fd[2];
pid_t pid;
char buf[20]={0};
int len = 0;
if(pipe(fd) < 0)
printf("Create Pipe Error!\n");
if((pid = fork()) < 0) {
printf("Fork Error!\n");
} else if(pid > 0) {
close(fd[0]);
write(fd[1],"hello world\n", 12);
} else {
close(fd[1]);
read(fd[0], buf, 20);
printf("%s\n", buf);
}
//pause();
return 0;
}
网友评论