I'm looking to build a task monitor/manager using the Win32 API. It will be started (preferably as a windows service) with a command line argument specifying how many instances of a new process it should start.
task_man.exe 40
Will start 40 instances of the process
task.exe
Now, whenever a task.exe exits (correctly or not), I will have to start a new one to replace it.
My rough idea is this:
Start the tasks from task_man, get their PIDs, and then have a loop that checks whether the PIDs are all active processes. For every invalid PID, start a new process and replace the old PID with the new one.
Is there a better design I can use, or a better workflow? Is there a standard method for doing this? I don't want to reinvent the wheel... Also, which APIs should I look into?
I'm also looking for a design that is easy to change afterwards - i.e. if I run
task_man.exe 30
afterwards, a new task_man shouldn't start running, but rather it should change the number of tasks in the previous instance. (I know it will start running, what I'm saying it should modify the original and then exit)
I'm not looking for code (as in I'm not looking for the full implementation, not that I mind looking over samples), rather what APIs I can use, or suggestions on the overall design I came up with.
The easiest way to tell if a process has exited is to wait on its handle. You can do that in a few ways: