diff options
author | Andrew Christian <andrew.christian@nokia.com> | 2012-02-08 07:53:54 -0500 |
---|---|---|
committer | Chris Craig <ext-chris.craig@nokia.com> | 2012-02-08 15:10:31 +0100 |
commit | 458c47468386fa51c20f862561d50dcbd05da15b (patch) | |
tree | 869619d951afe7e354cf6136cfeef035a91d26cb | |
parent | c315c08527e2de7d4f252874b2a1833cc319df87 (diff) |
Terminate process group on destruction
Change-Id: If07998eadea1f1f36d6b2cf7522476d3a28eb8b6
Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
-rw-r--r-- | src/core/unixprocessbackend.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/core/unixprocessbackend.cpp b/src/core/unixprocessbackend.cpp index 100cfc0..48b4cc8 100644 --- a/src/core/unixprocessbackend.cpp +++ b/src/core/unixprocessbackend.cpp @@ -44,11 +44,22 @@ #include "procutils.h" #include <sys/resource.h> #include <errno.h> +#include <signal.h> #include <QDebug> #include <QFile> QT_BEGIN_NAMESPACE_PROCESSMANAGER +static void sendSignalToProcess(pid_t pid, int sig) +{ + pid_t pgrp = ::getpgid(pid); + if (pgrp != -1 && ::killpg(pgrp, sig) == 0) + return; + + qWarning("Unable terminate process group: %d, switching to process %d", pgrp, pid); + ::kill(pid, sig); +} + /*! \class UnixProcessBackend \brief The UnixProcessBackend class wraps a QProcess object @@ -67,10 +78,13 @@ UnixProcessBackend::UnixProcessBackend(const ProcessInfo& info, QObject *parent) /*! Destroy this process object. Any created QProcess is a child of this object, so it will be automatically terminated. + We have to do some special processing to terminate the process group. */ UnixProcessBackend::~UnixProcessBackend() { + if (m_process && m_process->state() != QProcess::NotRunning) + sendSignalToProcess(m_process->pid(), SIGKILL); } /*! @@ -221,11 +235,12 @@ void UnixProcessBackend::stop(int timeout) if (m_process->state() != QProcess::NotRunning) { if (timeout > 0) { - m_process->terminate(); + sendSignalToProcess(m_process->pid(), SIGTERM); m_killTimer.start(timeout); - } - else - m_process->kill(); + } + else { + sendSignalToProcess(m_process->pid(), SIGKILL); + } } } |