1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils,pid.R
\name{pid_exists}
\alias{pid_exists}
\title{Check whether a process PID exists or not}
\usage{
pid_exists(pid, debug = getOption2("parallelly.debug", FALSE))
}
\arguments{
\item{pid}{A positive integer.}
}
\value{
Returns \code{TRUE} if a process with the given PID exists,
\code{FALSE} if a process with the given PID does not exists, and
\code{NA} if it is not possible to check PIDs on the current system.
}
\description{
Check whether a process PID exists or not
}
\details{
There is no single go-to function in \R for testing whether a PID exists
or not. Instead, this function tries to identify a working one among
multiple possible alternatives. A method is considered working if the
PID of the current process is successfully identified as being existing
such that \code{pid_exists(Sys.getpid())} is \code{TRUE}. If no working
approach is found, \code{pid_exists()} will always return \code{NA}
regardless of PID tested.
On Unix, including macOS, alternatives \code{tools::pskill(pid, signal = 0L)}
and \code{system2("ps", args = pid)} are used.
On MS Windows, various alternatives of \code{system2("tasklist", ...)} are used.
Note, some MS Windows machines are configures to not allow using
\code{tasklist} on other process IDs than the current one.
}
\references{
\enumerate{
\item The Open Group Base Specifications Issue 7, 2018 edition,
IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)
\url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html}
\item Microsoft, tasklist, 2021-03-03,
\url{https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/tasklist}
\item R-devel thread 'Detecting whether a process exists or not by its PID?',
2018-08-30.
\url{https://stat.ethz.ch/pipermail/r-devel/2018-August/076702.html}
}
}
\seealso{
\code{\link[tools]{pskill}()} and \code{\link[base]{system2}()}.
}
\keyword{internal}
|