Get Process Status with WinApi in C (Active or Not)
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
精彩评论