Daemonise.c

From Organic Design wiki
Revision as of 23:30, 21 July 2006 by Nad (talk | contribs) (make nice ps name)

// Convert running program into a system daemon strcpy(*argv, sprintf(*argv,"%s (peerd:%s)",peer,port)); pid_t pid = fork(); if (pid > 0) exit(EXIT_SUCCESS); if (pid < 0) exit(logErr("First fork() failed!")); if (setsid() < 0) exit(logErr("setsid() failed!")); pid = fork(); if (pid > 0) exit(EXIT_SUCCESS); if (pid < 0) exit(logErr("Second fork() failed!")); chdir("/"); umask(0); //close(STDIN_FILENO); //close(STDOUT_FILENO); //close(STDERR_FILENO);