summaryrefslogtreecommitdiffhomepage
path: root/process.cpp
blob: b30ef3d2026837db962ddb9613e8f7769f49d59c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "process.h"

#include <filesystem>
#include <string>

#include "file.h"

namespace fs = std::filesystem;

bool Reichwein::Process::is_running(pid_t pid)
{
  fs::path pid_file{"/proc/" + std::to_string(pid) + "/stat"};
  if (!fs::exists(pid_file))
   return false;

  std::string s{Reichwein::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";
}