LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2008, 09:36 PM   #1
Peterius
Member
 
Registered: May 2004
Distribution: Gentoo, Debian, OpenBSD, NetBSD
Posts: 158

Rep: Reputation: 16
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?
 
Old 05-25-2008, 09:54 PM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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.
 
Old 05-25-2008, 10:15 PM   #3
Peterius
Member
 
Registered: May 2004
Distribution: Gentoo, Debian, OpenBSD, NetBSD
Posts: 158

Original Poster
Rep: Reputation: 16
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.

Last edited by Peterius; 05-26-2008 at 12:20 AM.
 
Old 05-25-2008, 11:55 PM   #4
Peterius
Member
 
Registered: May 2004
Distribution: Gentoo, Debian, OpenBSD, NetBSD
Posts: 158

Original Poster
Rep: Reputation: 16
Nevermind.

Last edited by Peterius; 05-26-2008 at 12:19 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handler routine vdx Programming 7 09-24-2007 12:43 AM
sigint custom handler nc3b Programming 6 05-09-2007 08:39 AM
SIGINT handler with Fork() xface66 Programming 1 04-02-2007 12:15 PM
howto know whether a function is called in signal handler snowing Programming 1 11-07-2005 09:55 PM
Konqueror / KDE Crash Handler: Signal 11 Bob P Linux - Software 4 10-13-2004 04:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration