4

If a program runs fork() what sets standard streams STDOUT, STDIN and STDERR?

2 Answers 2

7

Stdin, stdout and stderr are inherited from the parent process. It's up to the child process to change them to point to new files if that is needed.

From the fork(2) man page:

   *  The  child inherits copies of the parent's set of open file descrip‐
      tors.  Each file descriptor in the child refers  to  the  same  open
      file  description (see open(2)) as the corresponding file descriptor
      in the parent.
0

As Kyle Jones states, they're propagated from the parent process. If you're asking how to set them in a child, you're looking for freopen().

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.