linux下c的代码原型如下:
#define _GNU_SOURCE
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
static volatile int event_fd;
static void handler(int signum, siginfo_t *si, void *data){
event_fd = si->si_fd;
printf("info size:%d, data:%d/n", sizeof(siginfo_t), sizeof(data));
}
int main(int argc, char **argv){
struct sigaction action;
int fd;
action.sa_sigaction = handler;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO;
sigaction(SIGRTMIN+1, &action, NULL);
fd = open("test", O_RDONLY);
fcntl(fd, F_SETSIG, SIGRTMIN+1);
fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_MULTISHOT);
fd = open(".", O_RDONLY);
fcntl(fd, F_SETSIG, SIGRTMIN+1);
fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_MULTISHOT);
while(1){
pause();
printf("got event on fd=%d/n", event_fd);
}
}
我要使用python,可以使用嵌入式方式,如果不是嵌入式方式,将会有1个以上的进程出现。
//#define _GNU_SOURCE
#include "Python.h"
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
typedef void my_handler_t(int, int);
typedef my_handler_t * my_handler;
static void * current_handler;
static volatile int event_fd;
static void default_h
#define _GNU_SOURCE
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
static volatile int event_fd;
static void handler(int signum, siginfo_t *si, void *data){
event_fd = si->si_fd;
printf("info size:%d, data:%d/n", sizeof(siginfo_t), sizeof(data));
}
int main(int argc, char **argv){
struct sigaction action;
int fd;
action.sa_sigaction = handler;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO;
sigaction(SIGRTMIN+1, &action, NULL);
fd = open("test", O_RDONLY);
fcntl(fd, F_SETSIG, SIGRTMIN+1);
fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_MULTISHOT);
fd = open(".", O_RDONLY);
fcntl(fd, F_SETSIG, SIGRTMIN+1);
fcntl(fd, F_NOTIFY, DN_MODIFY | DN_CREATE | DN_MULTISHOT);
while(1){
pause();
printf("got event on fd=%d/n", event_fd);
}
}
我要使用python,可以使用嵌入式方式,如果不是嵌入式方式,将会有1个以上的进程出现。
//#define _GNU_SOURCE
#include "Python.h"
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
typedef void my_handler_t(int, int);
typedef my_handler_t * my_handler;
static void * current_handler;
static volatile int event_fd;
static void default_h