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.
You cannot block all signals, SIGKILL for example.
You have to invoke signal once for each separate signal.
Next, printf() may cause problems in your signal handler. Most of the standard library functions have problems because they can be interrupted by yet another signal. Try using write() instead.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
Here's a demonstration program that catches an interrupt signal; e.g., when a user tries to abort a program with CTRL-C or the delete key. By use setsig, sigsetjmp and siglongjmp the program cannot be killed by flooding it with interrupt signals (this is the sort of thing that you'd use to clean up files when an interrupt is received):
This isn't a bad template to use for building up what you're talking about; it appears in Chapter 6 of Kochan and Wood Topics in C Programming Revised Edition (ISBN 0-471-53404-8).
a quick scan of the header files (/usr/include/asm/signal.h & /usr/include/bits/signum.h) does not reveal a single macro that specifies all catch-able signals.
however, i suggest you write a loop that sets them all in just a couple lines of code. here's some psuedo code:
for ( i = 0; i < 32; i++ )
{
signal( i, sighandler );
}
don't know what the system will do if you try to set a signal handler for a signal that cannot be caught.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.