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

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

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

Usage

1
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 greg@warnes.net

References

"wait" and "waitpid" man pages

See Also

fork, exit, getpid, kill, killall

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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()

warnes/fork documentation built on May 4, 2019, 12:59 a.m.