File indexing completed on 2022-11-23 12:12:12

0001 /*
0002     SPDX-FileCopyrightText: 2009 George Kiagiadakis <gkiagia@users.sourceforge.net>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "detachedprocessmonitor.h"
0007 #include "drkonqi_debug.h"
0008 
0009 #include <chrono>
0010 #include <errno.h>
0011 #include <signal.h>
0012 
0013 #include <QTimerEvent>
0014 
0015 using namespace std::chrono_literals;
0016 
0017 DetachedProcessMonitor::DetachedProcessMonitor(QObject *parent)
0018     : QObject(parent)
0019     , m_pid(0)
0020 {
0021 }
0022 
0023 void DetachedProcessMonitor::startMonitoring(int pid)
0024 {
0025     m_pid = pid;
0026     startTimer(10ms);
0027 }
0028 
0029 void DetachedProcessMonitor::timerEvent(QTimerEvent *event)
0030 {
0031     Q_ASSERT(m_pid != 0);
0032     if (::kill(m_pid, 0) < 0) {
0033         qCDebug(DRKONQI_LOG) << "Process" << m_pid << "finished. kill(2) returned errno:" << errno;
0034         killTimer(event->timerId());
0035         m_pid = 0;
0036         Q_EMIT processFinished();
0037     }
0038 }