Commit 72e46b3a1e3322f59a591f1da1a63e362f4fc384
1 parent
d78d769b
add daemonize code from other project. (Might be integrated in a future class bu…
…t i am not sure right now
Showing
1 changed file
with
23 additions
and
0 deletions
src/daemonize.c
0 → 100644
1 | +#include <stdio.h> /* for printf() and fprintf() */ | |
2 | +#include <unistd.h> /* for getopt */ | |
3 | +#include <stdlib.h> | |
4 | + | |
5 | + | |
6 | +void daemonize(void) { | |
7 | + pid_t pid; | |
8 | + | |
9 | + if (0 > ((pid = fork()))) { | |
10 | + perror("deamoinze[fork]"); | |
11 | + exit(EXIT_FAILURE); | |
12 | + } else if (0 != pid) { | |
13 | + exit(EXIT_SUCCESS); | |
14 | + } | |
15 | + | |
16 | + /* make new child session leader */ | |
17 | + setsid(); | |
18 | + | |
19 | + /* connect all standard streams to /dev/null */ | |
20 | + freopen("/dev/null", "w", stderr); | |
21 | + freopen("/dev/null", "r", stdin); | |
22 | + freopen("/dev/null", "w", stdout); | |
23 | +} | ... | ... |
Please
register
or
login
to post a comment