[Rd] Detecting whether a process exists or not by its PID?

Gábor Csárdi c@@rdi@g@bor @ending from gm@il@com
Fri Aug 31 15:48:44 CEST 2018


On Fri, Aug 31, 2018 at 3:35 PM Tomas Kalibera <tomas.kalibera using gmail.com> wrote:
>
> On 08/31/2018 03:13 PM, Gábor Csárdi wrote:
> > On Fri, Aug 31, 2018 at 2:51 PM Tomas Kalibera <tomas.kalibera using gmail.com> wrote:
> > [...]
> >> kill(sig=0) is specified by POSIX but indeed as you say there is a race
> >> condition due to PID-reuse.  In principle, detecting that a worker
> >> process is still alive cannot be done correctly outside base R.
> > I am not sure why you think so.
> To avoid the race with PID re-use one needs access to signal handling,
> to blocking signals, to handling sigchld. system/system2 and
> mcparallel/mccollect in base R use these features and the interaction is
> still safe given the specific use in system/system2 and
> mcparallel/mccollect, yet would have to be re-visited if either of the
> two uses change. These features cannot be safely used outside of base R
> in contributed packages.

Yes, _in theory_ this is right, and of course this only works for
child processes.

_In practice_, you do not need signal handling. The startup time stamp
method is
completely fine, because it is practically impossible to have two
processes with the
same pid and the same (high precision) startup time. This method also
works for any
process (not just child processes), so for PSOCK clusters as well.

Gabor

[...]



More information about the R-devel mailing list