TSG
TSG

Reputation: 4617

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?

Upvotes: 1

Views: 676

Answers (2)

kzsnyk
kzsnyk

Reputation: 2211

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.

Upvotes: 0

  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, e.g. is finished.

Upvotes: 3

Related Questions