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, statPtr, 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 for.
29
30 int* statPtr (out) The result of waiting on a process (pipe).
31 Either 0 or ECHILD.
32
33 int options The options controlling the wait. WNOHANG
34 specifies not to wait when checking the
35 process.
36_________________________________________________________________
37
39 Tcl_DetachPids and Tcl_ReapDetachedProcs provide a mechanism for manag‐
40 ing subprocesses that are running in background. These procedures are
41 needed because the parent of a process must eventually invoke the wait‐
42 pid kernel call (or one of a few other similar kernel calls) to wait
43 for the child to exit. Until the parent waits for the child, the
44 child's state cannot be completely reclaimed by the system. If a par‐
45 ent continually creates children and doesn't wait on them, the system's
46 process table will eventually overflow, even if all the children have
47 exited.
48
49 Tcl_DetachPids may be called to ask Tcl to take responsibility for one
50 or more processes whose process ids are contained in the pidPtr array
51 passed as argument. The caller presumably has started these processes
52 running in background and doesn't want to have to deal with them again.
53
54 Tcl_ReapDetachedProcs invokes the waitpid kernel call on each of the
55 background processes so that its state can be cleaned up if it has
56 exited. If the process hasn't exited yet, Tcl_ReapDetachedProcs
57 doesn't wait for it to exit; it will check again the next time it is
58 invoked. Tcl automatically calls Tcl_ReapDetachedProcs each time the
59 exec command is executed, so in most cases it isn't necessary for any
60 code outside of Tcl to invoke Tcl_ReapDetachedProcs. However, if you
61 call Tcl_DetachPids in situations where the exec command may never get
62 executed, you may wish to call Tcl_ReapDetachedProcs from time to time
63 so that background processes can be cleaned up.
64
65 Tcl_WaitPid is a thin wrapper around the facilities provided by the
66 operating system to wait on the end of a spawned process and to check a
67 whether spawned process is still running. It is used by Tcl_ReapDe‐
68 tachedProcs and the channel system to portably access the operating
69 system.
70
71
73 background, child, detach, process, wait
74
75
76
77Tcl Tcl_DetachPids(3)