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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Henrik Bengtsson-5
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

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

Tomas Kalibera
Thanks for spotting this, fixed in R-devel (including the Windows version).
Tomas


On 03/18/2018 09:53 PM, Henrik Bengtsson wrote:

> 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel