Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++, How to determine if a Windows Process is running?

This is concerning Windows XP processes.

I have a process running, let's call it Process1. Process1 creates a new process, Process2, and saves its id.

Now, at some point Process1 wants Process2 to do something, so it first needs to make sure that Process2 is still alive and that the user has not not killed it.

How can I check that this process is still running? Since I created it, I have the Process ID, I would think there is some library function along the lines of IsProcessIDValid( id ) but I can't find it on MSDN

like image 345
Pedro Avatar asked Oct 19 '09 21:10

Pedro


People also ask

How can I see what process is using a program?

The best place to start when monitoring apps is the Task Manager. Launch it from the Start menu or with the Ctrl+Shift+Esc keyboard shortcut. You'll land on the Processes screen. At the top of the table, you'll see a list of all the apps which are running on your desktop.

How do I search for a process in Windows?

Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column. Click on any column name to sort.


1 Answers

You can use GetExitCodeProcess. It will return STILL_ACTIVE (259) if the process is still running (or if it happened to exit with that exit code :( ).

like image 117
Dolphin Avatar answered Sep 29 '22 22:09

Dolphin