f



Is there a way to stop a child process inheriting signal handlers?

I have a forking server and I need child processes to call a different signal
handler than the parent for various signals. Now obviously I could reset them
immediately after fork() but there will always be that small window where the
child could get a signal and call the parent handler before signal() or
sigaction() is called, or alternatively I could set them before but of course 
that then messes up the parent signal handling for a small period which is 
equally unwanted.

So my question is , is there a way to stop the child processes inheriting 
signal handlers or even better is there a way to preset the signal handlers 
for any child processes yet to be created? There doesn't seem to be any 
appropriate sigaction() flags to allow this. My question is for Linux, but if 
there's a generic Unix solution so much the better.

Thanks for any help

-- 
Spud

0
spud
11/1/2016 2:29:08 PM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

2 Replies
489 Views

Similar Articles

[PageSpeed] 31

In article <nva8rk$1kuv$1@gioia.aioe.org>, spud@potato.field wrote:

> I have a forking server and I need child processes to call a different signal
> handler than the parent for various signals. Now obviously I could reset them
> immediately after fork() but there will always be that small window where the
> child could get a signal and call the parent handler before signal() or
> sigaction() is called, or alternatively I could set them before but of course 
> that then messes up the parent signal handling for a small period which is 
> equally unwanted.
> 
> So my question is , is there a way to stop the child processes inheriting 
> signal handlers or even better is there a way to preset the signal handlers 
> for any child processes yet to be created? There doesn't seem to be any 
> appropriate sigaction() flags to allow this. My question is for Linux, but if 
> there's a generic Unix solution so much the better.
> 
> Thanks for any help

Maybe something like this:

Block signals
Fork
In child, reset signal handlers
Unblock signals in both processes

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0
Barry
11/1/2016 2:46:54 PM
On Tue, 01 Nov 2016 10:46:54 -0400
Barry Margolin <barmar@alum.mit.edu> wrote:
>Maybe something like this:
>
>Block signals
>Fork
>In child, reset signal handlers
>Unblock signals in both processes

Thanks. I'd completely forgotten that you can block signals. Time to get
Stevens off the shelf for a refresher!

-- 
Spud


0
spud
11/1/2016 3:00:24 PM
Reply: