title: fork() system call and while loop ( part 2)
body: <p>Does anyone know why the <code>printf(&quot;Type q to quit&quot;)</code> line prints twice in the terminal when I run this code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main (int argc, char *argv[])
  {
      char run[2];
      run[0]='a';
      int pid=0;
      while (run[0]!= 'q')    
      {
          printf(&quot;Type q to quit \n&quot;);
          fgets (run, 2, stdin);
    
          pid=fork();
          //wait();
          if(pid==0) { break;}
      }
  }
  </code></pre>
  <p>I would like the child to break from the loop and the parent to continue looping (to create new children). If I call <code>wait()</code> the execution ends after the first iteration regardless of whether I enter <code>'q'</code> or not. Otherwise it works as expected but prints the <code>&quot;Type q to quit&quot;</code> line twice every time. Why does this happen?</p>