Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I check that if a process is running or not ?

387 views
Skip to first unread message

wrenashe

unread,
Apr 23, 2008, 6:34:31 AM4/23/08
to
OpenProcess() failed to detect if a process is running via given PID.
Does anyone have idea to do the check by win32 api?

Mike Collins

unread,
Apr 23, 2008, 7:53:23 AM4/23/08
to
At a guess, you could use CreateToolhelp32Snapshot to look for the process
depending on what information you have before hand...

Mike C

"wrenashe" <wren...@gmail.com> wrote in message
news:03c65e6e-a556-4f39...@24g2000hsh.googlegroups.com...

na

unread,
Apr 23, 2008, 1:54:15 PM4/23/08
to

"wrenashe" <wren...@gmail.com> wrote in message
news:03c65e6e-a556-4f39...@24g2000hsh.googlegroups.com...
> OpenProcess() failed to detect if a process is running via given PID.
> Does anyone have idea to do the check by win32 api?

Use the HKEY_PERFORMANCE_DATA section of the Registry.


wrenashe

unread,
Apr 23, 2008, 11:47:42 PM4/23/08
to
On Apr 23, 7:53 pm, "Mike Collins" <its@TheBottomOfThePost> wrote:
> At a guess, you could use CreateToolhelp32Snapshot to look for theprocess
> depending on what information you have before hand...
>
> Mike C
>
> "wrenashe" <wrena...@gmail.com> wrote in message
>
> news:03c65e6e-a556-4f39...@24g2000hsh.googlegroups.com...
>
> > OpenProcess() failed to detect if aprocessisrunningvia given PID.

> > Does anyone have idea to do thecheckby win32 api?

Since a killed process's pid still exists in windows handle table, so
openprocess() fails to report its actual state. I used
CreateToolhelp32Snapshot() to list all known PIDs, and then check if
my pid(that killed one's) is in there. If there, process is running
otherwise, it is gone already. Now it seems work well.

Ben Voigt [C++ MVP]

unread,
Apr 24, 2008, 9:59:15 AM4/24/08
to
wrenashe wrote:
> On Apr 23, 7:53 pm, "Mike Collins" <its@TheBottomOfThePost> wrote:
>> At a guess, you could use CreateToolhelp32Snapshot to look for
>> theprocess depending on what information you have before hand...
>>
>> Mike C
>>
>> "wrenashe" <wrena...@gmail.com> wrote in message
>>
>> news:03c65e6e-a556-4f39...@24g2000hsh.googlegroups.com...
>>
>>> OpenProcess() failed to detect if aprocessisrunningvia given PID.
>>> Does anyone have idea to do thecheckby win32 api?
>
> Since a killed process's pid still exists in windows handle table, so
> openprocess() fails to report its actual state. I used

GetExitCodeProcess?
http://msdn2.microsoft.com/en-us/library/ms683189(VS.85).aspx

Corinna Vinschen

unread,
Apr 25, 2008, 5:14:51 AM4/25/08
to
wrenashe wrote:
> OpenProcess() failed to detect if a process is running via given PID.
> Does anyone have idea to do the check by win32 api?

If you have the handle to the process and SYNCHRONIZE access, use
WaitForSingleObject/WaitForMultipleObjects to wait for the handle. It
will be signalled as soon as the process exits.


Corinna

--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat

0 new messages