dup2() and exec()
问题 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> int main( int argc, char **argv) { int pfds[ 2], i; size_t pbytrd; pid_t childpid; char buffer[ 200]; pipe( pfds); if( ( childpid = fork() ) == -1) { perror( "fork error: "); exit( 1); } else if( childpid == 0) { close( pfds[ 0]); dup2( pfds[1], 1); close( pfds[ 1]); for( i = 0; i < 10; i++) printf("Hello..."); execlp( "xterm","xterm","-e","./sample_a", (char *) 0); exit( 0); } else { close( pfds