From 10dc56c3380971a4961d62c10ef756c8537f7c61 Mon Sep 17 00:00:00 2001 From: Thulinma <jaron@vietors.com> Date: Mon, 10 Jun 2013 15:18:34 +0200 Subject: [PATCH] Fixed a race condition in process status checking. --- lib/procs.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/procs.cpp b/lib/procs.cpp index f0a07913..5b61ea18 100644 --- a/lib/procs.cpp +++ b/lib/procs.cpp @@ -621,7 +621,9 @@ bool Util::Procs::isActive(std::string name){ std::map<pid_t, std::string>::iterator it; for (it = plist.begin(); it != plist.end(); it++){ if (( *it).second == name){ - return true; + if (kill(( *it).first, 0) == 0){ + return true; + } } } return false; @@ -629,7 +631,7 @@ bool Util::Procs::isActive(std::string name){ /// Returns true if a process with this PID is currently active. bool Util::Procs::isActive(pid_t name){ - return (plist.count(name) == 1); + return (plist.count(name) == 1) && (kill(name, 0) == 0); } /// Gets PID for this named process, if active.