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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -