Unix pipe - reading data from stdin in the child descriptor
问题 I'm trying to implement unix piping in c (i.e. execute ls | wc). I have found a related solution to my problem (C Unix Pipes Example) however, I am not sure why a specific portion of the solved code snippet works. Here's the code: /* Run WC. */ int filedes[2]; pipe(filedes); /* Run LS. */ pid_t pid = fork(); if (pid == 0) { /* Set stdout to the input side of the pipe, and run 'ls'. */ dup2(filedes[1], 1); char *argv[] = {"ls", NULL}; execv("/bin/ls", argv); } else { /* Close the input side of