Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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.
share|improve this answer

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().

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.