title: Is the file created by child after fork, also shared with parent?
body: <p>I know that after <code>fork()</code>, all files (and their offsets) opened by the <strong>parent</strong> are shared<br>
  by the <strong>child</strong>. That is, <strong>parent</strong> and <strong>child</strong> share the file table entry of all the files.  </p>
  
  <p>What happens if <strong>child</strong> opens some file. Is it specific to <strong>child</strong>? Or is it shared by <strong>parent</strong>?  </p>
  
  <p>I've also written small test program. Is this the right way to test this?  </p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  #define FLAG (O_RDWR | O_CREAT | O_TRUNC)
  
  int main(int argc, char *argv[])
  {
      pid_t pid;
  
      if ((pid = fork()) &lt; 0) {
          perror("fork error");
          exit(1);
      } else if (pid == 0) {
          int fc;
          if ((fc = open("abc", FLAG)) == -1) {
              perror("cannot open abc");
              exit(-1);
          }
          exit(fc);
          //returning the file descriptor open through exit()
      } else {
          int fp;
          wait(&amp;fp);
          if (fp == -1)
              exit(1);
          if (fcntl(fp, F_GETFD) == -1)
              perror("doesn't work");     //Ouputs: doesn't work: Bad file descriptor
          //returns file descriptor flags
          //should not return error, if fd is valid
      }
      return 0;
  }
  </code></pre>
  
  <p>Thanks.  </p>