From: caspard AT sci DOT kun DOT nl (Caspar Derksen) Newsgroups: comp.os.msdos.djgpp Subject: signal() and alarm() - Bug? Date: 11 Mar 1997 18:35:13 +0100 Organization: University of Nijmegen, The Netherlands Message-ID: <5g454h$lh0@hera.cs.kun.nl> NNTP-Posting-Host: hera.cs.kun.nl Lines: 60 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Hello, I have the following problem: I want to perform some possibly expensive computation that I want to abort if no result is found in time. I have implemented this under Unix using alarm(). If some time limit is exceeded, an alarm signal is raised that is handled by some procedure restoring the previous state of the program. With DJGPP, alarm() or signal() does not seem to work, although the FAQ suggests that signals and alarm should work. I am using v2 under Win95-DOS. Would v2.01 solve my problem? Does anyone known another solution? Thanks for reading, Caspar Derksen Example: under Unix this program prints "sigalrm!!\n" after one second. Under DJGPP, nothing happens.... Why not? -----------------------------&<---------------------- #include #include #include static jmp_buf env; static void sigalrm(int sig) { longjmp(env,sig); } static void install_alarm_handler(void) { if (signal(SIGALRM, sigalrm) == SIG_ERR) { fprintf(stderr, "Cannot install timer\n"); exit(1); }; } static unsigned set_alarm(time) unsigned time; { return alarm(time); } int main(int argc, char *argv[]) { if (setjmp(env) != 0) { printf("sigalrm!!\n"); exit(0); }; install_alarm_handler(); set_alarm(1); while (1) { /* loop */ }; }