Dave's Brain

Browse - programming tips - win32 check if a process is running

Date: 2010may13
OS: Windows
Language: C/C++

Q.  How can I tell if a process is running?

A.  By attempting to get the exit code, like this:

	BOOL IsProcessRunning(const HANDLE hProcess)
	{
		DWORD		dwExitCode;
	
		if (!GetExitCodeProcess(hProcess, &dwExitCode)) return FALSE;
		return dwExitCode == STILL_ACTIVE;
	}

	void ExampleUse()
	{
		if (IsProcessRunning(hMyProcess))
		{
			printf("My process IS running\n");
		}
		else
		{
			printf("My process is NOT running\n");
		}
	}

If you just want to wait until a process is done it is better to do:

	WaitForSingleObject(hProcess, INFINITE);
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: