c - "Alarm clock" message on linux -
i'm working on project written in c , i'm using alarms. in beginning of code use sigaction() initialize alarm:
struct sigaction sa; sa.sa_handler = alarm_handler; sigaction(sigalrm, &sa, null);
then call alarm alarm() function in loop:
while(){ alarm(myseconds); }
the program sends first alarm , runs handler function, when sends second 1 message appears on output stream:
"alarm clock"
i don't know why keeps happening. thank you.
you leave variables of struct sigaction
uninitialized, need
struct sigaction sa; memset(&sa, 0, sizeof sa); sa.sa_handler = alarm_handler;
note alarm documentation says if calling alarm() again before current alarm has expired: " in event set alarm() canceled.". calling millions of times second in loop not idea, you're resetting alarm.
Comments
Post a Comment