Files
BloomPatched/src/Services/ProcessService.hpp

62 lines
1.6 KiB
C++
Raw Normal View History

2022-09-15 00:30:59 +01:00
#pragma once
#include <optional>
#include <memory>
#include <sys/types.h>
2022-09-15 00:30:59 +01:00
#include <proc/readproc.h>
namespace Services
2022-09-15 00:30:59 +01:00
{
class ProcessService
2022-09-15 00:30:59 +01:00
{
public:
/**
* Returns the process ID of the current process.
*
* @return
*/
static ::pid_t getProcessId();
/**
* Returns the process ID of the current process's parent.
*
* @return
*/
static ::pid_t getParentProcessId();
/**
* Returns the effective user ID of the given process.
*
* @param processId
* If not provided, this function will use the current process ID.
*
* @return
*/
static ::uid_t getEffectiveUserId(std::optional<::pid_t> processId = std::nullopt);
/**
* Returns true if the given process is running as root.
*
* @param processId
* If not provided, this function will perform the check against the current process.
*
* @return
*/
static bool isRunningAsRoot(std::optional<::pid_t> processId = std::nullopt);
2022-09-15 00:30:59 +01:00
/**
* Returns true if the given process is managed by CLion.
*
* @param processId
* If not provided, this function will perform the check against the current process.
*
2022-09-15 00:30:59 +01:00
* @return
*/
static bool isManagedByClion(std::optional<::pid_t> processId = std::nullopt);
2022-09-15 00:30:59 +01:00
private:
2022-10-01 21:01:37 +01:00
using Proc = std::unique_ptr<::proc_t, decltype(&::freeproc)>;
static Proc getProcessInfo(::pid_t processId);
2022-09-15 00:30:59 +01:00
};
}