DetachPids.3
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
- '"
- '" Copyright (c) 1989-1993 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: DetachPids.3,v 1.3 2001/04/03 14:53:45 andreas_kupries Exp $
- '"
- .so man.macros
- .TH Tcl_DetachPids 3 "" Tcl "Tcl Library Procedures"
- .BS
- .SH NAME
- Tcl_DetachPids, Tcl_ReapDetachedProcs, Tcl_WaitPid - manage child processes in background
- .SH SYNOPSIS
- .nf
- fB#include <tcl.h>fR
- .sp
- fBTcl_DetachPidsfR(fInumPids, pidPtrfR)
- .sp
- fBTcl_ReapDetachedProcsfR()
- .sp
- Tcl_Pid
- fBTcl_WaitPidfR(fIpid, statPtr, optionsfR)
- .SH ARGUMENTS
- .AS int *statusPtr
- .AP int numPids in
- Number of process ids contained in the array pointed to by fIpidPtrfR.
- .AP int *pidPtr in
- Address of array containing fInumPidsfR process ids.
- .AP Tcl_Pid pid in
- The id of the process (pipe) to wait for.
- .AP int* statPtr out
- The result of waiting on a process (pipe). Either 0 or ECHILD.
- .AP int options
- The options controlling the wait. WNOHANG specifies not to wait when
- checking the process.
- .BE
- .SH DESCRIPTION
- .PP
- fBTcl_DetachPidsfR and fBTcl_ReapDetachedProcsfR provide a
- mechanism for managing subprocesses that are running in background.
- These procedures are needed because the parent of a process must
- eventually invoke the fBwaitpidfR kernel call (or one of a few other
- similar kernel calls) to wait for the child to exit. Until the
- parent waits for the child, the child's state cannot be completely
- reclaimed by the system. If a parent continually creates children
- and doesn't wait on them, the system's process table will eventually
- overflow, even if all the children have exited.
- .PP
- fBTcl_DetachPidsfR may be called to ask Tcl to take responsibility
- for one or more processes whose process ids are contained in the
- fIpidPtrfR array passed as argument. The caller presumably
- has started these processes running in background and doesn't
- want to have to deal with them again.
- .PP
- fBTcl_ReapDetachedProcsfR invokes the fBwaitpidfR kernel call
- on each of the background processes so that its state can be cleaned
- up if it has exited. If the process hasn't exited yet,
- fBTcl_ReapDetachedProcsfR doesn't wait for it to exit; it will check again
- the next time it is invoked.
- Tcl automatically calls fBTcl_ReapDetachedProcsfR each time the
- fBexecfR command is executed, so in most cases it isn't necessary
- for any code outside of Tcl to invoke fBTcl_ReapDetachedProcsfR.
- However, if you call fBTcl_DetachPidsfR in situations where the
- fBexecfR command may never get executed, you may wish to call
- fBTcl_ReapDetachedProcsfR from time to time so that background
- processes can be cleaned up.
- .PP
- fBTcl_WaitPidfR is a thin wrapper around the facilities provided by
- the operating system to wait on the end of a spawned process and to
- check a whether spawned process is still running. It is used by
- fBTcl_ReapDetachedProcsfR and the channel system to portably access
- the operating system.
- .SH KEYWORDS
- background, child, detach, process, wait