[LCP] Terminating signals to handle
Jean-Daniel Pauget
jd at disjunkt.com
Wed Jan 14 20:16:45 EST 2009
On Tue, Jan 13, 2009 at 09:32:06PM -0900, Christopher Howard wrote:
> I'm writing an ncurses app in C (my first C app, actually). The terminal
> mode is set to raw, so the app shouldn't reason the SIGINT signal (well, I
> guess not anyway...) But a friend of mine looked at the code and told me I
> should have a function that handles terminating signals, to make sure that
> the terminal is returned to a normal state if someone kills the program
> externally.
>
> Here are my questions: Which signals should I bother handling? I see in
> the signal(7) man page here that there are something like twenty signals
> that can be received. SIGHUP, SIGKILL, SIGTERM, and SIGSTOP seem relevant
> for the aforementioned purpose...
>
> Secondly: Can the signal function in signal.h be used to direct more than
> one kind of signal to the same function? (Rather than a separate function
> for each signal?)
sur you can. the main idea (my humble opinion) is to process the
less you can in the function signal handler. most things are
"dangerous" in that function because it can be called anywhen during
your code. so evreything that is started from the handler must be
thread safe, re-entrant etc.
personally I simply turn on or off some flags, protected with a
semaphore or something alike, and leave the main job to the regular
code for when it check those flags, say, at the next select
loop ...
--
Jean-Daniel Pauget
Tél: +33 (0)9 61 57 94 29 / +33 (0)2 99 73 81 89
la basse garenne
35270 Meillac
France
More information about the linuxCprogramming
mailing list