If you read
Perderabo's post carefully you would not be asking this question. The scenario you are describing cannot happen since dup2 will do what you tell it to instead of picking the lowest file descriptor available and assigning it to pfds. The notion of parent and child process is relative as this is decided only by the return value of the fork() function as to which process becomes the parent and which the child. In your case the "ls" process is the child process (though a small code change can swap this around) while the "wc -l" is the parent process.