-
Notifications
You must be signed in to change notification settings - Fork 0
/
main1_3.c
37 lines (35 loc) · 882 Bytes
/
main1_3.c
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
int main()
{
pid_t pid = fork();
if (pid == 0)
{
// we are in child
// move to root dir used to not block fie system
chdir("/");
//move the child to another session so the parent may be close
setsid();
printf("startion my daemon\n");
// close output channels
close(stdout);
close(stdin);
close(stderr);
// open log
openlog("myDaemon", LOG_PID, LOG_DAEMON);
syslog(LOG_NOTICE, "Deamon started 4");
usleep(3000000);
syslog(LOG_NOTICE, "Doing some work ..... 4");
usleep(3000000);
syslog(LOG_NOTICE, "Deamon Finished 4");
}
else
{
printf("DAEMON PID %d\n", pid);
}
return 0;
}
// search it using
// grep myDaemon /var/log/syslog