[Mono-list] Question on unix signal handling

Robert Jordan robertj at gmx.net
Thu Jan 17 16:36:34 UTC 2013


On 17.01.2013 17:02, mickeyf wrote:
> So my questions are:
>
> If I have a Mono application with an arbitrary number of threads, can I use
> this approach to make sure that any signal is properly caught and handled by
> a single method? That is, will any signals that are raised be seen only by
> my signal handler, and ignored by everything else?

Yes, but only if you implement these handlers as documented
(using an own thread and UnixSignal.WaitAny).

> If my Mono app is using unmanaged libraries, I presumably have to ensure
> that the library code also either ignores any signals or handles them in a
> sensible way. (Using signal(2), or SIGACTION(2) ?)

You don't have to ensure anything, unless your unmanaged libraries
are already using signal handlers. As long as these handlers
don't call back into the managed world, you should be safe.

> What I'm ultimately aiming at is that I can
>
> a) make sure that I can shut down my application cleanly and completely by
> sending it a signal (ctrl-C from the keyboard for example), and that
>
> b) it does not get tripped up by signals that may originate from other
> processes other than a system shut down, an intentional "kill", etc.

You can't (easily) detect where a signal is coming from. You should
assume that the kernel is smart enough in dispatching signals to your
process. E.g. it won't let a signal reach your process if the sender
doesn't have enough privileges etc.

Robert




More information about the Mono-list mailing list