main() { int sig_int();/* my signal handling function */ ... signal(SIGINT, sig_int);/* establish handler */ ... while(sig_int_flag == 0) /*在这里有可能执行sig_int(),从而导致永远睡眠*/ pause();/* go to sleep, waiting for signal */ ... }
sig_int() { signal(SIGINT, sig_int);/* reestablish handler for next time */ sig_int_flag = 1;/* set flag for main loop to examine */ }