4,441
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <unistd.h>
#define BUFSIZE 100
int main()
{
int n;
int fd[2];
pid_t pid;
char buf[BUFSIZE];
if(pipe(fd)<0)
printf("pipe errorn");
if(pid=fork()<0)
printf("fork errorn");
if (pid>0)/*parent*/
{
close(fd[0]);
printf("this is parent process");
write(fd[1],"Hello world",12);
}
if(pid==0) /*child*/
{
//sleep(1);
printf("this is child process");
close(fd[1]);
n=read(fd[0],buf,BUFSIZE);
write(STDOUT_FILENO,buf,n);
}
return 0;
}