0
我使用execlp()
执行的子进程的命令,并保存到一个管道由家长本身例如打印管内容屏幕
int pipefd[2];
if (pipe(pipefd)) {
perror("pipe");
exit(127);
}
if(!fork()){
close(pipefd[0]);
dup2(pipefd[1], 1);
close(pipefd[1]);
execlp("ls", "ls", NULL);
} else {
close(pipefd[1]);
dup2(pipefd[0], 0);
close(pipefd[0]);
execlp("wc", "wc", NULL);
}
读取在某些情况下,家长不必执行任何操作,只是将管道内容打印在屏幕上,如何在屏幕上打印管道(可能由于未知输出大小而不存储到变量中)。