From: Marcin Siodelski Date: Thu, 5 Feb 2015 14:58:28 +0000 (+0100) Subject: [3669] Added support for ProcessSpawn spawning more processes. X-Git-Tag: trac3712_base~13^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=150e8fc3b57836f3fbee369287129ade4d7fb236;p=thirdparty%2Fkea.git [3669] Added support for ProcessSpawn spawning more processes. --- diff --git a/src/lib/util/process_spawn.cc b/src/lib/util/process_spawn.cc index eb6f19de55..0986413db6 100644 --- a/src/lib/util/process_spawn.cc +++ b/src/lib/util/process_spawn.cc @@ -66,6 +66,11 @@ public: /// @return true if the child process is running, false otherwise. bool isRunning(const pid_t pid) const; + /// @brief Checks if any of the spawned processes is still running. + /// + /// @return true if at least one child process is still running. + bool isAnyRunning() const; + /// @brief Returns exit status of the process. /// /// If the process is still running, the previous status is returned @@ -103,6 +108,7 @@ private: /// @brief A signal set installing a handler for SIGCHLD. SignalSetPtr signals_; + /// @brief A map holding the status codes of executed processes. std::map process_status_; /// @brief Path to an executable. @@ -190,6 +196,17 @@ ProcessSpawnImpl::isRunning(const pid_t pid) const { return ((pid != 0) && (kill(pid, 0) == 0)); } +bool +ProcessSpawnImpl::isAnyRunning() const { + for (std::map::const_iterator proc = process_status_.begin(); + proc != process_status_.end(); ++proc) { + if (isRunning(proc->first)) { + return (true); + } + } + return (false); +} + int ProcessSpawnImpl::getExitStatus(const pid_t pid) const { std::map::const_iterator status = process_status_.find(pid); @@ -252,6 +269,11 @@ ProcessSpawn::isRunning(const pid_t pid) const { return (impl_->isRunning(pid)); } +bool +ProcessSpawn::isAnyRunning() const { + return (impl_->isAnyRunning()); +} + int ProcessSpawn::getExitStatus(const pid_t pid) const { return (impl_->getExitStatus(pid)); diff --git a/src/lib/util/process_spawn.h b/src/lib/util/process_spawn.h index 492aa640af..977fe39456 100644 --- a/src/lib/util/process_spawn.h +++ b/src/lib/util/process_spawn.h @@ -90,6 +90,11 @@ public: /// @return true if the child process is running, false otherwise. bool isRunning(const pid_t pid) const; + /// @brief Checks if any of the spawned processes is still running. + /// + /// @return true if at least one child process is still running. + bool isAnyRunning() const; + /// @brief Returns exit status of the process. /// /// If the process is still running, the previous status is returned