fork                package:multicore                R Documentation

_F_o_r_k _a _c_o_p_y _o_f _t_h_e _c_u_r_r_e_n_t _R _p_r_o_c_e_s_s

_D_e_s_c_r_i_p_t_i_o_n:

     '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

_U_s_a_g_e:

     fork()
     exit(exit.code = 0L, send = NULL)

_A_r_g_u_m_e_n_t_s:

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 'NULL' send this data before exiting (equivalent to
          using 'sendMaster')

_D_e_t_a_i_l_s:

     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.

_V_a_l_u_e:

     'fork' returns an object of the class 'childProcess' (to the
     master) and 'masterProcess' (to the child).

     'exit' never returns

_W_a_r_n_i_n_g:

     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.

_N_o_t_e:

     Windows opearting system lacks the 'fork' system call so it cannot
     be used with multicore.

_A_u_t_h_o_r(_s):

     Simon Urbanek

_S_e_e _A_l_s_o:

     'parallel', 'sendMaster'

_E_x_a_m_p_l_e_s:

       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))

