Re: Signal handlers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel Nilsson <daniel@xxxxxxxxxxxxxxx> writes:

> On Mon, Aug 09, 2004 at 02:53:49PM +0200, Michael Natterer wrote:
>> Daniel Nilsson <daniel@xxxxxxxxxxxxxxx> writes:
>> 
>> > I have a question on signal handlers, in a gtk application should I
>> > use the normal libc functions for handling signals such as SIGINT or
>> > do I need to take anything else in consideration.
>> >
>> > I.e. can I just call this in main() before gtk_main to install a
>> > signal handler for SIGINT that will go off and clear up some hardware
>> > registers before the application terminates;
>> >
>> >  signal(SIGINT, termination_handler);
>> 
>> That will work, however you should never ever (!) use signal().
>> use sigaction() instead if you want reliable signal handling.
>
> Thanks, are you saying that even if the only thing I want to do is 
> reset a few registers before the application exits I should use 
> sigaction ? What problems could signal give me ? The reason for
> asking is that I have an implementation already with signal which
> seems to work fine, what kind of testing should I do that could
> trigger a problem ?

In the case of cleaning up on SIGINT (the handler is guarenteed
to run just once and the program doesn't continue after the handler)
it's perfectly fine to use signal(). The problem with signal() is
that it's one-shot and there is a small time gap in between
invoking the handler and re-installing it where you can lose
signals. Also, sigaction() behaves sane WRT to interrupted
system calls.

But as said, these are non-issues with your cleanup SIGINT handler,
so you can safely ignore me :)

ciao,
--mitch
_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux