Kill child process of QProcess
I have a problem about the killing of child processes of a QProcess instance. The issue is the following:
In my GUI appclication I have a QProcess instance, which deployed by a user interaction. The started process starts other child processes as well.
When the user presses the button "Stop", I trigger the "kill" slot of the QProcess, so the process will be killed, but its chiled processes stay there (I check it in the Windows task manager).
Does anybody have a tip, how can I kill the whole process tree?
The problem is that you kill the process but you do not shut off gracefully. The process does not have a chance to cleanup.
You may want to try "terminate()":http://qt-project.org/doc/qt-5/qprocess.html#terminate instead. This slot tries to shut-down a process gracefully. However, it may not work for all processes started (e.g. command line processes).
yes, doesn't help me: my started processes are console applications.
Is there any sollution to list the deployed chiled processes of my QProcess instance or any other solution?
Not that I am aware of.
The OS would have to support this. Possibly you can use "sysinternals":http://technet.microsoft.com/en-us/sysinternals/bb896682 and do some significant wrapping around.
Are we talking about Windows here? Windows does not really have the concept of a process hierarchy, like Linux has. So killing the "parent" process, will not kill the "child" processes it has created. Still, you can find out by which process a specific process had been created. So if you which to kill all "child" processes of process XYZ, you will have to filter all running processes and then kill those that had been created by XYZ. This will require going down to the Win32 API. Use CreateToolhelp32Snapshot to create a snapshot and then iterate trough the process list via Process32First and Process32Next.
The "th32ParentProcessID" field is what you are interested in ;-)