Skip to content

en_get_process_object

伏秋洛 edited this page Jun 19, 2023 · 1 revision

Introduction

Get a Process object to perform various operations.

Example

#include "process.h"

using namespace hak;

pid_t pid = 123456;
auto process = std::make_shared<hak::process>(pid);

The above code obtains a hak::process object.

Check if the process is alive

To check if the process is alive, you can use waitpid or the cn_proc.h kernel module, but hak also provides an interface for checking the running status by reading /proc/pid/stat (although it is very time-consuming).

#include "process.h"

using namespace hak;

pid_t pid = 123456;
auto process = std::make_shared<hak::process>(pid);

bool running = process->is_running();