title: Redirecting STDIN, STDOUT, STDERR to /dev/null in C
body: <p>In Stevens' UNIX Network Programming, he mentions redirecting stdin, stdout and stderr, which is needed when setting up a daemon.  He does it with the following C code</p>
  
  <pre><code>/* redirect stdin, stdout, and stderr to /dev/null */
  open("/dev/null", O_RDONLY);
  open("/dev/null", O_RDWR);
  open("/dev/null", O_RDWR);
  </code></pre>
  
  <p>I'm confused how these three 'know' they are redirecting the three std*.   Especially since the last two commands are the same.  Could someone explain or point me in the right direction?</p>