How to detect the appcrash (QProcess)
-
Hi everyone,
as the title says how can I detect an appcrash in windows (the one where the user has to choose 2 options: check solution & close the program, close the program).I am actually making a scheduler program which using an extern application (*.exe), which is not programmed by me and there is no way to debug it. The scheduler program is using an user specified number of QProcess to concurrently execute the tasks and I also implement a synchronization there.
This extern application crash sometimes, which cause the schedule to wait for user input (choose these 2 options: check solution & close the program, close the program). I usually start the schedule over night and expecting the end result to be available on the morning, but this appcrash made the schedule to be stuck :(PS: The crashes is actually can be ignored since from 1000 tasks it will occur 5 times only, which does not reallly alter the end result significantly.
So anyone know the solution for detecting the appcrash?
-
QProcess has multiple signals to do that.
Catch this signal and you should be able to detect a crash of the external app:
@
void QProcess::error(QProcess::ProcessError error) [signal]
@
The ProcessError has a crashed enum value etc.
Greetz -
Hi Jeroentje,
thank you very much for your reply.
I tried it but it still display the crash window, which holds the execution of the next tasks.
I forgot to mention my intention:
What I want is to ignore the error and continue using the process for the next task. Because I want to leave the program running over night (unattended) and expect the end-result on the morning.PS: By ignore I mean kill the process without the user has to take some action (i.e. choosing one of the option).
Any suggestion?
-
Hi,
If you want to suppress the crash dialog.
May be "this":http://blogs.msdn.com/b/alejacma/archive/2011/02/18/how-to-disable-the-pop-up-that-windows-shows-when-an-app-crashes.aspx would help you. -
[quote author="p3c0" date="1382354619"]Hi,
If you want to suppress the crash dialog.
May be "this":http://blogs.msdn.com/b/alejacma/archive/2011/02/18/how-to-disable-the-pop-up-that-windows-shows-when-an-app-crashes.aspx would help you.[/quote]No need for registry hacks, just use SetErrorMode(), probably with SEM_FAILCRITICALERRORS and SEM_NOGPFAULTERRORBOX() flags. You should call this early in your process.
-
Ok. This seems to be a more cleaner example. But will it work for his external process? And also he says the external exe is not programmed by him.
-
If the external EXE is not programmed by him, he cannot do it that way :-(
But he can still do it via Job control!
- Create job object via CreateJobObject()
- Use SetInformationJobObject() with parameter JobObjectBasicLimitInformation
- In the JOBOBJECT_BASIC_LIMIT_INFORMATION struct, set JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION flag
- Assign new process to the job via AssignProcessToJobObject()
__
Important notice:
There's a longstanding bug/limitation in QProcess that prevents Job Control from working properly. AssignProcessToJobObject() will always fail!
You need to include the following fix when compiling Qt:
http://pastie.org/private/krtzp6jzilju6ejv8ppwa -
Hi,
bq. I forgot to mention my intention:
What I want is to ignore the error and continue using the process for the next task. Because I want to leave the program running over night (unattended) and expect the end-result on the morning.by which method have you started the process? I have not seen or missed that :)
I did simple tests with a simulated app's crash and I think what you need to achieve, starting many processes avoiding your app hanging on if one of them crashes and sync finshed() signaling to get a task's result, depends on the method used to start the process: for me it worked with start() but each QProcess must be a different object (not same object starting the same external exe!) ... in this way even for a crashed process you can catch the finished() signal after the error dialog's closing ...
hope it will work for you!
Cheers!