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.
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.
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.