views:

132

answers:

2

We're preparing an application using Qt that has a main process that controls the GUI and spawns processes that do the actual data processing. Messages are exchanged between the main process and the data-processing processes using the Qt mechanisms and the stdin/stdout pipes.

Now, in the event that the GUI crashes, the other processes keep running. What we'd like to be able to do is to, when a new GUI starts, reconnect to these processes as before. Anyone know if this is possible, and if so, how to achieve it?

+1  A: 

This is possible if you are using a named pipe for communicating with the process. stdin/out are closed if the process they belong to is terminated.

drhirsch
Except that the QProcess class object handles the stdin/stdout/stderr pipes internally. In order to use "named pipes" instead, the QProcess class would have to be modified, which I'd rather avoid.
Gamma Draconis
You didn't state that you need to use QProcess. In this case, create a proxy process with your GUI app via QProcess. The proxy stays up as long as your GUI app. It communicates to your GUI with QProcess::read()/write(). This proxy creates the named pipe and starts the worker process and connects the pipe to stdin/out of the worker. It also restarts the worker if it dies. The proxy could probably be something simple as a small shell script.
drhirsch
A: 

You might want to investigate shared memory for the communication between processes. I seem to recall that it was able to recover in a very similar situation at a previous job.

Another possibility, if your platform supports it, is to use dbus for the communication between processes. If that is the case, neither process would have to be there, but will act get the appropriate messages if it is running.

Caleb Huitt - cjhuitt