signals related question

Hi all,

Just a little question relative to signals.
I know that if an application is in the sleep state, When a signal is catched, it will be processed by the handler. But what happens if it's processing something? Does the processing stops??
The following code should illustrate this case

void handleSignal(int signal){
while(my_object->getWorkingState==1)
sleep(1);
printf("anything");
}

int main(...){
....
signal(SIGUSR1,handleSignal);
while(1){
my_object->process();
sleep();
}
....
}

Thanks for the attention.
Best regards,

Ernesto

Not so, really :slight_smile:

take this example program

#include <stdio.h>
#include <signal.h>

void process(void);
void sigFunc(int);

void sigFunc(int sigNo) {
  printf("Received Signal: %d\n", sigNo);
  exit (1);
}

void process() {
  //Run it with printf uncommented and sleep commented
  //For the second time do the vice-versa

  //printf("What am I doing\n");
  sleep(1);
}

int main()
{
  signal(SIGUSR1, sigFunc);
  while (1) {
    process();
  }
  return 0;
}

If you do run the program in two different ways, where printf is active, therefore its processing
and in the second form where it is in sleep mode, thereby after executing the sleep call

in either of the case, whatever be the state of the program that is in memory when kernel delivers a signal to the process,
if the signal handler is registered with a function 'f' it would be executed else default action of the delivered signal would be executed.

If your question is what I think it is, if your proccess is within a system call or a library call, the signal can stop that call, and the call will return an error usually. Then you can check if the SIGALRM was set (or set through your own signal handler function) to decide what to do next.