Search code examples
ctheory

Is a server an infinite loop running as a background process?


Is a server essentially a background process running an infinite loop listening on a port? For example:

while(1){
   command = read(127.0.0.1:xxxx);
   if(command){
      execute(command);
   }
}

When I say server, I obviously am not referring to a physical server (computer). I am referring to a MySQL server, or Apache, etc.

Full disclosure - I haven't had time to poke through any source code. Actual code examples would be great!


Solution

  • That's more or less what server software generally does.

    Usually it gets more complicated because the infinite loop "only" accepts the connection and each connection can often handle multiple "commands" (or whatever they are called in the used protocol), but the basic idea is roughly this.