简体   繁体   中英

QThread::terminate vs kill

I have a BASH script run (QProcess blocking) in a QThread (in C++). This BASH script tars lots of files and can run for 1/2 hour.

In case the user wants to shutdown my program I need to kill my BASH script. But how? QThread::Quit will wait for the BASH program to terminate before processing signals, QThread::Terminate documentation says it MAY kill a thread immediately.

I want the equivalent of 'kill -9 myscript'. Is there a proper Qt way to do this?

  1. Do not use additional threads. It's never necessary.
  2. Never use any waitForXxx methods.
  3. Use QProcess::kill to kill the process.
  4. Use QProcess 's signals to get notified when the process changes state, eg is finished.

I want the equivalent of 'kill -9 myscript'. Is there a proper Qt way to do this ?

from the Qt's doc http://doc.qt.io/qt-5/qprocess.html#kill :

void QProcess::kill()

Kills the current process, causing it to exit immediately.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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