title: How can a Unix program display output on screen even when stdout and stderr are redirected?
body: <p>I was running a program (valgrind, actually) on my Ubuntu machine, and had redirected both stdout and stderr to different files. I was surprised to see a short message appear on the screen -- how is that possible? How could I do that myself in a C++ program?</p>
  
  <p>EDIT: Here's the command I used, and the output:</p>
  
  <pre><code>$ valgrind ./myprogram &gt; val.out 2&gt; val.err
  *** stack smashing detected ***: ./myprogram terminated
  </code></pre>
  
  <p>EDIT2: Playing with it a little more, it turns out that myprogram, not valgrind, is causing the message to be printed, and as answered below, it looks like gcc stack smashing detection code is printing to /dev/tty</p>