-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.c
More file actions
40 lines (35 loc) · 707 Bytes
/
util.c
File metadata and controls
40 lines (35 loc) · 707 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
/*
Begin-Doc
Name: util.c
Description: utility/helper routines
End-Doc
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include "debug.h"
/*
Begin-Doc
Name: BeDaemon
Description: daemonize process
Syntax: BeDaemon(progname)
Returns: process id
End-Doc
*/
int BeDaemon(char *pgm)
{
int childpid;
int curpid;
Debug(("%s: %s\n", pgm, "forking into background"));
if ((childpid = fork()) < 0) {
Error(("%s: %s\n", pgm, "initial fork error"));
exit(1);
} else if (childpid != 0) {
exit(0);
}
curpid = getpid();
Debug(("%s: %s (%d)\n", pgm, "background process id", curpid));
return curpid;
}