使用 C 语言的 WinApi 获取进程状态(活动或非活动)
在我的项目操作系统课程中,我们必须获取进程状态。我们用c 编码。
输出示例:
Process No Process Id Program Name Status Handle Count
1 5780 notepad.exe ACTIVE 1
如何获取状态和处理计数?
At my operating system course in a project we have to get process status. We are coding with c.
Example output:
Process No Process Id Program Name Status Handle Count
1 5780 notepad.exe ACTIVE 1
How can i get status and handle count?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
OpenProcess
并使用PROCESS_QUERY_INFORMATION
作为所需的访问权限(或者使用之前获得的句柄,可能来自CreateProcess
< /a>),然后尝试使用GetExitCodeProcess
< /a>.如果它返回STILL_ACTIVE
,则进程尚未终止,否则已终止。不要忘记使用关闭句柄
Get a process handle using
OpenProcess
withPROCESS_QUERY_INFORMATION
as the desired access (or use a handle previously obtained, possibly fromCreateProcess
), then try to get its termination status usingGetExitCodeProcess
. If it returnsSTILL_ACTIVE
, the process has not terminated yet, otherwise it has. Don't forget to close the handle usingCloseHandle
前 2 或 3 列或多或少都是琐碎的。查找 msdn 以获取进程枚举。
句柄枚举有点棘手,但也是可行的,请参阅以下内容:
link1 link2
The first 2 or 3 columns are more or less trivial. Look up msdn for process enumeration.
Handle enumeration is a bit trickier, but also doable, see these:
link1 link2