diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-webserver.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp index 4ac550e..7826a58 100644 --- a/tests/test-webserver.cpp +++ b/tests/test-webserver.cpp @@ -15,6 +15,8 @@ #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> +#include <fmt/core.h> + #include <chrono> #include <filesystem> #include <iostream> @@ -33,6 +35,7 @@ using namespace std::string_literals; namespace fs = std::filesystem; namespace pt = boost::property_tree; +using namespace Reichwein; class WebserverProcess { @@ -118,6 +121,28 @@ public: m_pid = 0; } + bool isRunning() + { + if (m_pid == 0) + return false; + + fs::path pid_file{fmt::format("/proc/{}/stat", m_pid)}; + if (!fs::exists(pid_file)) + return false; + + std::string s{File::getFile(pid_file)}; + + auto pos0{s.find(' ', 0)}; + pos0 = s.find(' ', pos0 + 1); + pos0++; + + auto pos1{s.find(' ', pos0 + 1)}; + + std::string state{s.substr(pos0, pos1 - pos0)}; + + return state == "R" || state == "S"; + } + private: pid_t m_pid; }; |