Learn R Programming

bfork (version 0.1.2)

fork: Fork a new process

Description

Create a new process given a function.

Usage

fork(fn)

Arguments

fn
a function that takes no arguments and returns no arguments that will be run in a new process

See Also

wait. waitpid.

Examples

Run this code
    ## create a function to be run as a separate process
    fn <- function() {
        Sys.sleep(4)
        print("World!")
    }

    ## fork the process
    pid <- fork(fn)

    ## do work in the parent process
    print("Hello")

    ## wait for the child process
    waitpid(pid)

Run the code above in your browser using DataLab