aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2025-10-05 16:00:47 +1000
committerSteve Bennett <steveb@workware.net.au>2025-10-05 16:01:39 +1000
commit912c167ed6dc5c2cb30bd57e20f10954503438e2 (patch)
treefda25e027857d266d315252d3c2f37e14be302c4
parent5575c554c2e6e8a55655dc61e49cff7ccb71bf48 (diff)
downloadjimtcl-master.zip
jimtcl-master.tar.gz
jimtcl-master.tar.bz2
wait -nohang: return correct result if child still runningHEADmaster
Fixes #359
-rw-r--r--jim-exec.c4
-rw-r--r--tests/exec2.test9
2 files changed, 13 insertions, 0 deletions
diff --git a/jim-exec.c b/jim-exec.c
index 0e681e1..0363faa 100644
--- a/jim-exec.c
+++ b/jim-exec.c
@@ -613,6 +613,10 @@ static int Jim_WaitCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
*/
pid = phandle;
}
+ else if (phandle == 0) {
+ /* Child still running */
+ pid = 0;
+ }
#endif
errCodeObj = JimMakeErrorCode(interp, pid, status, NULL);
diff --git a/tests/exec2.test b/tests/exec2.test
index 9daef58..e63cbbd 100644
--- a/tests/exec2.test
+++ b/tests/exec2.test
@@ -172,4 +172,13 @@ test exec2-5.6 {wait -1 to wait for any child} -constraints {after jim nomingw32
list $status $($waitpid == $pid) $code
} -result {CHILDSTATUS 1 0}
+test exec2-5.7 {wait -nohang for child not finished} -constraints {after jim nomingw32} -body {
+ set pid [exec sleep 10 &]
+ # Get the status of the running child
+ wait -nohang $pid
+} -result {NONE 0 -1} -cleanup {
+ kill $pid
+ wait $pid
+}
+
testreport