artoon
artoon

Reputation: 739

Initialize QProcess to a process already running

I would like know if it's possible to create a QProcess and initialize it to a process which is already running?

My application starts an other application. So if my application is abnormally closed, when it will be restarted, I would like attach the other application.

Upvotes: 5

Views: 3069

Answers (2)

Unfortunately, due to the internal architecture of QProcess, there's no support for this. You'd need to copy-paste a bunch of QProcess code to a new class and add the missing functionality yourself.

There's an easier way, though: create a process wrapper that exposes a QProcess via QLocalSocket. The wrapper is simple and shouldn't be crashing. It can self-terminate when the process itself terminates, to prevent dangling wrappers from hanging around. When your application crashes or is terminated, the new instance can try to attach to the local socket if a wrapper exists. If it doesn't exist, then it will spawn a new wrapper.

Upvotes: 1

cloose
cloose

Reputation: 956

You should use an IPC system like e.g. Qt D-Bus on Linux. You then communicate with the other process over the IPC system instead of stdin and stdout.

When your frontend application crashes, then the restarted application can reconnect to the backend process.

Upvotes: 1

Related Questions