diff options
author | f.bonnet <f.bonnet> | 2017-08-18 12:49:08 (GMT) |
---|---|---|
committer | f.bonnet <f.bonnet> | 2017-08-18 12:49:08 (GMT) |
commit | 03470df2ff2414f1912a85772cd6f558196ca8bc (patch) | |
tree | 93c4102d0c31a0bf11c1568d11980957a735f9cf /generic/tclPipe.c | |
parent | 5aaef06572dc90a7a493d187959fe9829da27fbb (diff) | |
download | tcl-03470df2ff2414f1912a85772cd6f558196ca8bc.zip tcl-03470df2ff2414f1912a85772cd6f558196ca8bc.tar.gz tcl-03470df2ff2414f1912a85772cd6f558196ca8bc.tar.bz2 |
Completed [tcl::process autopurge] semantics and added [tcl::process purge] implementation along with the necessary internal functions TclpGetChildPid/TclReapPids
Diffstat (limited to 'generic/tclPipe.c')
-rw-r--r-- | generic/tclPipe.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/generic/tclPipe.c b/generic/tclPipe.c index d6cd188..c98ee7e 100644 --- a/generic/tclPipe.c +++ b/generic/tclPipe.c @@ -247,6 +247,61 @@ Tcl_ReapDetachedProcs(void) /* *---------------------------------------------------------------------- * + * TclReapPids -- + * + * This function is similar to Tcl_ReapDetachedProcs but works on a + * subset of processes. + * + * Results: + * None. + * + * Side effects: + * Processes are waited on, so that they can be reaped by the system. + * + *---------------------------------------------------------------------- + */ + +void +TclReapPids( + int numPids, /* Number of pids to detach: gives size of + * array pointed to by pidPtr. */ + Tcl_Pid *pidPtr) /* Array of pids to detach. */ +{ + register Detached *detPtr; + Detached *nextPtr, *prevPtr; + int status; + Tcl_Pid pid; + int i; + + Tcl_MutexLock(&pipeMutex); + for (detPtr = detList, prevPtr = NULL; detPtr != NULL; ) { + pid = 0; + for (i = 0; i < numPids; i++) { + if (detPtr->pid == pidPtr[i]) { + pid = Tcl_WaitPid(detPtr->pid, &status, WNOHANG); + break; + } + } + if ((pid == 0) || ((pid == (Tcl_Pid) -1) && (errno != ECHILD))) { + prevPtr = detPtr; + detPtr = detPtr->nextPtr; + continue; + } + nextPtr = detPtr->nextPtr; + if (prevPtr == NULL) { + detList = detPtr->nextPtr; + } else { + prevPtr->nextPtr = detPtr->nextPtr; + } + ckfree(detPtr); + detPtr = nextPtr; + } + Tcl_MutexUnlock(&pipeMutex); +} + +/* + *---------------------------------------------------------------------- + * * TclCleanupChildren -- * * This is a utility function used to wait for child processes to exit, @@ -854,7 +909,9 @@ TclCreatePipeline( * arguments between the "|" characters. */ - Tcl_ReapDetachedProcs(); + if (TclProcessGetAutopurge()) { + Tcl_ReapDetachedProcs(); + } pidPtr = ckalloc(cmdCount * sizeof(Tcl_Pid)); curInFile = inputFile; |