Browse Source

[3669] Added support for ProcessSpawn spawning more processes.

Marcin Siodelski 10 years ago
parent
commit
150e8fc3b5
2 changed files with 27 additions and 0 deletions
  1. 22 0
      src/lib/util/process_spawn.cc
  2. 5 0
      src/lib/util/process_spawn.h

+ 22 - 0
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<pid_t, int> 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<pid_t, int>::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<pid_t, int>::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));

+ 5 - 0
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