title: What happens when a tcp server binds and forks before doing an accept ? Which process would handle the client requests?
body: <p>In linux, I have written a standard tcp server(using internet sockets) with a small difference. This is the skeleton of the server</p>
  
  <pre><code>fd=socket(...);
  bind(...);
  listen(...);
  //now do a fork
  fork(); 
  //this will create two processes bound to the same server listening on the same port !!
  
  clientfd=accept(...);
  </code></pre>
  
  <p>What will happen when a client connects to the server on the listening port. Which process will accept the connection ?</p>
  
  <p>From the practical runs of the program, always the parent(the process which forked) was getting the client request. I want to know the theory behind this. Was it just accidental that the parent process was getting the request ?</p>
  
  <p>Now I killed the parent process. So there is only child process running. When a client tried to connect to the server on the same port number, the child(or the lone survivor) process got the connection. How is this behavior explained ?</p>