|
NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
|
进程管理类 更多...
#include <process.hpp>
类 | |
| struct | memory_info |
| 进程内存信息 更多... | |
| struct | time_info |
| 进程时间信息 更多... | |
| struct | shell_result |
| shell 命令执行结果 更多... | |
Public 类型 | |
| enum class | state { running , suspended , stopped , exited , unknown } |
| 进程状态枚举 更多... | |
| enum class | permission { read = 0x01 , write = 0x02 , execute = 0x04 , terminate = 0x08 , query_info = 0x10 , all = 0xFF } |
| 进程权限枚举 更多... | |
| enum class | privilege_level { privileged , not_privileged , unknown } |
| 进程特权级别 更多... | |
| enum class | elevation_tool { auto_ , sudo , pkexec } |
| 提权工具选择 更多... | |
| using | native_id_type |
| 进程ID类型 | |
Public 成员函数 | |
| process ()=default | |
| 默认构造 | |
| ~process () | |
| 析构 | |
| process (process &&other) noexcept | |
| 移动构造 | |
| process & | operator= (process &&other) noexcept |
| 移动赋值 | |
| process & | set_work_dir (const string &dir) |
| 设置子进程工作目录 | |
| process & | set_env (const string &key, const string &value) |
| 设置子进程环境变量 | |
| process & | set_capture_stdout (bool v=true) |
| 捕获标准输出 | |
| process & | set_capture_stderr (bool v=true) |
| 捕获标准错误 | |
| process & | set_stdin_data (const string &data) |
| 预设要写入子进程 stdin 的数据 | |
| void | start (const string &executable, const vector< string > &args={}) |
| 启动子进程 | |
| void | start_elevated (const string &executable, const vector< string > &args={}, elevation_tool tool=elevation_tool::auto_) |
| 以管理员/root 权限启动子进程 | |
| int | wait (int timeout_ms=-1) |
| 等待子进程退出 | |
| void | terminate () |
| 终止子进程(SIGTERM → 短暂等待 → SIGKILL) | |
| void | suspend () |
| 挂起子进程 | |
| void | resume () |
| 恢复子进程 | |
| void | close () noexcept |
| 显式关闭进程句柄并清理资源 | |
| bool | is_running () const |
| 子进程是否正在运行 | |
| state | get_state () const |
| 获取子进程状态 | |
| memory_info | get_memory_info () const |
| 获取子进程内存信息 | |
| native_id_type | id () const noexcept |
| 子进程 ID | |
| int | exit_code () const noexcept |
| 子进程退出码(仅在 wait() 返回后有效) | |
| const string & | stdout_output () const noexcept |
| 获取捕获的标准输出 | |
| const string & | stderr_output () const noexcept |
| 获取捕获的标准错误 | |
| void | write_stdin (const string &data) |
| 向子进程的 stdin 写入数据 | |
| void | close_stdin () |
| 关闭子进程的 stdin | |
静态 Public 成员函数 | |
| static shell_result | execute_shell (const string &command, int timeout_ms=-1) |
| 执行 shell 命令并获取输出 | |
| static shell_result | execute_elevated_shell (const string &command, int timeout_ms=-1, elevation_tool tool=elevation_tool::auto_) |
| 以管理员/root 权限执行 shell 命令 | |
| static native_id_type | current_id () noexcept |
| 获取当前进程 ID | |
| static privilege_level | current_privilege_level () noexcept |
| 获取当前进程的特权级别 | |
| static string | name (native_id_type process_id) |
| 根据进程 ID 获取进程名称 | |
| static memory_info | get_memory_info (native_id_type process_id) |
| 查询任意进程的内存信息 | |
| static state | get_state (native_id_type process_id) |
| 查询任意进程的运行状态 | |
| static privilege_level | get_privilege_level (native_id_type process_id) |
| 获取指定进程的特权级别 | |
| static bool | check_permission (native_id_type process_id, permission perm) |
| 检查对指定进程的访问权限 | |
进程管理类
支持 stdout/stderr 分离捕获、stdin 写入、工作目录和环境变量设置。
在文件 process.hpp 第 63 行定义.
|
strong |
提权工具选择
| 枚举值 | |
|---|---|
| auto_ | Windows 忽略此选项;Linux 自动尝试 pkexec,回退至 sudo |
| sudo | Linux 强制使用 sudo 提权 |
| pkexec | Linux 强制使用 pkexec 提权 |
在文件 process.hpp 第 138 行定义.
|
strong |
进程权限枚举
| 枚举值 | |
|---|---|
| read | 读取权限 |
| write | 写入权限 |
| execute | 执行权限 |
| terminate | 终止权限 |
| query_info | 查询信息权限 |
| all | 所有权限 |
在文件 process.hpp 第 116 行定义.
|
strong |
|
strong |
进程状态枚举
| 枚举值 | |
|---|---|
| running | 进程正在运行 |
| suspended | 进程已被挂起 |
| stopped | 进程已停止 |
| exited | 进程已退出 |
| unknown | 进程状态未知 |
在文件 process.hpp 第 104 行定义.
|
default |
默认构造
不启动任何进程
被这些函数引用 operator=(), process(), set_capture_stderr(), set_capture_stdout(), set_env(), set_stdin_data(), set_work_dir() , 以及 ~process().
| process::~process | ( | ) |
|
staticnodiscard |
检查对指定进程的访问权限
| process_id | 目标进程 ID |
| perm | 要检查的权限 |
引用了 check_permission().
被这些函数引用 check_permission().
|
static |
以管理员/root 权限执行 shell 命令
| command | 命令字符串 |
| timeout_ms | 超时毫秒,-1 无限等待 |
| tool | 提权工具选择 |
| process_exception | 执行失败或超时 |
引用了 auto_.
|
staticnodiscard |
执行 shell 命令并获取输出
| command | 命令字符串 |
| timeout_ms | 超时毫秒,-1 无限等待 |
| process_exception | 执行失败或超时 |
|
staticnodiscard |
|
staticnodiscard |
|
staticnodiscard |
|
staticnodiscard |
| process & process::set_capture_stderr | ( | bool | v = true | ) |
| void process::start_elevated | ( | const string & | executable, |
| const vector< string > & | args = {}, | ||
| elevation_tool | tool = elevation_tool::auto_ ) |
以管理员/root 权限启动子进程
| executable | 可执行文件路径 |
| args | 命令行参数列表 |
| tool | 提权工具 |
| process_exception | 启动失败或已设置了管道捕获时抛出 |
| int process::wait | ( | int | timeout_ms = -1 | ) |