Re: Catching system signals and exception handling
Re: Catching system signals and exception handling
- Subject: Re: Catching system signals and exception handling
- From: Aaron Burghardt <email@hidden>
- Date: Thu, 21 Jul 2005 15:09:26 -0400
Thanks, guys, this helps a lot. I have searched for EXC_BAD_ADDRESS
and read quite a bit, but I guess I was looking at the wrong topic.
Most discussion is about trying to fix the bug that caused the error.
Searching for signal handling returned more relevant material.
Frankly, though, I'm of the opinion that this is a lot of work if the
only thing we hope to gain is to be able tell the user we are about
to crash. I hope I can convince the client of that, too.
Thanks again,
Aaron
On Jul 21, 2005, at 11:45 AM, Laurent Michel wrote:
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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