James Vanns
2006-03-08 16:27:57 UTC
All,
I shall try and briefly detail my ramblings in the subject...
I'm designing an application that will use threads, processes, signals
and execves - hopefully not in a mess either!? What I would like you to
do is comment on whether you see any problems with this theory:
Upon execution of the main process (e.g. via main()), before any new
processes or threads are executed I block all (possible) signals. After
this I create a new thread that will handle SIGHUP, SIGTERM and SIGINT
for the rest of the application (I don't want the other threads to
receive these signals).
After this an arbitrary number of threads will be executed... each one
of these threads will fork(). The child of thread n will restore the
old sigset_t (using pthread_sigmask ()) saved from main() and then
immediately execve() an external program. The reason for the restore of
the old (e,g, unblocked, default) sigset is so that the exec'd program
can be terminated, hup'd etc. as normal. Is this necessary? Or will the
exec set a new, default signal mask when the process image is
overwritten?
The parent of thread n will unblock SIGCHLD (again, using
pthread_sigmask ()) so it can receive the signal sent by the child
(upon exit) - I want to use waitpid to wait for this event (only in
this thread). When the parent recieves the return code of the child the
thread itself exits.
I've knocked up some relatively crude yet (I hope) accurate code and it
seems to work OK but are there any traps I should be aware of when
going about designing an app in this specific way?
Comments appreciated.
Regards,
Jim
I shall try and briefly detail my ramblings in the subject...
I'm designing an application that will use threads, processes, signals
and execves - hopefully not in a mess either!? What I would like you to
do is comment on whether you see any problems with this theory:
Upon execution of the main process (e.g. via main()), before any new
processes or threads are executed I block all (possible) signals. After
this I create a new thread that will handle SIGHUP, SIGTERM and SIGINT
for the rest of the application (I don't want the other threads to
receive these signals).
After this an arbitrary number of threads will be executed... each one
of these threads will fork(). The child of thread n will restore the
old sigset_t (using pthread_sigmask ()) saved from main() and then
immediately execve() an external program. The reason for the restore of
the old (e,g, unblocked, default) sigset is so that the exec'd program
can be terminated, hup'd etc. as normal. Is this necessary? Or will the
exec set a new, default signal mask when the process image is
overwritten?
The parent of thread n will unblock SIGCHLD (again, using
pthread_sigmask ()) so it can receive the signal sent by the child
(upon exit) - I want to use waitpid to wait for this event (only in
this thread). When the parent recieves the return code of the child the
thread itself exits.
I've knocked up some relatively crude yet (I hope) accurate code and it
seems to work OK but are there any traps I should be aware of when
going about designing an app in this specific way?
Comments appreciated.
Regards,
Jim