Re: Catching system signals and exception handling
Re: Catching system signals and exception handling
- Subject: Re: Catching system signals and exception handling
- From: Laurent Michel <email@hidden>
- Date: Thu, 21 Jul 2005 11:45:39 -0400
On Jul 21, 2005, at 11:16 AM, j o a r wrote:
On 21 jul 2005, at 17.03, Aaron Burghardt wrote:
I'm trying to learn how handle system signals so I can catch
SIGBUS & SIGSEGV signals, report them, and possibly recover from
them. I've tried using the NSExceptionHandler from the
ExceptionHandling framework, but I can't get it to catch signals
and convert to exceptions, so I've moved on to installing my own
signal handler.
I would like to have my signal handler create and raise an
NSException. My test app will do it once, but subsequent signals
get caught in an infinite loop. Is there a way to do this? Do I
need to use setjmp/longjmp?
You're not allowed to use Cocoa from a signal handler. You're
basically not allowed to do anything in a signal handler. Read the
documentation, and the discussions on this topic that you can find
in the list archives.
j o a r
You should be using a signal monitoring thread. Have a separate
thread that uses sigwait (check with man) to wait for signals. Mask
the signals in the other threads to force delivery in the monitor.
The monitor thread will block waiting for signals to arrive. When a
signal arrives, it simply wakes up and returns from sigwait. Thus, it
is not being interrupted by a signal and it can use all the APIs you
can dream of (As noted above, in a 'normal' signal handler cocoa is
out of bound, but so is most of the API in the C library). All this
stuff is POSIX thread features, so check out the POSIX doc on how to
mask/block/wait for signals (pthread_sigmask springs to mind)
Finally, do not expect to recover from a sigbus / sigsegv. The best
you can do is terminate gracefully. But terminate you will.
Hope it helps.
--
Laurent
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40thorgal.homelinux.org
This email sent to email@hidden
--
Laurent
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden