#include
#include
void ALARMhandler(int sig)
{
signal(SIGALRM, SIG_IGN); /* ignore this signal */
printf(\"H
You're not setting the handler in your main function.
Before you do alarm(2), put the signal(SIGALRM, ALARMhandler); in your main.
It should work then.
Note that your "All Done" will never be printed, because you'll stay in the while(1) loop after the signal processor has run. If you want the loop to be broken, you'll need to have a flag that the signal handler changes.
#include
#include
#include
/* number of times the handle will run: */
volatile int breakflag = 3;
void handle(int sig) {
printf("Hello\n");
--breakflag;
alarm(1);
}
int main() {
signal(SIGALRM, handle);
alarm(1);
while(breakflag) { sleep(1); }
printf("done\n");
return 0;
}