title: Pre-fork model in C
body: <p>Additional to  <a href="https://stackoverflow.com/questions/16267378/dynamic-pool-of-process-c/16284972?noredirect=1#comment23335789_16284972">dynamic pool of process C</a></p>
  
  <p>Changed code:</p>
  
  <pre><code>   int main(int argc, char *argv[])
      {
      ...//settings
      listensock = socket(AF_INET, SOCK_STREAM,IPPROTO_TCP);
      result = bind(listensock, (struct sockaddr *) &amp;sAddr, sizeof(sAddr));
      result = listen(listensock, 1);
      ...//skip errors checking
  
      while(1){
              newsock = accept(listensock, NULL,NULL);
              pid=fork();
              if (pid == 0) {
                  send(newsock, buffer, nread, 0);
              }
              close(newsock);
      }
      wait(NULL);
  }
  </code></pre>
  
  <p>This creates childs only if someone try to connect. It is not pre-fork model. N processes should be run after server starts and wait for connects. If I try to invoke <code>fork()</code> 3 times in loop, it immediately terminate. How to start, wait until someone connect and then send data (like in  my code). </p>