+ int32_t childPid = waitpid(-1, &status, WNOHANG);
+ if(childPid == 0)
+ {
+ // No children have finished.
+ // Check if any have exceeded execution time
+ auto endTime = std::chrono::steady_clock::now();
+
+ for(auto& tc : children)
+ {
+ std::chrono::steady_clock::duration timeSpan = endTime - tc.second.startTime;
+ std::chrono::duration<double> seconds = std::chrono::duration_cast<std::chrono::duration<double>>(timeSpan);
+ if(seconds.count() > MAXIMUM_CHILD_LIFETIME)
+ {
+ // Kill the child process. A subsequent call to waitpid will process signal result below.
+ kill(tc.first, SIGKILL);
+ }
+ }
+ }
+ else if(childPid == -1) // waitpid errored