What's the difference between QProcess :: kill () and QProcess :: terminate ()?

I have read some documentation but it is not clear to me. I know that both "terminate" the process and that kill () is meant to make it terminate, but what does terminate () mean?

+3


source to share


1 answer


I don't know what's not clear if you wrote:

void QProcess :: kill ()

Kills the current process, causing it to exit immediately.

On Windows, kill () uses TerminateProcess, and on Unix and OS X, the SIGKILL signal is sent to the process.

http://doc.qt.io/qt-5/qprocess.html#kill


void QProcess :: terminate ()

An attempt was made to terminate the process.

The process cannot exit due to a call to this function (the ability to prompt the user for any unsaved files, etc. is provided).

On Windows, terminate () sends a WM_CLOSE message to all top-level windows in a process, and then to the main thread of the process itself. On Unix and OS X, the SIGTERM signal is sent.

Console applications on Windows that do not start an event loop, or whose event loop does not process the WM_CLOSE message, can only be terminated by calling kill ().

http://doc.qt.io/qt-5/qprocess.html#terminate

So, mostly ​terminate()

less violent, but doesn't guarantee that the process will end.



On Unix, it terminate()

uses the SIGTERM signal and kill()

sends a SIGKILL to the process. The difference between the two is that SIGTERM can be captured by a process that allows cleanup, etc. SIGTERM can be ignored. SIGKILL will literally kill the process, the process cannot ignore it.

On Windows, the WM_CLOSE message is sent when you call terminate()

, so the application can handle it gracefully as well. kill()

calls TerminateProcess () , which is more or less equal to Windows SIGKILL.

I think terminate()

SIGTERM and WM_CLOSE can be handled by Qt and broadcast to regular Qt events, but you should try it yourself. Of course, you can handle them using special system functions.


", which leads to termination () so as not to exit the process.

It is you because you can catch terminate()

signals / messages and do whatever you want, or it could be the user of your application if prompted if he really wants to exit the application. Another resource is WM_CLOSE .

+7


source







All Articles