CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    201

    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.

  2. #2
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: Check if a program runs?

    You can use log file to record when the program has shutted down.
    Thanks for your help.

  3. #3
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    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

  4. #4
    Join Date
    May 2009
    Location
    China
    Posts
    8

    Re: Check if a program runs?

    Is the program you want to monitor developed by you or published by others?

  5. #5
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    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.

  6. #6
    Join Date
    Feb 2009
    Posts
    201

    Re: Check if a program runs?

    Quote Originally Posted by Lzj View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured