title: Why memory mapping to `STDOUT_FILENO` failed?
body: <p>I have written some code to test the <code>mmap</code> system call.</p>
  <p>Here I want to map the virtual memory address space to the <code>STDOUT</code>, and print a string via the pointer <code>ptr</code> that returned by the <code>mmap</code>.</p>
  <pre class="lang-c prettyprint-override"><code>int main()
  {
      void *ptr = mmap(NULL, 1024, PROT_WRITE | PROT_READ, MAP_PRIVATE, STDOUT_FILENO, 0);
      memcpy(ptr, &quot;hello&quot;, 6);
  }
  </code></pre>
  <p>But this code failed:</p>
  <pre class="lang-sh prettyprint-override"><code>$ gcc mmap.c
  $ ./a.out
  Segmentation fault (core dumped)
  </code></pre>
  <p>And I have tested <code>mmap</code> on <code>STDIN</code>, it is ok.</p>
  <pre class="lang-c prettyprint-override"><code>int main()
  {
      // executed by `./a.out &lt; text.txt`
      void *ptr = mmap(NULL, 1024, PROT_WRITE | PROT_READ, MAP_PRIVATE, STDIN_FILENO, 0);
      write(STDOUT_FILENO, ptr, 1024); 
  }
  </code></pre>
  <p>Why <code>mmap</code> on <code>STDOUT</code> failed here? And what are the differences between <code>mmap</code> on <code>STDIN</code> and <code>STDOUT</code> ?</p>