From 962e8a19deaa939ede349fa2fb3845ea98e09e5d Mon Sep 17 00:00:00 2001 From: "Eric J. Korpela" Date: Sat, 6 Sep 2003 03:34:03 +0000 Subject: [PATCH] Added a wait4 implementation for older operating systems. svn path=/trunk/boinc/; revision=2283 --- client/app.C | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/client/app.C b/client/app.C index 6f35d7d7dd..50b37400ae 100644 --- a/client/app.C +++ b/client/app.C @@ -446,6 +446,46 @@ int ACTIVE_TASK::kill_task() { #endif } +#if !defined(HAVE_WAIT4) && defined(HAVE_WAIT3) +#include +struct proc_info_t { + int status; + rusage r; + proc_info_t() {}; + proc_info_t(int s, const rusage &ru); +}; + +proc_info_t::proc_info_t(int s, const rusage &ru) : status(s), r(ru) {} + +pid_t wait4(pid_t pid, int *statusp, int options, struct rusage *rusagep) { + static std::map proc_info; + pid_t tmp_pid=0; + + if (!pid) { + return wait3(statusp,options,rusagep); + } else { + if (proc_info.find(pid) == proc_info.end()) { + do { + tmp_pid=wait3(statusp,options,rusagep); + if ((tmp_pid>0) && (tmp_pid != pid)) { + proc_info[tmp_pid]=proc_info_t(*statusp,*rusagep); + if (!(options && WNOHANG)) { + tmp_pid=0; + } + } else { + return pid; + } + } while (!tmp_pid); + } else { + *statusp=proc_info[pid].status; + *rusagep=proc_info[pid].r; + proc_info.erase(pid); + return pid; + } + } +} +#endif + bool ACTIVE_TASK::task_exited() { #ifdef _WIN32 unsigned long exit_code;