Description Usage Arguments Details Value Warning Note Author(s) See Also Examples
fork
creates a new child process as a copy of the current R process
exit
closes the current child process, informing the master process as necessary
1 2 |
exit.code |
process exit code. Currently it is not used by multicore, but other applciations might. By convention 0 signifies clean exit, 1 an error. |
send |
if not |
The fork
function provides an interface to the fork
system call. In addition it sets up a pipe between the master and
child process that can be used to send data from the child process
to the master (see sendMaster
) and child's stdin is
re-mapped to another pipe held by the master process (see
link{sendChildStdin}
).
If you are not familiar with the fork
system call, do not
use this function since it leads to very complex inter-process
interactions among the R processes involved.
In a nutshell fork
spawns a copy (child) of the current
process, that can work in parallel to the master (parent)
process. At the point of forking both processes share exactly the
same state including the workspace, global options, loaded packages
etc. Forking is relatively cheap in modern operating systems and no
real copy of the used memory is created, instead both processes
share the same memory and only modified parts are copied. This makes
fork
an ideal tool for parallel processing since there is no
need to setup the parallel working environment, data and code is
shared automatically from the start.
It is strongly discouraged to use fork
in GUI or
embedded environments, because it leads to several processes sharing
the same GUI which will likely cause chaos (and possibly
crashes). Child processes should never use on-screen graphics
devices.
fork
returns an object of the class childProcess
(to
the master) and masterProcess
(to the child).
exit
never returns
This is a very low-level API for expert use only. If you are
interested in user-level parallel execution use
mclapply
, parallel
and friends instead.
Windows opearting system lacks the fork
system call so it
cannot be used with multicore.
Simon Urbanek
1 2 3 4 5 6 7 | p <- fork()
if (inherits(p, "masterProcess")) {
cat("I'm a child! ", Sys.getpid(), "\n")
exit(,"I was a child")
}
cat("I'm the master\n")
unserialize(readChildren(1.5))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.