-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdaemon.c
More file actions
41 lines (40 loc) · 781 Bytes
/
daemon.c
File metadata and controls
41 lines (40 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
/**
* @file
* @brief Tworzenie demona
*
* Plik posiadający funkcję która służy do tworzenia demona.
*/
/**@brief
* Funkcja tworząca demona- tworzony jest proces potomny, następnie zabijany proces "rodzic". "Osierocony" proces staje się demonem.
*/
void create_deamon()
{
pid_t pid, sid;
pid = fork();
if(pid<0)
{
exit(EXIT_FAILURE);
}
if(pid>0)
{
exit(EXIT_SUCCESS);
}
umask(0);
sid =setsid();
if(sid<0)
{
exit(EXIT_FAILURE);
}
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
}