Move the pid_running() function to common utils

We're going to need this for our watchdog.
This commit is contained in:
Robbert van der Helm
2021-05-01 17:08:47 +02:00
parent 131d749ba6
commit 071bb157ad
3 changed files with 24 additions and 24 deletions
+18
View File
@@ -48,6 +48,24 @@ bool set_realtime_priority(bool sched_fifo, int priority) {
&params) == 0;
}
bool pid_running(pid_t pid) {
// With regular individually hosted plugins we can simply check whether the
// process is still running, however Boost.Process does not allow you to do
// the same thing for a process that's not a direct child if this process.
// When using plugin groups we'll have to manually check whether the PID
// returned by the group host process is still active. We sadly can't use
// `kill()` for this as that provides no way to distinguish between active
// processes and zombies, and a terminated group host process will always be
// left as a zombie process. If the process is active, then
// `/proc/<pid>/{cwd,exe,root}` will be valid symlinks.
try {
fs::canonical("/proc/" + std::to_string(pid) + "/exe");
return true;
} catch (const fs::filesystem_error&) {
return false;
}
}
ScopedFlushToZero::ScopedFlushToZero() {
old_ftz_mode = _MM_GET_FLUSH_ZERO_MODE();
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
+6
View File
@@ -84,6 +84,12 @@ std::optional<int> get_realtime_priority();
*/
bool set_realtime_priority(bool sched_fifo, int priority = 5);
/**
* Check whether a process with the given PID is still active (and not a
* zombie).
*/
bool pid_running(pid_t pid);
/**
* A RAII wrapper that will temporarily enable the FTZ flag so that denormals
* are automatically flushed to zero, returning to whatever the flag was
-24
View File
@@ -26,12 +26,6 @@
namespace bp = boost::process;
namespace fs = boost::filesystem;
/**
* Check whether a process with the given PID is still active (and not a
* zombie).
*/
bool pid_running(pid_t pid);
/**
* Simple helper function around `boost::process::child` that launches the host
* application (`*.exe`) wrapped in winedbg if compiling with
@@ -234,21 +228,3 @@ void GroupHost::terminate() {
// the sockets will cause the associated plugin to exit.
sockets.close();
}
bool pid_running(pid_t pid) {
// With regular individually hosted plugins we can simply check whether the
// process is still running, however Boost.Process does not allow you to do
// the same thing for a process that's not a direct child if this process.
// When using plugin groups we'll have to manually check whether the PID
// returned by the group host process is still active. We sadly can't use
// `kill()` for this as that provides no way to distinguish between active
// processes and zombies, and a terminated group host process will always be
// left as a zombie process. If the process is active, then
// `/proc/<pid>/{cwd,exe,root}` will be valid symlinks.
try {
fs::canonical("/proc/" + std::to_string(pid) + "/exe");
return true;
} catch (const fs::filesystem_error&) {
return false;
}
}