children
Low-level Functions for Management of Forked Processes
Description
These are low-level support functions for the forking approach.
They are not available on Windows, and not exported from the namespace.
Usage
children(select) readChild(child) readChildren(timeout = 0) selectChildren(children = NULL, timeout = 0) sendChildStdin(child, what) sendMaster(what, raw.asis = TRUE) mckill(process, signal = 2L)
Arguments
select | if omitted, all active children are returned, otherwise |
child | child process (object of the class |
timeout | timeout (in seconds, fractions supported) to wait for a response before giving up. |
children | list of child processes or a single child process object or a vector of process IDs or |
what | For For |
raw.asis | logical, if |
process | process (object of the class |
signal | integer: signal to send. Values of 2 (SIGINT), 9 (SIGKILL) and 15 (SIGTERM) are pretty much portable, but for maximal portability use |
Details
children
returns currently active children.
readChild
reads data (sent by sendMaster
) from a given child process.
selectChildren
checks children for available data.
readChildren
checks all children for available data and reads from the first child that has available data.
sendChildStdin
sends a string (or data) to one or more child's standard input. Note that if the master session was interactive, it will also be echoed on the standard output of the master process (unless disabled). The function is vector-compatible, so you can specify child
as a list or a vector of process IDs.
sendMaster
sends data from the child to the master process.
mckill
sends a signal to a child process: it is equivalent to pskill
in package tools.
Value
children
returns a (possibly empty) list of objects of class "process"
, the process ID.
readChild
and readChildren
return a raw vector with a "pid"
attribute if data were available, an integer vector of length one with the process ID if a child terminated or NULL
if the child no longer exists (no children at all for readChildren
).
selectChildren
returns TRUE
is the timeout was reached, FALSE
if an error occurred (e.g., if the master process was interrupted) or an integer vector of process IDs with children that have data available, or NULL
if there are no children.
sendChildStdin
returns a vector of TRUE
values (one for each member of child
) or throws an error.
sendMaster
returns TRUE
or throws an error.
mckill
returns TRUE
.
Warning
This is a very low-level interface for expert use only: it not regarded as part of the R API and subject to change without notice.
sendMaster
, readChild
and sendChildStdin
did not support long vectors prior to R 3.4.0 and so were limited to 2^31 - 1 bytes (and still are on 32-bit platforms).
Author(s)
Simon Urbanek and R Core.
Derived from the multicore package formerly on CRAN.
See Also
mcfork
, sendMaster
, mcparallel
Examples
## Not run: p <- mcparallel(scan(n = 1, quiet = TRUE)) sendChildStdin(p, "17.4\n") mccollect(p)[[1]] ## End(Not run)
Copyright (©) 1999–2012 R Foundation for Statistical Computing.
Licensed under the GNU General Public License.