mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
plasma: kill runner optimization
by calling kill() function instead of spawning a process Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
bcb99e3eff
commit
8fb86d0a8c
2 changed files with 17 additions and 27 deletions
|
@ -20,7 +20,6 @@
|
|||
#include "killrunner.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QProcess>
|
||||
#include <KDebug>
|
||||
#include <KIcon>
|
||||
#include <KUser>
|
||||
|
@ -36,10 +35,6 @@ KillRunner::KillRunner(QObject *parent, const QVariantList& args)
|
|||
reloadConfiguration();
|
||||
}
|
||||
|
||||
KillRunner::~KillRunner()
|
||||
{
|
||||
}
|
||||
|
||||
void KillRunner::reloadConfiguration()
|
||||
{
|
||||
#warning TODO: untranslated keyword match, why is it even translated when it is configurable?
|
||||
|
@ -106,16 +101,19 @@ void KillRunner::match(Plasma::RunnerContext &context)
|
|||
|
||||
// Set the relevance
|
||||
switch (m_sorting) {
|
||||
case KillRunnerSort::CPU:
|
||||
case KillRunnerSort::CPU: {
|
||||
match.setRelevance((process->userUsage + process->sysUsage) / 100);
|
||||
break;
|
||||
case KillRunnerSort::CPUI:
|
||||
}
|
||||
case KillRunnerSort::CPUI: {
|
||||
match.setRelevance(1 - (process->userUsage + process->sysUsage) / 100);
|
||||
break;
|
||||
case KillRunnerSort::NONE:
|
||||
}
|
||||
case KillRunnerSort::NONE: {
|
||||
match.setRelevance(name.compare(term, Qt::CaseInsensitive) == 0 ? 1 : 9);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
matches << match;
|
||||
}
|
||||
|
@ -127,28 +125,21 @@ void KillRunner::match(Plasma::RunnerContext &context)
|
|||
void KillRunner::run(const Plasma::QueryMatch &match)
|
||||
{
|
||||
const quint64 pid = match.data().toULongLong();
|
||||
int signal = SIGKILL;
|
||||
int sig = SIGKILL;
|
||||
if (match.selectedAction() != NULL) {
|
||||
signal = match.selectedAction()->data().toInt();
|
||||
sig = match.selectedAction()->data().toInt();
|
||||
}
|
||||
|
||||
QStringList args;
|
||||
args << QString("-%1").arg(signal) << QString::number(pid);
|
||||
|
||||
QProcess killproc(this);
|
||||
killproc.start("kill", args);
|
||||
if (!killproc.waitForFinished() || killproc.exitCode() != 0) {
|
||||
const QString errorstring = QString::fromLocal8Bit(killproc.readAllStandardError());
|
||||
KMessageBox::error(nullptr, errorstring);
|
||||
if (::kill(pid, sig) == -1) {
|
||||
const int savederrno = errno;
|
||||
KMessageBox::error(nullptr, qt_error_string(savederrno));
|
||||
}
|
||||
}
|
||||
|
||||
QList<QAction*> KillRunner::actionsForMatch(const Plasma::QueryMatch &match)
|
||||
{
|
||||
Q_UNUSED(match)
|
||||
|
||||
QList<QAction*> ret;
|
||||
|
||||
if (!action("SIGTERM")) {
|
||||
QAction* action = addAction("SIGTERM", KIcon("application-exit"), i18n("Send SIGTERM"));
|
||||
action->setData(int(SIGTERM));
|
||||
|
|
|
@ -33,7 +33,6 @@ class KillRunner : public Plasma::AbstractRunner
|
|||
|
||||
public:
|
||||
KillRunner(QObject *parent, const QVariantList& args);
|
||||
~KillRunner();
|
||||
|
||||
void match(Plasma::RunnerContext &context);
|
||||
void run(const Plasma::QueryMatch &match);
|
||||
|
|
Loading…
Add table
Reference in a new issue