-
Notifications
You must be signed in to change notification settings - Fork 53
zh_get_process_object
伏秋洛 edited this page Jun 19, 2023
·
1 revision
获取一个Process对象以执行各种操作。
#include "process.h"
using namespace hak;
pid_t pid = 123456;
auto process = std::make_shared<hak::process>(pid);
上面的代码就获取了一个hak::process对象。
判断进程是否存活可以使用waitpid或者内核模块的cn_proc.h来实现,但是hak也提供了一个读取/proc/pid/stat实现的运行状态判断的接口(虽然非常耗时)。
#include "process.h"
using namespace hak;
pid_t pid = 123456;
auto process = std::make_shared<hak::process>(pid);
bool running = process->is_running();
Only through learning and communication!