Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Ok that makes sense. Does each subshell get it's own standard input stream and output stream? Also in the first case, ./foo calls system(/bin/sh). Shouldn't this sys call block in the first case? Also, why is the stdin of the process ./foo the same as the shell invoked by it? Commented Jun 9, 2014 at 0:20
  • @RohitRamprasad Standard input, standard output and other file descriptors are inherited by subprocesses. They change only when a process changes them explicitly; for example, the redirection and pipe operators in the shell cause the shell to manipulate descriptors just before invoking the command. Commented Jun 9, 2014 at 0:27
  • This makes a lot of sense. Thanks! What about the system call to /bin/sh. Shouldn't it also block in the first case? This is the last thing that is confusing me! Commented Jun 9, 2014 at 0:30
  • @RohitRamprasad The fact that foo calls some other program (such as a shell) doesn't change anything. The shell reads from standard input, so it will block if the end of file has not been reached, and return immediately if the end of file has been reached. Commented Jun 9, 2014 at 0:34