title: What happens when a thread forks?
body: <p>I know calling <code>fork() sys_call</code> from a thread is a bad idea. 
  However, what will happen if a thread creates a new process using <code>fork()</code>? </p>
  
  <p>The new process will be the child of the main thread that created the thread. I think.</p>
  
  <p>If its parent finishes first, the new process will be attached to init process.
  And its parent is main thread, not the thread that created it.</p>
  
  <p>Correct me if I am wrong.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;pthread.h&gt;
  
  int main () 
  {
       thread_t pid;
       pthread_create(&amp;(pid), NULL, &amp;(f),NULL);
       pthread_join(tid, NULL);
       return 0;
  }
  
  void* f()
  {
       int i;
       i = fork();
  
       if (i &lt; 0) {
           // handle error
       } else if (i == 0) // son process
       {
            // Do something;
       } else {
            // Do something;
       }
   }
  </code></pre>