Преглед изворни кода

ADD skeleton_daemon

master
MEUNIER Thibaud пре 5 година
родитељ
комит
ab7a7f608e
1 измењених фајлова са 50 додато и 0 уклоњено
  1. +50
    -0
      src/skeleton_daemon.c

+ 50
- 0
src/skeleton_daemon.c Прегледај датотеку

@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
static void skeleton_daemon()
{
pid_t pid;
/* Fork off the parent process */
pid = fork();
/* An error occurred */
if (pid < 0)
exit(EXIT_FAILURE);
/* Success: Let the parent terminate */
if (pid > 0)
exit(EXIT_SUCCESS);
/* On success: The child process becomes session leader */
if (setsid() < 0)
exit(EXIT_FAILURE);
/* Catch, ignore and handle signals */
//TODO: Implement a working signal handler */
signal(SIGCHLD, SIG_IGN);
signal(SIGHUP, SIG_IGN);
/* Fork off for the second time*/
pid = fork();
/* An error occurred */
if (pid < 0)
exit(EXIT_FAILURE);
/* Success: Let the parent terminate */
if (pid > 0)
exit(EXIT_SUCCESS);
/* Set new file permissions */
umask(0);
/* Open the log file */
openlog ("firstdaemon", LOG_PID, LOG_DAEMON);
}

Loading…
Откажи
Сачувај