cleanup zombies during run, and check processes still exist
[tridge/junkcode.git] / notify.c
1 #define DN_ACCESS       0x00000001      /* File accessed in directory */
2 #define DN_MODIFY       0x00000002      /* File modified in directory */
3 #define DN_CREATE       0x00000004      /* File created in directory */
4 #define DN_DELETE       0x00000008      /* File removed from directory */
5 #define DN_RENAME       0x00000010      /* File renamed in directory */
6 #define DN_ATTRIB       0x00000020      /* File changed attribute */
7 #define DN_MULTISHOT    0x80000000      /* Don't remove notifier */
8 #define F_NOTIFY 1026
9
10 #define _GNU_SOURCE     /* needed to get the defines */
11 #include <fcntl.h>      /* in glibc 2.2 this has the needed
12                                    values defined */
13 #include <signal.h>
14 #include <stdio.h>
15 #include <unistd.h>
16
17 static int event_fd;
18
19 static void handler(int sig, siginfo_t *si, void *data)
20 {
21         event_fd = si->si_fd;
22 }
23
24 int main(void)
25 {
26         struct sigaction act;
27         int fd;
28         
29         act.sa_sigaction = handler;
30         sigemptyset(&act.sa_mask);
31         act.sa_flags = SA_SIGINFO;
32         sigaction(SIGRTMIN, &act, NULL);
33         
34         fd = open(".", O_RDONLY);
35         fcntl(fd, F_SETSIG, SIGRTMIN);
36         fcntl(fd, F_NOTIFY, DN_MODIFY|DN_CREATE|DN_MULTISHOT);
37         /* we will now be notified if any of the files
38            in "dir" is modified or new files are
39            created */
40         while (1) {
41                 pause();
42                 printf("Got event on fd=%d\n", event_fd);
43         }
44
45         return 0;
46 }