#define _GNU_SOURCE #include #include #include #include int event_fd; struct sigaction act; void handler(int sig, siginfo_t *si, void *data) { event_fd = si->si_fd; printf("handler called!\n"); exit(0); } int main(void) { int fd; act.sa_sigaction = handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_SIGINFO; sigaction(SIGRTMIN, &act, NULL); if ((fd = open("/tmp/mytest", O_RDONLY|O_CREAT,0777)) == -1) printf("Create file failed: %d, %s \n", errno, strerror(errno)); fcntl(fd, F_SETSIG, SIGRTMIN); if(fcntl(fd, F_SETLEASE, F_WRLCK) == -1) { printf("F_SETLEASE, F_WRLCK failed: %d, %s \n", errno, strerror(errno)); exit(1); } fd = open("/tmp/mytest", O_RDWR|O_CREAT,0777); while(1) sleep(1); }