aboutsummaryrefslogtreecommitdiff
path: root/zencore/thread.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2022-02-11 09:12:32 +0100
committerMartin Ridgers <[email protected]>2022-02-11 09:12:32 +0100
commit22e4e3b389df7cddc134ea998cda6a4563af697c (patch)
treef811d59bfe8bd5f8f25142b38c8d2e86166af43c /zencore/thread.cpp
parentPOSIX states the shared memory paths should start with a slash (diff)
downloadzen-22e4e3b389df7cddc134ea998cda6a4563af697c.tar.xz
zen-22e4e3b389df7cddc134ea998cda6a4563af697c.zip
Do not zombify child processes to more closely match Windows
Diffstat (limited to 'zencore/thread.cpp')
-rw-r--r--zencore/thread.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp
index a123eec82..fba2d4732 100644
--- a/zencore/thread.cpp
+++ b/zencore/thread.cpp
@@ -73,6 +73,19 @@ SetNameInternal(DWORD thread_id, const char* name)
}
#endif
+#if ZEN_PLATFORM_LINUX
+const bool bNoZombieChildren = [] () {
+ // When a child process exits it is put into a zombie state until the parent
+ // collects its result. This doesn't fit the Windows-like model that Zen uses
+ // where there is a less strict familial model and no zombification. Ignoring
+ // SIGCHLD siganals removes the need to call wait() on zombies. Another option
+ // would be for the child to call setsid() but that would detatch the child
+ // from the terminal.
+ sigignore(SIGCHLD);
+ return true;
+} ();
+#endif
+
void
SetCurrentThreadName([[maybe_unused]] std::string_view ThreadName)
{
@@ -628,8 +641,10 @@ ProcessHandle::Wait(int TimeoutMs)
timespec SleepTime = {0, SleepMs * 1000 * 1000};
for (int i = 0;; i += SleepMs)
{
+#if ZEN_PLATFORM_MAC
int WaitState = 0;
waitpid(m_Pid, &WaitState, WNOHANG | WCONTINUED | WUNTRACED);
+#endif
if (kill(m_Pid, 0) < 0)
{