#include <fcntl.h>
#include <stdio.h>
#include "apue.h"
#include <errno.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <stropts.h>
#include <sys/mman.h>
int
main(int argc , char *argv[])
{
int n,fd[2];
pid_t pid;
char line[MAXLINE];
if(pipe(fd)<0)
err_sys("pipe err");
if((pid=fork())<0)
err_sys("pipe erro");
else if(pid>0)
{
close(fd[0]);
if(write(fd[1],"hello world \n",13)<0)
err_sys("write err");
}
else{
close(fd[1]);
if((n=read(fd[0],line,MAXLINE))<0)
err_sys("read erro");
if(write(STDOUT_FILENO,line,n)<0)
err_sys("write erro");
}
exit(0);
}
父子进程通过管道传递数据
最新推荐文章于 2022-07-10 06:31:21 发布