Demonizing the Server

A server, to be a real server shall be able to run as a demon, it shall run in background and it shall not be linked to a terminal. To do this I'll add two functions to the simple server:

  1. demonize
  2. detachFromTerminal

The first function sets up the process to ignore child, quit, and hup signals, and then it uses a fork() to duplicate the process. The father process will be terminated as soon as possible while the child process will execute a detachFromTerminal and then it will continue its esecution.

The detachFromTerminal function sets the calling process as the leader of a new session, the it associates the streams linked to stdin, stdout and stderr with the /dev/null device.

ignore the SIGHUP, SIGCHLD and the SIGQUIT signal

(void) signal(SIGHUP, SIG_IGN);

Create a new process to use as daemon

The new process will be detached from the terminal

The father process will quit suddenly


Network programming index:

The Server

The Client

Demonizing the Server

The source code