From henrik.bengtsson at gmail.com  Sun Mar 18 21:53:20 2018
From: henrik.bengtsson at gmail.com (Henrik Bengtsson)
Date: Sun, 18 Mar 2018 13:53:20 -0700
Subject: [Rd] BUG: tools::pskill() returns incorrect values or non-initated
 garbage values [PATCH]
Message-ID: <CAFDcVCSwdcMOMcUknbBPjLyhzAZ9mG4TT2m0Bh25rG9RkZyx8w@mail.gmail.com>

For the record, I've just filed the following bug report with a patch
to https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17395:

tools::pskill() returns either random garbage or incorrect values,
because the internal ps_kill() (a) it does not initiate the returned
logical, and (b) it assigns the logical returned the 0/-1 value of C's
kill().

# Example 1: returns garbage due to non-initiated allocation

> as.integer(tools::pskill(0))
[1] 44764824
> as.integer(tools::pskill(0))
[1] 41609736
> as.integer(tools::pskill(0))
[1] 45003984


# Example 2: returns 0 in success and -1 on failure

> p <- parallel::mcparallel({ Sys.sleep(3600); 42L })
> res <- tools::pskill(pid = p$pid, signal = tools::SIGKILL)
> as.integer(res)
[1] 0

> p <- parallel::mcparallel({ Sys.sleep(3600); 42L })
> res <- tools::pskill(pid = p$pid, signal = -1) ## invalid signal
> as.integer(res)
[1] -1

/Henrik



[Rd] BUG: tools::pskill() returns incorrect values or non-initated garbage values [PATCH]
Henrik Bengtsson