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?
-
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?
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.
-
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?
andwan0 wrote:
Does anyone know how to execute an external program
-
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?
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.
-
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?
You can start an application using
CreateProcess
. If you plan to run the process from a service, you may need to useCreateProcessAsUser
orCreateProcessWithLogonW
orCreateProcessWithTokenW
instead. To monitor a process there are several functions available likeGetProcessMemoryInfo
,InitializeProcessForWsWatch
,GetProcessIoCounters
,QueryProcessCycleTime
etc. To kill a process, you can use theTerminateProcess
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.