根据进程名获取PID - DmaGetPidFromName
函数简介
根据进程名获取进程 ID (PID),支持部分匹配。(高级版功能,普通版无法使用)
接口名称
DmaGetPidFromName
DLL调用
int32_t OLA_CALL_TYPE DmaGetPidFromName(int64_t instance, int64_t deviceId, OLA_STRING_INPUT processName);
参数定义:
instance(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。deviceId(长整型数): 设备IDprocessName(字符串): 进程名,支持部分匹配
示例:
// 获取进程 PID
int32_t pid = DmaGetPidFromName(instance, deviceId, "notepad.exe");
if (pid > 0) {
printf("进程 PID: %d\n", pid);
} else {
printf("未找到进程\n");
}
// 使用部分匹配
int32_t pid2 = DmaGetPidFromName(instance, deviceId, "notepad");
if (pid2 > 0) {
printf("进程 PID: %d\n", pid2);
}
返回值
整型数:
- 成功: 返回 PID (>0)
- 失败: 返回 0
参数说明
processName(进程名):
- 支持完整进程名 (如 "notepad.exe")
- 支持部分匹配 (如 "notepad")
- 不区分大小写
应用场景
- 快速查找目标进程
- 进程管理和监控
- 动态获取进程 ID
相关接口
- DmaGetPidList - 获取所有进程 PID 列表
- DmaGetProcessInfo - 获取进程基本信息
