Kill child process on crash
-
Is there a way to ensure that child processes created with QProcess are killed if the main process dies?
-
You could subclass QProcess and give it a new destructor. In the destructor, you check if the process is still running, and if it is, invoke QProcess::kill() on it.
It all depends on how your main process died though. If the process suddenly terminates, there is no way to guarantee that destructor code will run at all. I don't know if there are other ways.
-
I am trying to address the situation where my main process crashes.
-
I guess this is question about Windows platform. On Unixes if you kill QProcess then also all its children will die. On Windows if you kill QProcess - its children keep living. I had to implement custom code using WinAPI to kill also all nested children in such case for win32 platform to have same behavior as on Unixes.
-
I am running windows, mac and linux and none of the platforms seems to kill the child process. I call it a "child process" only because it is started using QProcess from my main process. Could it be that I miss a flag or something to actually make it a "nested child" process?
-
[quote author="Andre" date="1305296276"]Well... you could of course create some kind of monitoring process to do the cleanup for you in case the main process dies, but I think that is overkill. [/quote]
You mean creating a process that check the processes state to cleanup children... ok, also a solution. Here in our software we such stuff but it's a huge product with partly customer apps also running as childs...