c – QProcess :: kill()和QProcess :: terminate()之间有什么区别?
作者:互联网
我读了一些文档,但对我来说还不够清楚.我知道两个“结束”进程并且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.
http://doc.qt.io/qt-5/qprocess.html#kill
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. On Unix and OS X the SIGTERM signal is sent.
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().
http://doc.qt.io/qt-5/qprocess.html#terminate
因此,基本上terminate()不太残酷,但不保证进程将被终止.
在Unix上,terminate()使用SIGTERM信号,而kill()将SIGKILL发送给进程.它们之间的区别在于SIGTERM可以被进程捕获,这允许它执行清理等.可以忽略SIGTERM. SIGKILL将字面上杀死进程,进程不能忽略它.
在Windows WM_CLOSE上发布消息,当您调用terminate()时,应用程序也可以正常处理它. kill()调用TerminateProcess(),这或多或少是Windows等价的SIGKILL.
我认为终止()SIGTERM和WM_CLOSE可以由Qt处理并转换为正常的Qt事件,但你必须自己尝试.您当然可以通过系统特定的功能来处理它们.
“是什么导致terminate()不退出进程.”
这是你,因为你可以捕获terminate()信号/消息并做任何你想做的事情,或者如果他被提示他是否真的想要退出app,它可以是你的应用程序的用户. Yet another resource on WM_CLOSE.
标签:qprocess,difference,c,qt 来源: https://codeday.me/bug/20190728/1560219.html