日期:2014-05-16 浏览次数:20740 次
#include <stdio.h> #include <signal.h> #include <unistd.h> #include <fcntl.h> void sig_handler(int signo) { char data[100]; int len ; len = read(STDIN_FILENO,&data,100); data[len]=0; printf("This signal is : %d\n",signo); printf("%s\n",data); exit(0); } int main() { int oflags; signal(SIGINT,sig_handler); signal(SIGTERM,sig_handler); signal(SIGIO,sig_handler); fcntl(STDIN_FILENO,F_SETOWN,getpid()); printf("ID:%d\n",getpid()); oflags = fcntl(STDIN_FILENO,F_GETFL); fcntl(STDIN_FILENO,F_SETFL,oflags|FASYNC); while(1); }