1

I'm building a failsafe application for professional video. The Qt application checks the 4 corners of the 2nd screen and if they are a certain RGB value (I use a special background) the Qt program knows it crashed so it sends a signal to the videomixer to fade to the other input.

Now I also want to add a check to see if the video program didn't crash (it can be the video program doesn't respond but still shows an output so I can't see the desktop on the 2nd screen). I know I can use Qprocess to start an external process. It's not that easy to hook it up to a process that already runs.

Now the question: how can I check if the program crashed (so "not responding") and see this as quick as possible so I can fade to the other video input. And what happens when my Qt program crashes, will it also exit the child process?

Thanks!

Jannes
  • 29
  • 9
  • 1
    Do you use linux or windows ? – Adrien BARRAL Jan 27 '14 at 09:51
  • 1
    Do you have the possibility to launch you process with your QT Application in a QProcess ? If yes, your problem will become trivial. – Adrien BARRAL Jan 27 '14 at 09:52
  • I'm using OSX, but I'll also make a windows version. It's possible to launch the the external process with the QT application, but only if I know the external process will run independent from the QT application (so a crash from the QT application won't affect the external process in any way). If the external process crashes when the QT application crashes, I'm not solving the solution of making a 100% safe failsafe but I'm adding an extra factor for crashes – Jannes Jan 27 '14 at 10:33

2 Answers2

1

Using QProcess creates an attached process, so unfortunately it will be killed when your process dies. When you create a detached process using the static method QProcess::startDetached, you don't get the monitoring functionality.

You need to write a little platform-specific monitoring class that can launch a detached process and inform you of changes in its status. You need to use the native APIs in implementing that. QProcess's sources can be a good inspiration for where to start.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
0

@KubaOber is partially correct in his statement. If you start and detach a process indeed you loose the Qt way of communicating with it and monitory what it does. However you OS offers plenty solutions to oversee what happens with it. On Linux you can use:

  • pgrep to check if the process is running or not (execute the command as a child process and see if it returns 0 (process is running) or 1 (process is no longer running)
  • you can use proc filesystem to see when a process terminates (see here) and then use $? or a variable (as in described in the link) to check its exit status
  • kill allows you a great amount of control possibilities along with pipes

You should note however that especially on Windows there are plenty of programs that do not follow the Unix convention for exit codes (0 = exited normally, anything else - error has occurred). Also a crash is just an error state that the process ended up with. The exit code tells you that an error has occurred but in terms of a crash you will probably not be able to make the difference just by looking at it.

Community
  • 1
  • 1
rbaleksandar
  • 8,713
  • 7
  • 76
  • 161