title: Fork error?  How to fix?
body: <p>What is the problem with this code? How to solve it? Parent processes goto in if or child process?</p>
  
  <p>first code produce zombie process or second code or both or non ?</p>
  
  <pre><code>#include &lt;signal.h&gt;
  #include &lt;sys/wait.h&gt;
  main() {
    for (;;) {
      if (!fork()) {
        exit(0);
      }
      sleep(1);
    }
  }
  </code></pre>
  
  <p>what about this code : </p>
  
  <pre><code>#include &lt;signal.h&gt;
  #include &lt;sys/wait.h&gt;
  main() {
    for (;;) {
      if (fork()) {
        exit(0);
      }
      sleep(1);
    }
  }
  </code></pre>