-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessMonitor.h
58 lines (43 loc) · 1.21 KB
/
ProcessMonitor.h
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2023 Stephen Foulds
#pragma once
#include "Process.h"
#include <algorithm>
#include <condition_variable>
#include <json.hpp>
#include <list>
#include <memory>
#include <optional>
#include <regex>
#include <string>
#include <thread>
#include <vector>
class ProcessMonitor
{
public:
ProcessMonitor();
~ProcessMonitor();
ProcessMonitor(const ProcessMonitor &) = delete;
ProcessMonitor &operator=(const ProcessMonitor &) = delete;
bool Start();
bool Stop();
std::string GetJson();
private:
bool setListenMode(bool enable) const;
void receiveMessages();
static void getProcessCommandLine(pid_t pid, std::string &commandLine);
[[nodiscard]] static pid_t getParentPid(pid_t pid);
void setSocketFilter() const;
std::string getSystemdService(pid_t pid);
private:
int mSocket;
bool mListen;
long mPageSize;
bool mValid;
nlohmann::json mProcessJson;
std::thread mMessageReceiver;
std::vector<processInfo> mRunningProcesses;
std::vector<processInfo> mExitedProcesses;
std::chrono::time_point<std::chrono::system_clock> mStart;
std::chrono::time_point<std::chrono::system_clock> mEnd;
};