简体   繁体   English

QProcess :: kill()和QProcess :: terminate()之间有什么区别?

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

I read some documentation but it isn't clear enough to me. 我读了一些文档,但对我来说还不够清楚。 I know that both "end" a process and that kill() is meant to force it to end, but what is terminate() supposed to do then? 我知道两个“结束”进程并且kill()意味着强制它结束,但是终止()应该做什么呢?

Dunno what's not clear if you have written: 不知道你写的是什么还不清楚:

void QProcess::kill() 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. 在Windows上,kill()使用TerminateProcess,在Unix和OS X上,SIGKILL信号被发送到进程。

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


void QProcess::​terminate() void QProcess :: 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). 由于调用此函数,该进程可能无法退出(它有机会提示用户输入任何未保存的文件等)。

On Windows, terminate() posts a WM_CLOSE message to all toplevel windows of the process and then to the main thread of the process itself. 在Windows上,terminate()将WM_CLOSE消息发布到进程的所有顶级窗口,然后发送到进程本身的主线程。 On Unix and OS X the SIGTERM signal is sent. 在Unix和OS X上发送SIGTERM信号。

Console applications on Windows that do not run an event loop, or whose event loop does not handle the WM_CLOSE message, can only be terminated by calling kill(). Windows上没有运行事件循环或其事件循环不处理WM_CLOSE消息的控制台应用程序只能通过调用kill()来终止。

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

So, basically ​terminate() is less brutal, but does not guarantee that process will be terminated. 因此,基本上​terminate()不太残酷,但不保证进程将被终止。

On Unix terminate() uses SIGTERM signal, while kill() sends SIGKILL to the process. 在Unix上, terminate()使用SIGTERM信号,而kill()将SIGKILL发送给进程。 The difference between them is that SIGTERM can be caught by a process, which allows it to perform cleanup etc. SIGTERM can be ignored. 它们之间的区别在于SIGTERM可以被进程捕获,这允许它执行清理等。可以忽略SIGTERM。 SIGKILL will literally kill process, process can not ignore it. SIGKILL将字面上杀死进程,进程不能忽略它。

On Windows WM_CLOSE message is posted, when you call terminate() , so application can also gracefully handle it. 在Windows上发布WM_CLOSE消息,当您调用terminate() ,应用程序也可以正常处理它。 kill() calls TerminateProcess() , which is more or less Windows equvalent of SIGKILL. kill()调用TerminateProcess() ,它或多或少是Windows等价的SIGKILL。

I think terminate() SIGTERM and WM_CLOSE could be handled by Qt and translated into normal Qt events, but you have to try it yourself. 我认为terminate() SIGTERM和WM_CLOSE可以由Qt处理并转换为正常的Qt事件,但你必须自己尝试。 You can of course handle them by system specific functions. 您当然可以通过系统特定的功能来处理它们。


"what causes terminate() to not exit the process." “是什么导致terminate()不退出进程。”

It is you, because you can catch terminate() signals/messages and do whatever you want, or it can be user of your application if he is prompted if he really wants to quit app. 这是你,因为你可以捕获terminate()信号/消息并做任何你想做的事情,或者如果他被提示他是否真的想要退出app,它可以是你的应用程序的用户。 Yet another resource on WM_CLOSE . 另一个关于WM_CLOSE的资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM