QProcess::terminate() or QProcess::close()
-
My application starts its help viewer on macOS and Linux using QProcess::startDetached().
When my application closes, should I:
- Call QProcess::close() which will kill it? or
- Call QProcess::terminate()
The code currently uses close() :
if (helpProcess && helpProcess->state() == QProcess::Running) { helpProcess->close(); }Thanks, David
-
My application starts its help viewer on macOS and Linux using QProcess::startDetached().
When my application closes, should I:
- Call QProcess::close() which will kill it? or
- Call QProcess::terminate()
The code currently uses close() :
if (helpProcess && helpProcess->state() == QProcess::Running) { helpProcess->close(); }Thanks, David
@Perdrix said in QProcess::terminate() or QProcess::close():
My application starts its help viewer on macOS and Linux using QProcess::startDetached().
Then you can't close or terminate it at all...
And the difference between close() and terminate() are properly documented - but reading seems to be very hard nowadays:
close: Closes all communication with the process and kills it.
terminate: Attempts to terminate the process. The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc). -
@Perdrix said in QProcess::terminate() or QProcess::close():
My application starts its help viewer on macOS and Linux using QProcess::startDetached().
Then you can't close or terminate it at all...
And the difference between close() and terminate() are properly documented - but reading seems to be very hard nowadays:
close: Closes all communication with the process and kills it.
terminate: Attempts to terminate the process. The process may not exit as a result of calling this function (it is given the chance to prompt the user for any unsaved files, etc).@Christian-Ehrlicher Yes, I can read I was asking for advice on which to use.
But given the startDetached and either of those won't play together.
I need to think again...
D.
-
@Christian-Ehrlicher Yes, I can read I was asking for advice on which to use.
But given the startDetached and either of those won't play together.
I need to think again...
D.
@Perdrix
Neither if usingstartDetached(). Of course your Help viewer will outlive your app, if that is not desirable you would need to "kill" it or usestart(). Then you would have to useterminate(), or if you are in control of the Help viewer and want to be smart you could write it to detectclose()and exit it then. -
There is a concept in multi-processing that says you should not "have" to close or terminate a process/thread, but that you should signal it to end gracefully, and catch a status when it is done. ie, the responsibility for ending lies in the child itself, not in the parent, and that close/terminate are only for handlign exceptional error conditions. In some frameworks they haven't even implemented close/terminate.
-
All well and good but that presumes that the process in question accepts input asking it nicely to close (probably on re-directed stdin). In this case the help display process doesn't support that.
I've now changed to use start() instead of startDetached()
-
All well and good but that presumes that the process in question accepts input asking it nicely to close (probably on re-directed stdin). In this case the help display process doesn't support that.
I've now changed to use start() instead of startDetached()
@Perdrix said in QProcess::terminate() or QProcess::close():
All well and good but that presumes that the process in question accepts input asking it nicely to close (probably on re-directed stdin). In this case the help display process doesn't support that.
I've now changed to use start() instead of startDetached()
Actually that's not entirely true. For a normal command line program it would terminate on its own, such as "ls, ps ax, df,...whatever", but in your case it's a little different. The POSIX way to tell a child to die gracefully is to send it a kill signal, which is different from using close/terminate. kill(pid, SIGTERM) kills a process, and can be trapped by the child to do cleanup. But in all fairness the QProcess::close() probably does that implicitly, whereas QProcess::terminate() is not "nice" about it.