ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.