Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Netscape is not a newsreader, and probably never shall be. -- Tom Christiansen


devel / comp.unix.programmer / Signal race between parent and child

SubjectAuthor
* Signal race between parent and childNoob
`- Re: Signal race between parent and childRainer Weikusat

1
Signal race between parent and child

<smguld$8ud$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16775&group=comp.unix.programmer#16775

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: root@127.0.0.1 (Noob)
Newsgroups: comp.unix.programmer
Subject: Signal race between parent and child
Date: Wed, 10 Nov 2021 18:14:21 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <smguld$8ud$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Nov 2021 17:14:21 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="df277037ca49bede1d6f850dea1ae11f";
logging-data="9165"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VeJTUXpX/yXTGOOKD5CYMwblbua8Aups="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:Ee6Fw2wOiAhcsevJsMdLQQsuBJo=
Content-Language: en-US
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: Noob - Wed, 10 Nov 2021 17:14 UTC

Hello everyone,

Suppose process A forks/execs process B, and immediately sends a signal
to process B.

int child_pid = fork();
if (child_pid == 0) // child
execv("/bin/progB", argv);
// parent
kill(child_pid, 64);

Assume the first thing progB does is to install a handler for signal 64.

It seems to me that there is a race:

If process B runs first after the fork, then all is well, B installs the handler,
then process A sends the signal, and everyone lives happily ever after.

However, if process A runs first after the fork, the OS delivers the signal
before process B enters main(), perhaps even before it execs. Process B then
terminates in agony.

Does this fall under the "don't do that!" rule?

Or perhaps program A is expected to set the signal mask for
progB before even calling fork()?
It's too late after fork() because A can't touch B's sigmask.

Regards.

Re: Signal race between parent and child

<87k0hf7utl.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16779&group=comp.unix.programmer#16779

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweikusat@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Signal race between parent and child
Date: Wed, 10 Nov 2021 18:02:30 +0000
Lines: 33
Message-ID: <87k0hf7utl.fsf@doppelsaurus.mobileactivedefense.com>
References: <smguld$8ud$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net A5CfnstTVljJI57C2diNtAYgeksd4il3N4dxVcHX21lJU+w2s=
Cancel-Lock: sha1:7MUzLNuIwqff3wGYJ5XpsRyTfQ4= sha1:9xrBRieoXiIJh124ZK7FDamdubE=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
 by: Rainer Weikusat - Wed, 10 Nov 2021 18:02 UTC

Noob <root@127.0.0.1> writes:
> Hello everyone,
>
> Suppose process A forks/execs process B, and immediately sends a signal
> to process B.
>
> int child_pid = fork();
> if (child_pid == 0) // child
> execv("/bin/progB", argv);
> // parent
> kill(child_pid, 64);
>
> Assume the first thing progB does is to install a handler for signal 64.
>
> It seems to me that there is a race:
>
> If process B runs first after the fork, then all is well, B installs the handler,
> then process A sends the signal, and everyone lives happily ever after.
>
> However, if process A runs first after the fork, the OS delivers the signal
> before process B enters main(), perhaps even before it execs. Process B then
> terminates in agony.
>
> Does this fall under the "don't do that!" rule?

Yes.

> Or perhaps program A is expected to set the signal mask for
> progB before even calling fork()?

That would be a sensible way to handle this: If b must handle the
signal, it must inherit a signal masks which blocks it to be able to
install its handler reliaby before getting hit with the signal.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor