Added forget and remember functions to process library

This commit is contained in:
Thulinma 2016-11-18 00:04:17 +01:00
parent bdb1578ba6
commit 42eca60cfc
2 changed files with 15 additions and 1 deletions

View file

@ -444,6 +444,18 @@ int Util::Procs::Count() {
/// Returns true if a process with this PID is currently active. /// Returns true if a process with this PID is currently active.
bool Util::Procs::isActive(pid_t name) { bool Util::Procs::isActive(pid_t name) {
tthread::lock_guard<tthread::mutex> guard(plistMutex); tthread::lock_guard<tthread::mutex> 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<tthread::mutex> guard(plistMutex);
plist.erase(pid);
}
/// Remember the given PID, killing it on shutdown.
void Util::Procs::remember(pid_t pid) {
tthread::lock_guard<tthread::mutex> guard(plistMutex);
plist.insert(pid);
} }

View file

@ -38,6 +38,8 @@ namespace Util {
static int Count(); static int Count();
static bool isActive(pid_t name); static bool isActive(pid_t name);
static bool isRunning(pid_t pid); static bool isRunning(pid_t pid);
static void forget(pid_t pid);
static void remember(pid_t pid);
static std::set<int> socketList; ///< Holds sockets that should be closed before forking static std::set<int> socketList; ///< Holds sockets that should be closed before forking
}; };
} }