Thread: QUERY: How to control external exe & read it's process details

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    12

    QUERY: How to control external exe & read it's process details

    I would like to create a service or background running program (something that minimizes to system tray).

    It would have a path list of external applications, eg.

    - C:\App1\Task1.exe
    - C:\App2\Task2.exe
    - C:\App3\Task3.exe

    It would start the first one and monitor the process details (CPU Usage, Mem Usage, and maybe I/O Writes). Each application will do their jobs for a couple of minutes then go idle - hence completed the task. At this point the CPU Usage = 0, Mem Usage, etc. will be idle.

    Then I need to close/kill that process and start the next application in the list. And this repeats as above and so on.

    Does anyone know how to execute an external program, monitor the process details, then kill it?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    This question is not relevant to a C++ forum. It is windows programming.

    To create a process, look up the win32 API function CreateProcess(). To monitor timing and utilisation information, look up GetProcessTimes() and related functions.

    It is generally quite dangerous to spawn an application, only to wait until it is idle and kill it. Doing that sort of thing increases the chance of spawned applications failing to clean up sensibly after themselves (with results ranging from corruption of data files to causing instability of the operating system). It is usually better to use some form of interprocess communication, so you can tell the application to terminate itself in a clean manner.

    Or, better yet, design the spawned applications so they terminate when their job is done. All you need then is a batch file to run them in sequence.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-27-2011, 10:09 AM
  2. read file details
    By kodithuwa in forum C Programming
    Replies: 1
    Last Post: 11-05-2007, 12:27 AM
  3. Accessing External App's Control Property
    By Hysteresis in forum Windows Programming
    Replies: 2
    Last Post: 09-16-2007, 12:50 PM
  4. Getting Output from an external process
    By radroach in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2005, 07:53 PM
  5. Running External Process from service
    By rotis23 in forum Windows Programming
    Replies: 2
    Last Post: 12-02-2004, 08:56 AM