Calling fclose() here after dup()ing its file descriptor blocks until the child process has ended (presumably because the stream has ended).