Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 262
artoon Avatar asked Nov 03 '22 19:11

artoon


2 Answers

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.

like image 54
cloose Avatar answered Nov 15 '22 07:11

cloose


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.

like image 21
Kuba hasn't forgotten Monica Avatar answered Nov 15 '22 05:11

Kuba hasn't forgotten Monica