dear all: There is a demo for kqueue and signal, Under FreeBSD4.9, I can get the output of "got SIGCHLD by kqueue". But I can't get the same result under FreeBSD5.4. I'd appreciate that if anyone can let me know why this happend. Here is my code:
#include <unistd.h> #include <string.h> #include <sys/event.h> #include <stdio.h> #include <signal.h> #define DEBUG(x...) fprintf(stderr, x) int main() { int kq, res; struct kevent ke; kq = kqueue(); if ( kq < 0 ) { DEBUG("init kqueue failed %s : %d\n", __FILE__, __LINE__); return -1; } //when remove this code, everything is ok....what diffence with 4.9 and 5.4? if ( signal(SIGCHLD, SIG_IGN) == SIG_ERR ) { DEBUG("signal failed %s : %d\n", __FILE__, __LINE__); } EV_SET(&ke, SIGCHLD, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL); if ( kevent(kq, &ke, 1, NULL, 0, NULL) < 0 ) { DEBUG("kevent failed %s : %d\n", __FILE__, __LINE__); return -1; } EV_SET(&ke, 1, EVFILT_TIMER, EV_ADD, 0, 1000, NULL); if ( kevent(kq, &ke, 1, NULL, 0, NULL) < 0 ) { return -1; } while(1) { bzero(&ke, sizeof( struct kevent) ); res = kevent(kq, NULL, 0, &ke, 1, NULL); if ( res == 0 ) continue; if ( res < 0 ) { DEBUG("kevent failed %s : %d\n", __FILE__, __LINE__); return -1; } if (ke.ident == SIGCHLD ) { DEBUG("got SIGCHLD by kqueue\n"); } else if ( ke.ident == 1 && ke.filter == EVFILT_TIMER ) { DEBUG("time out\n"); res = fork(); if ( res < 0 ) { DEBUG("Fork Error\n"); return -1; } else if ( res == 0 ) { DEBUG("Child ...\n"); return 0; } else { DEBUG("Father ...\n"); } } } return 0; } _______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users