Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. QUERY: How to control external exe & read it's process details

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

Scheduled Pinned Locked Moved C / C++ / MFC
databasetutorialquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andwan0
    wrote on last edited by
    #1

    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?

    Richard Andrew x64R A J _ 4 Replies Last reply
    0
    • A andwan0

      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?

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Why can't the program exit by itself once it's done? When you create a process, you can wait on the process handle, and it will signal when the process closes.

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • A andwan0

        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?

        A Offline
        A Offline
        Abhi Lahare
        wrote on last edited by
        #3

        andwan0 wrote:

        Does anyone know how to execute an external program

        CreateProcess[^]

        1 Reply Last reply
        0
        • A andwan0

          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?

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          That isn't ideal of course. The reason is that it isn't deterministic. You don't know it is done but rather you are guessing it. As an example where there could be real problems if one process is relying on an external server and there are network problems it could take a minute for the server to send a response. During which time the process is blocked - and thus not doing anything. At a minimum you are going to need to wait a significant amount of time to be sure it isn't doing anything.

          1 Reply Last reply
          0
          • A andwan0

            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?

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            You can start an application using CreateProcess. If you plan to run the process from a service, you may need to use CreateProcessAsUser or CreateProcessWithLogonW or CreateProcessWithTokenW instead. To monitor a process there are several functions available like GetProcessMemoryInfo, InitializeProcessForWsWatch, GetProcessIoCounters, QueryProcessCycleTime etc. To kill a process, you can use the TerminateProcess function, but this is not recommended as this is an unconditional termination. Instead you must have some sort of built in mechanism in the process for it to terminate itself. This could be by sending a message or by setting an event if you want to control it from a service.

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++)

            Polymorphism in C

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups