mcchildren {parallel}R Documentation

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)

mckill(process, signal = 2L)

Arguments

select

if omitted, all active children are returned, otherwise select should be a list of processes and only those from the list that are active will be returned.

child

child process (object of the class "childProcess") or a process ID (pid). See also ‘Details’.

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 NULL. If NULL behaves as if all currently known children were supplied.

what

For sendChildStdin:
Character or raw vector. In the former case elements are collapsed using the newline character. (But no trailing newline is added at the end!)

For sendMaster:
Data to send to the master process. If what is not a raw vector, it will be serialized into a raw vector. Do NOT send an empty raw vector – that is reserved for internal use.

process

process (object of the class process) or a process ID (pid)

signal

integer: signal to send. Values of 2 (SIGINT), 9 (SIGKILL) and 15 (SIGTERM) are pretty much portable, but for maximal portability use tools::SIGTERM and so on.

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)

[Package parallel version 3.5.0 Index]