|
楼主 |
发表于 2009-3-26 10:23:50
|
显示全部楼层
void sort_pipe(char *argv[SIZE], int mark)
{
int fd[2];
pid_t pid;
argv[mark] = (char *) 0;
if ((pid = fork()) < 0)
printf("sub fork error\n");
else if (pid == 0) {
if (pipe(fd))
printf("error in creating pipe\n");
if (fork() == 0) {
close(fd[0]);
close(STDOUT_FILENO);
dup(fd[1]);
close(fd[1]);
if (execvp(argv[0], argv) < 0)
printf("%s: %s\n", argv[0], strerror(errno));
exit(0);
}
close(fd[1]);
close(STDIN_FILENO);
dup(fd[0]);
close(fd[0]);
if (execvp(argv[mark + 1], &argv[mark + 1]) < 0)
printf("%s: %s\n", argv[mark + 1], strerror(errno));
exit(0);
}
if ((pid = waitpid(pid, NULL, 0)) < 0) {
printf("waitpid error\n");
printf("%s\n", strerror(errno));
}
} |
|