The pseudo code could be:
Setup current process as a daemon (fork, setsid, fork etc.) Create a socket on a well known port while (true) Get a client connection if (fork()==0) Close parent's copy of client connection else In child, deal with client request exit child process endif endwhileYou will see essentially this solution used in the Tiny Daemon case study in the next tutorial.
main(int argc, char **argv) { Setup process as a daenon (fork, setsid, fork etc.) execvp(argv [1], &argv[1]); }