title: C: dup and close-on-exec
body: <p>In a (German) book about C programming (Linux-UNIX-Programmierung, by Jürgen Wolf) I have found a statement, which translated to English would be as following (sentences numbered by me):</p>
  
  <blockquote>
    <p>In some cases it can be necessary that you need to duplicate a file descriptor [1]. An example for this would be, if a parent process wants to exchange data with a child process and the child process is overlaid by a new process through the use of <code>exec*()</code> [2]. In such a case, without <code>dup() or dup2()</code>, the <em>close-on-exec</em> flag would be set [3]. When this flag is set, all file descriptors become invalid (since being overlaid by the new process) - that is, they are not present anymore [4]. The communication between the parent and child process would thus be stopped [5]. If on the other hand you duplicate the file descriptor with <code>dup() or dup2()</code>, then the <em>close-on-exec</em> flag is deleted, and the newly overlaid process can use this file descriptor to communicate [6]. </p>
  </blockquote>
  
  <p>I believe that the above paragraph contains several misleading statements or even errors.</p>
  
  <p>In sentence [3], I do not understand why without the use of <code>dup()</code> or <code>dup2()</code> the <em>close-on-exec</em> flag would be set?</p>