diff --git a/processcore/processes_linux_p.cpp b/processcore/processes_linux_p.cpp --- a/processcore/processes_linux_p.cpp +++ b/processcore/processes_linux_p.cpp @@ -29,6 +29,7 @@ #include #include #include +#include //for sysconf #include @@ -630,9 +631,11 @@ errorCode = Processes::InvalidPid; return false; } - if (setpriority( PRIO_PROCESS, pid, priority )) { - switch (errno) { + auto error = + [this] { + switch (errno) { case ESRCH: + case ENOENT: errorCode = Processes::ProcessDoesNotExistOrZombie; break; case EINVAL: @@ -644,10 +647,25 @@ break; default: break; - } - //set niceness failed + } + }; + auto threadList { QDir(QString::fromLatin1("/proc/%1/task").arg(pid)). + entryList( QDir::NoDotAndDotDot | QDir::Dirs ) }; + if (threadList.isEmpty()) { + error(); return false; } + for (auto entry : threadList) { + int threadId = entry.toInt(); + if (!threadId) { + errorCode = Processes::InvalidParameter; + return false; + } + if (setpriority( PRIO_PROCESS, threadId, priority )) { + error(); + return false; + } + } return true; } @@ -687,22 +705,41 @@ return false; } - if (sched_setscheduler( pid, policy, ¶ms) != 0) { - switch (errno) { + auto error = + [this] { + switch (errno) { case ESRCH: + case ENOENT: errorCode = Processes::ProcessDoesNotExistOrZombie; break; case EINVAL: errorCode = Processes::InvalidParameter; break; + case EACCES: case EPERM: errorCode = Processes::InsufficientPermissions; break; default: break; - } + } + }; + auto threadList { QDir(QString::fromLatin1("/proc/%1/task").arg(pid)). + entryList( QDir::NoDotAndDotDot | QDir::Dirs ) }; + if (threadList.isEmpty()) { + error(); return false; } + for (auto entry : threadList) { + int threadId = entry.toInt(); + if (!threadId) { + errorCode = Processes::InvalidParameter; + return false; + } + if (sched_setscheduler( pid, policy, ¶ms) != 0) { + error(); + return false; + } + } return true; }