1Tcl_DetachPids(3) Tcl Library Procedures Tcl_DetachPids(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_DetachPids, Tcl_ReapDetachedProcs, Tcl_WaitPid - manage child pro‐
9 cesses in background
10
12 #include <tcl.h>
13
14 Tcl_DetachPids(numPids, pidPtr)
15
16 Tcl_ReapDetachedProcs()
17
18 Tcl_Pid
19 Tcl_WaitPid(pid, statusPtr, options)
20
22 int numPids (in) Number of process ids contained in the
23 array pointed to by pidPtr.
24
25 int *pidPtr (in) Address of array containing numPids
26 process ids.
27
28 Tcl_Pid pid (in) The id of the process (pipe) to wait
29 for.
30
31 int *statusPtr (out) The result of waiting on a process
32 (pipe). Either 0 or ECHILD.
33
34 int options (in) The options controlling the wait. WNO‐
35 HANG specifies not to wait when check‐
36 ing the process.
37_________________________________________________________________
38
40 Tcl_DetachPids and Tcl_ReapDetachedProcs provide a mechanism for manag‐
41 ing subprocesses that are running in background. These procedures are
42 needed because the parent of a process must eventually invoke the wait‐
43 pid kernel call (or one of a few other similar kernel calls) to wait
44 for the child to exit. Until the parent waits for the child, the
45 child's state cannot be completely reclaimed by the system. If a par‐
46 ent continually creates children and doesn't wait on them, the system's
47 process table will eventually overflow, even if all the children have
48 exited.
49
50 Tcl_DetachPids may be called to ask Tcl to take responsibility for one
51 or more processes whose process ids are contained in the pidPtr array
52 passed as argument. The caller presumably has started these processes
53 running in background and does not want to have to deal with them
54 again.
55
56 Tcl_ReapDetachedProcs invokes the waitpid kernel call on each of the
57 background processes so that its state can be cleaned up if it has
58 exited. If the process has not exited yet, Tcl_ReapDetachedProcs does
59 not wait for it to exit; it will check again the next time it is
60 invoked. Tcl automatically calls Tcl_ReapDetachedProcs each time the
61 exec command is executed, so in most cases it is not necessary for any
62 code outside of Tcl to invoke Tcl_ReapDetachedProcs. However, if you
63 call Tcl_DetachPids in situations where the exec command may never get
64 executed, you may wish to call Tcl_ReapDetachedProcs from time to time
65 so that background processes can be cleaned up.
66
67 Tcl_WaitPid is a thin wrapper around the facilities provided by the
68 operating system to wait on the end of a spawned process and to check a
69 whether spawned process is still running. It is used by Tcl_ReapDe‐
70 tachedProcs and the channel system to portably access the operating
71 system.
72
73
75 background, child, detach, process, wait
76
77
78
79Tcl Tcl_DetachPids(3)