I'm facing an issue with TerminateProcess() function. The application I'm currently writing a JobScheduler app that schedules and launches job at a specific time. For this purpose, I'm using CreateProcess() to execute my JobLauncher.
The JobLauncher process then launches a console program (using createprocess ) which effectively executes the job executable, waits for its termination and monitors the duration, user and kernel times elapsed etc.
In order to kill the job from the JobScheduler I firstly started using TerminateProcess() but it does not allow me to close the executable itself properly. I mean i found no way to hook any termination event.
Until I find a better way than a brutal TerminateProcess(), I wrote an intermediate solution using the GenerateConsoleCtrlEvent() in the calling program.
In the job application that launches the target job executable, I installed a handler using SetConsoleCtrlHandler(). And in the handler, I can terminate the process of the job and notifies my thirdparties properly. This is the better solution I found for now.
Is there a better way to programmaticaly and properly close a process ? Do you this solution is completly absurd ? I'm not a "system-level" specialist developer though...
Z.