Re: exception handling around a signal handler
- From: Ulrich Eckhardt <doomster@xxxxxxxx>
- Date: Mon, 27 Aug 2007 19:33:01 +0200
Brilte wrote:
I have some main code that performs work on an object. The object
(technically a struct), represents a child process. Currently i have a
bug within the child process that is causing it to segfault, but thats
not part of my question.
My question really is that when the child segfaults, the parent
receives a sigchld signal. This interrupts the main code which is
working with the child process and moves the object representing the
child process from one linked list into another and i lose the pointer
to the link within the main program causing it to segfault when it
tries to use a NULL pointer.
This can't work. The problem is that signal handlers are executed in the
context of a thread that is simply interrupted wherever it was. It could be
in the middle of an action that is otherwise (as far as e.g. threads are
concerned) atomic but the handler will be called nonetheless.
Now, there are basically two things you could do:
1. Use a flag.
The flag would be of type sigatomic_t (or somesuch) and you would need to
check it in the 'main' loop communicating with the child process.
2. Use a dedicated thread to wait for signals.
The used function is sigtimedwait(). From there on, you can use whatever is
necessary to signal to the other thread that the child-process has died.
Under no circumstance can you pull the structure from under the main loop in
the signal handler, because you have no way to detect where it is currently
in the code.
Uli
.
- Follow-Ups:
- Re: exception handling around a signal handler
- From: Rainer Weikusat
- Re: exception handling around a signal handler
- From: Brilte
- Re: exception handling around a signal handler
- References:
- exception handling around a signal handler
- From: Brilte
- exception handling around a signal handler
- Prev by Date: Re: fwrite
- Next by Date: Re: exception handling around a signal handler
- Previous by thread: Re: exception handling around a signal handler
- Next by thread: Re: exception handling around a signal handler
- Index(es):
Relevant Pages
|
|