title: Trying to find what is the max number of processes I can open
body: <p>I am a total beginner in C.
  I have this assginment to wirte a program that will find the max number of processes I can open.</p>
  
  <p>I come out with this code:</p>
  
  <pre><code>int main() {
  
  while (1){
      pid_t pid = fork();
      if(pid) {
          if ( pid == -1){
              fprintf(stderr,"Can't fork,error %d\n",errno);
              exit(EXIT_FAILURE);
          }else{
              int status;
              alarm(30);
              if(waitpid(pid, &amp;status, 0)==pid) {
                  alarm(0);
                  // the child process complete within 30 seconds
                  printf("Waiting.");
              }else {
                  alarm(0);
                  // the child process does not complete within 30 seconds
                  printf("killed");
                  kill(pid, SIGTERM);
              }
          }
      }
      else{
          alarm(30);
          printf("child");
      }
  }
  }
  </code></pre>
  
  <p>The thing is this program caused my laptop to crash..:-|</p>
  
  <p>I assumed that when the program will not be able to open more processes I will get -1 from the fork() and then will exit the program.
  Well, it didn't happened.</p>
  
  <p>Any idea?
  What am I missing here?</p>
  
  <p>Thanks!</p>