From 42eca60cfc7fe49749d0ef816b227b8fbfea3a5c Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 18 Nov 2016 00:04:17 +0100 Subject: [PATCH] Added forget and remember functions to process library --- lib/procs.cpp | 14 +++++++++++++- lib/procs.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/procs.cpp b/lib/procs.cpp index ba984b10..69e38299 100644 --- a/lib/procs.cpp +++ b/lib/procs.cpp @@ -444,6 +444,18 @@ int Util::Procs::Count() { /// Returns true if a process with this PID is currently active. bool Util::Procs::isActive(pid_t name) { tthread::lock_guard guard(plistMutex); - return (plist.count(name) == 1) && (kill(name, 0) == 0); + return (kill(name, 0) == 0); +} + +/// Forget about the given PID, keeping it running on shutdown. +void Util::Procs::forget(pid_t pid) { + tthread::lock_guard guard(plistMutex); + plist.erase(pid); +} + +/// Remember the given PID, killing it on shutdown. +void Util::Procs::remember(pid_t pid) { + tthread::lock_guard guard(plistMutex); + plist.insert(pid); } diff --git a/lib/procs.h b/lib/procs.h index 2c07cda8..667f570b 100644 --- a/lib/procs.h +++ b/lib/procs.h @@ -38,6 +38,8 @@ namespace Util { static int Count(); static bool isActive(pid_t name); static bool isRunning(pid_t pid); + static void forget(pid_t pid); + static void remember(pid_t pid); static std::set socketList; ///< Holds sockets that should be closed before forking }; }