开发者

Get Process Status with WinApi in C (Active or Not)

开发者 https://www.devze.com 2023-04-12 19:50 出处:网络
At my operating system course in a project we have to 开发者_如何学Goget process status. We are coding with c.

At my operating system course in a project we have to 开发者_如何学Goget 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?


Get a process handle using OpenProcess with PROCESS_QUERY_INFORMATION as the desired access (or use a handle previously obtained, possibly from CreateProcess), then try to get its termination status using GetExitCodeProcess. If it returns STILL_ACTIVE, the process has not terminated yet, otherwise it has. Don't forget to close the handle using CloseHandle


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号