So I\'m trying to call an alarm to display a message \"still working..\" every second. I included signal.h.
Outside of my main I have my function: (I never declare/d
ooga is correct that you keep reloading the alarm so that it will never go off. This works. I just put a sleep
in here so you don't keep stepping on yourself in the loop but you might want to substitute something more useful depending on where you are headed with this.
void display_message(int s)
{
printf("copyit: Still working...\n" );
// alarm(1); //for every second
// signal(SIGALRM, display_message);
}
int main(int argc, char *argv[])
{
int ret;
while(1)
{
signal(SIGALRM, display_message);
alarm(1);
if ((ret = sleep(3)) != 0)
{
printf("sleep was interrupted by SIGALRM\n");
}
}
return (0);
}