wait {fork}R Documentation

Wait for child process(es) to stop or terminate.

Description

Wait for child process(es) created using 'fork' command to stop or terminate.

Usage

wait(pid, nohang=FALSE, untraced=FALSE)

Arguments

pid integer indicating the set of child processes for which status is requested. If missing or NULL, wait for all child processes.
nohang Use the WNOHANG flag.
untraced Use the WUNTRACED flag.

Details

This function provides a thin wrapper around the Unix "wait" and "waitpid" system calls. If pid is missing or NULL call, "wait" is called, otherwise "waitpid" is called.

Refer to the local Unix man pages for details on these system calls and the meanings of the various flags.

Value

A vector of length 2 containing

pid Process id of a child process
status Status of the child process.


Refer to the local Unix man pages for details on these system calls and the meanings of the status indicator.

Author(s)

Gregory R. Warnes warnes@bst.rochester.edu

References

"wait" and "waitpid" man pages

See Also

fork, exit, getpid, kill, killall

Examples

waittest <- function()
{ 
  pid = fork(NULL)
  if(pid==0)
    {
      cat("Hi, I'm the child process and I need to explicitly call exit().")
      cat("\n\n")
      exit()
    }
  else
    {
      wait(pid)
      cat("Hi, I'm the main process, and I wait()ed until the child process\n")
      cat("finished before introducing myself.\n")
    }
}

waittest()

[Package fork version 1.2.1 Index]