diff options
| author | Martin Ridgers <[email protected]> | 2021-11-26 15:15:33 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-11-26 15:17:25 +0100 |
| commit | 4421f40ab6d2bc8e432d3e5aa24545b7b1e117d1 (patch) | |
| tree | e73e47c9747a47f412036cd18d922612a0a677d8 /zencore/thread.cpp | |
| parent | ProcessHandle::Wait() wasn't waiting indefinitely with a <0 timeout (diff) | |
| download | zen-4421f40ab6d2bc8e432d3e5aa24545b7b1e117d1.tar.xz zen-4421f40ab6d2bc8e432d3e5aa24545b7b1e117d1.zip | |
Child processes don't fully terminate until the parent waits on them
Diffstat (limited to 'zencore/thread.cpp')
| -rw-r--r-- | zencore/thread.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp index 0f2dc7181..3b69b7a1e 100644 --- a/zencore/thread.cpp +++ b/zencore/thread.cpp @@ -22,6 +22,7 @@ # include <pthread.h> # include <signal.h> # include <sys/file.h> +# include <sys/wait.h> # include <time.h> # include <unistd.h> #endif @@ -585,10 +586,8 @@ ProcessHandle::Wait(int TimeoutMs) timespec SleepTime = { 0, SleepMs * 1000 * 1000 }; for (int i = 0; ; i += SleepMs) { - if (TimeoutMs >= 0 && i >= TimeoutMs) - { - return false; - } + int WaitState = 0; + waitpid(m_Pid, &WaitState, WNOHANG|WCONTINUED|WUNTRACED); if (kill(m_Pid, 0) < 0) { @@ -599,6 +598,11 @@ ProcessHandle::Wait(int TimeoutMs) break; } + if (TimeoutMs >= 0 && i >= TimeoutMs) + { + return false; + } + nanosleep(&SleepTime, nullptr); } #else |