-
May 3rd, 2009, 05:01 AM
#1
Check if a program runs?
Hello, all!
How can I check if a program runs?
And when or immediately after it's shutted down, it will notice it and then run a statement.
Or more programs. So if one of them do crash, it will start the one who crashed.
I use Virsual Studio 2008 and C++.
- thanks for your help,
realchamp.
-
May 3rd, 2009, 06:50 AM
#2
Re: Check if a program runs?
You can use log file to record when the program has shutted down.
Thanks for your help.
-
May 4th, 2009, 03:11 AM
#3
Re: Check if a program runs?
You can look for a process having a specific name using the Toolhelp32 API. CreateToolhelp32Snapshot, Process32First and Process32Next are the functions you want to use.
Another way is to use a "starter" Application that starts the target application by calling CreateProcess. CreateProcess fills a PROCESS_INFORMATION structure that contains the PID of the newly created process, so you look for that process using its PID. If there´s no process with that PID you´ll have to restart it.
- Guido
-
May 10th, 2009, 01:56 PM
#4
Re: Check if a program runs?
Is the program you want to monitor developed by you or published by others?
-
May 10th, 2009, 07:38 PM
#5
Re: Check if a program runs?
You can create an interprocess semaphore object. When the first program starts, it creates an interprocess semaphore with an unique name. When subsequent instances of the same program is launched, they will fail creating the semaphore will the same name because the first had already created one. From here, subsequent instances can quit gracefully.
A good reason for using the semaphore is when the first instance of the program is killed, the semaphore will be automatically destroyed.
quoted from C++ Coding Standards:
KISS (Keep It Simple Software):
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
Avoid magic number:
Programming isn't magic, so don't incant it.
-
May 24th, 2009, 12:45 PM
#6
Re: Check if a program runs?
Originally Posted by Lzj
Is the program you want to monitor developed by you or published by others?
It's not published by me. It's made by someone else. And it's NOT in a graphical interface.
Sorry for posting back this late, I forgot I had this thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|