c - alarm stop's when signal arrive -


i'm trying combine signal , alarm. have 2 processes. 1 receiving input user, , write pipe , sending signal (sigusr2) other process. in other process, have infinite loop produces alarm every second. program should handle both alarm signal's , sigusr2 signals. alarm handle work fine, when signal arrive , signal handler active seem don't return loop produce alarm's. read man page of alarm , signal's , didn't find anything. says signal handler function should return original code, doesn't. know why code don't return loop after signal handler, , how force alarm handler function every second if signal's received meanwhile.

this loop:

while (1) { signal (sigusr2 , signal_hand); signal (sigalrm , alarm_hand); alarm (1); pause(); } 

this signal handler function:

void signal_hand (int sig) { // reading pipe , doing things accordingly ... } 

and alarm handler function:

void alarm_hand (int sig) { // doing things ... } 

eevery time sigusr2 (or kind of signal @ all), repeat while loop, , resets alarm timer 1 second. means if sigusr2 signals come more once per second, alarm never goes off.

try making following changes:

  • move 2 signal() configure alarm handlers outside loop. there no need reset signal handlers every time through loop. once they're set, they're set.
  • don't call alarm(1) in loop after sigalrm might not have been received. instead, call alarm(1) once before start loop , again reset timer inside alarm_hand function.

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -