LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   signal SIGINT handler SOMETIMES doesn't exit (http://www.linuxquestions.org/questions/programming-9/signal-sigint-handler-sometimes-doesnt-exit-644733/)

Peterius 05-25-2008 09:36 PM

signal SIGINT handler SOMETIMES doesn't exit
 
I'm using signal to specify a signal handler which calls a separate function cleanup_and_exit which calls exit()...

Its worked perfectly for the most part except for a few weird things about when I hit control-C.

But lately, it seems like it never works. About 30% of the time, I hit control-c, it says "catching interrupt signal" and then it just sits there... I check "ps" and the process is still running like fine and I have to kill it. I don't get it...

I considered maybe I'm not really supposed to call exit() from a sigint handler... but I don't think that's it... I'm not sure what this is. Has anyone experienced anything like this?

konsolebox 05-25-2008 09:54 PM

Perhaps you can create a global quit flag which the catching function can set and when the main loop of the program finds that it is set, it will exit.

Code:

bool quit = FALSE;

while (quit != TRUE) {
  ...
  sleep(X); // when a signal is caught, sleep should stop (that's what i think), catchquit will be executed and the loop will continue
}

catchquit() {
  quit = TRUE;
}

The problem is i really don't know how a catching function is implemented in text programs. Some might be implemented by summoning it in a new thread and/or some might be implemented with local copy of global variables. Just try anyway.

Peterius 05-25-2008 10:15 PM

I did consider that but I'd rather not.

Nevermind, I think the sigints were hitting some large memory remapping operation that called some kind of lock beforehand, as a result, my attempt to call free from the sigint handler deadlocked the program... pretty simple I guess.

Peterius 05-25-2008 11:55 PM

Nevermind.


All times are GMT -5. The time now is 05:05 AM.