<HTML><HEAD><TITLE>Library Procedures - Tcl_DetachPids manual page</TITLE></HEAD><BODY> <H3><A NAME="M2">NAME</A></H3> Tcl_DetachPids, Tcl_ReapDetachedProcs - manage child processes in background <H3><A NAME="M3">SYNOPSIS</A></H3> <B>#include <tcl.h></B><BR> <B>Tcl_DetachPids</B>(<I>numPids, pidPtr</I>)<BR> <B>Tcl_ReapDetachedProcs</B>()<BR> <H3><A NAME="M4">ARGUMENTS</A></H3> <DL> <P><DT>int <B>numPids</B> (in)<DD> Number of process ids contained in the array pointed to by <I>pidPtr</I>. <P><DT>int <B>*pidPtr</B> (in)<DD> Address of array containing <I>numPids</I> process ids. <P></DL> <H3><A NAME="M5">DESCRIPTION</A></H3> <B>Tcl_DetachPids</B> and <B>Tcl_ReapDetachedProcs</B> 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 <B>waitpid</B> 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. <P> <B>Tcl_DetachPids</B> may be called to ask Tcl to take responsibility for one or more processes whose process ids are contained in the <I>pidPtr</I> 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. <P> <B>Tcl_ReapDetachedProcs</B> invokes the <B>waitpid</B> 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, <B>Tcl_ReapDetachedProcs</B> doesn't wait for it to exit; it will check again the next time it is invoked. Tcl automatically calls <B>Tcl_ReapDetachedProcs</B> each time the <B><A HREF="../TclCmd/exec.htm">exec</A></B> command is executed, so in most cases it isn't necessary for any code outside of Tcl to invoke <B>Tcl_ReapDetachedProcs</B>. However, if you call <B>Tcl_DetachPids</B> in situations where the <B><A HREF="../TclCmd/exec.htm">exec</A></B> command may never get executed, you may wish to call <B>Tcl_ReapDetachedProcs</B> from time to time so that background processes can be cleaned up. <H3><A NAME="M6">KEYWORDS</A></H3> <A href="../Keywords/B.htm#background">background</A>, <A href="../Keywords/C.htm#child">child</A>, <A href="../Keywords/D.htm#detach">detach</A>, <A href="../Keywords/P.htm#process">process</A>, <A href="../Keywords/W.htm#wait">wait</A> <HR><PRE> <A HREF="../copyright.htm">Copyright</A> © 1989-1993 The Regents of the University of California. <A HREF="../copyright.htm">Copyright</A> © 1994-1996 Sun Microsystems, Inc. <A HREF="../copyright.htm">Copyright</A> © 1995-1997 Roger E. Critchlow Jr.</PRE> </BODY></HTML>