Is it possible from a C or C++ Linux program (say /usr/bin/foo
), to programmatically launch another program (say /usr/bin/bar
), and have foo
exit normally and for bar
to keep running?
system(3)
isn't suitable as it blocks until the other program completes. I'd like something that returns immediately.
The programs are both GUI programs, but I suspect that isn't relevant.
Is there anything in Qt or boost::process that can help?
Is there any common Linux wrapper program I could run through system(3)
to achieve this? I tried xdg-open
but I don't think it's the right thing.
Basically I want the second program to "detach" from the first, and behave as if the user launched it via the system UI. (On MacOS, for example, there is an open
command, so it would be like system("open /usr/bin/bar")
)
With
Qt
, you can usebool QProcess::startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory = QString(), qint64 *pid = nullptr)
as described here https://doc.qt.io/qt-5/qprocess.html#startDetachedHere is a minimal example of how to use it :