0

I wish to know how does an Apache HTTP server program serves many clients connecting to it at the same port 80? I know about port and sockets. I did lot of search on internet about it but could not find an answer that explains it most simply. Many answers raises new questions, like this one:

Normally, for every connecting client the server forks a child process that communicates with the client (TCP). The parent server hands off to the child process an established socket that communicates back to the client. When you send the data to a socket from your child server, the TCP stack in the OS creates a packet going back to the client and sets the "from port" to 80. If a server uses only a single child-process to serve all the sockets then the server is called single-process/threaded and if the server uses many sub-processes to serve each socket by one sub-process then the server is called multi-process/threaded server. Note that irrespective of the server's type a server can/should always uses the same initial socket to respond back (no need to allocate another server-port).

Is Apache HTTP server multithreaded or a single threaded? My guess is that it is multithreaded.

In case of persistent connection, how does client computer contacts its child process again? is there a table or something maintained by parent process to map the client to its child process? or a new child process is created everytime? What is the life-cycle of a child process?

1

Apache is indeed multithreaded, as it spawns a new process for each new connection. As for the child processes lifetime, it's killed when the connection is aborted, either by a disconnect or timeout.

  • Suppose the connection is not aborted, how does the client's new request is directed to the old child process? How the mapping is done at the server? Is there any child process id? – KawaiKx Jan 10 '16 at 11:22
  • @KawaiKx that's something I'm unsure of. I would be guessing that Apache maps that IP to a certain child process ID – td512 Jan 10 '16 at 19:10
  • @KawaiKx The OS does that. The kernel keeps track of all local sockets, both listening and connected. // That being said, this answer oversimplifies things. There’s no way anyone would waste a whole process per connection. That would be an incredible overhead. – Daniel B Jan 10 '16 at 21:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.