server 0.0.1
basicserverinfrastructure

src/daemonize.c File Reference

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
Include dependency graph for daemonize.c:

Go to the source code of this file.

Functions

void daemonize (void)

Function Documentation

void daemonize ( void  )

Definition at line 6 of file daemonize.c.

                     {
    pid_t pid;

    if (0 > ((pid = fork()))) {
        perror("deamoinze[fork]");
        exit(EXIT_FAILURE);
    } else if (0 != pid) {
        exit(EXIT_SUCCESS);
    }

    /* make new child session leader */
    setsid();

    /* connect all standard streams to /dev/null */
    stderr = freopen("/dev/null", "w", stderr);
    stdin  = freopen("/dev/null", "r", stdin);
    stdout = freopen("/dev/null", "w", stdout);
}
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines