home *** CD-ROM | disk | FTP | other *** search
- 1 /*
- 2 * daemon.c ----- The background process that waits for events to happen
- 3 * and performs some task based on that event. Most
- 4 * of the time, a daemon's action goes usually unnoticed
- 5 * by users.
- 6 */
- 7
- 8 #include <sys/signal.h>
- 9 #include <fcntl.h>
- 10 #include <stdio.h>
- 11 #include "local.h"
- 12
- 13 /*
- 14 * This is not the most complete method of creating a Unix daemon.
- 15 * Please see the paper by Dave Lennert in the Usenix ;login: newsletter
- 16 * dated July/August 1987 called "How To Write a Unix Daemon".
- 17 */
- 18
- 19 main(argc,argv)
- 20 char **argv;
- 21 {
- 22 int fd;
- 23 PACKET test;
- 24
- 25 signal(SIGINT, SIG_IGN); /* Only kill self when client says so */
- 26
- 27
- 28 /* Now open the FIFO for reading */
- 29
- 30 if ( (fd = open(PIPE, O_RDONLY)) == -1 )
- 31 fprintf(stderr, "Cannot open PIPE\n"), exit(1);
- 32
- 33 while(1)
- 34 {
- 35 read(fd, &test, sizeof test); /* Read client via FIFO*/
- 36
- 37 if ( !strcmp(test.string, "Done") )
- 38 printf("Byebye from Daemon\n"), exit(1);
- 39
- 40 printf("PID: %d - string: [%s]\n", test.pid, test.string);
- 41 }
- 42 }
-