Changeset View
Changeset View
Standalone View
Standalone View
processcore/processes_linux_p.cpp
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 104 | { | |||
---|---|---|---|---|---|
107 | { | 107 | { | ||
108 | public: | 108 | public: | ||
109 | Private() { mProcDir = opendir( "/proc" );} | 109 | Private() { mProcDir = opendir( "/proc" );} | ||
110 | ~Private(); | 110 | ~Private(); | ||
111 | inline bool readProcStatus(const QString &dir, Process *process); | 111 | inline bool readProcStatus(const QString &dir, Process *process); | ||
112 | inline bool readProcStat(const QString &dir, Process *process); | 112 | inline bool readProcStat(const QString &dir, Process *process); | ||
113 | inline bool readProcStatm(const QString &dir, Process *process); | 113 | inline bool readProcStatm(const QString &dir, Process *process); | ||
114 | inline bool readProcCmdline(const QString &dir, Process *process); | 114 | inline bool readProcCmdline(const QString &dir, Process *process); | ||
115 | inline bool readProcCGroup(const QString &dir, Process *process); | ||||
115 | inline bool getNiceness(long pid, Process *process); | 116 | inline bool getNiceness(long pid, Process *process); | ||
116 | inline bool getIOStatistics(const QString &dir, Process *process); | 117 | inline bool getIOStatistics(const QString &dir, Process *process); | ||
117 | QFile mFile; | 118 | QFile mFile; | ||
118 | char mBuffer[PROCESS_BUFFER_SIZE+1]; //used as a buffer to read data into | 119 | char mBuffer[PROCESS_BUFFER_SIZE+1]; //used as a buffer to read data into | ||
119 | DIR* mProcDir; | 120 | DIR* mProcDir; | ||
120 | }; | 121 | }; | ||
121 | 122 | | |||
122 | ProcessesLocal::Private::~Private() | 123 | ProcessesLocal::Private::~Private() | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 133 | { | |||
195 | } | 196 | } | ||
196 | } | 197 | } | ||
197 | 198 | | |||
198 | finish: | 199 | finish: | ||
199 | mFile.close(); | 200 | mFile.close(); | ||
200 | return true; | 201 | return true; | ||
201 | } | 202 | } | ||
202 | 203 | | |||
204 | bool ProcessesLocal::Private::readProcCGroup(const QString &dir, Process *process) | ||||
205 | { | ||||
206 | mFile.setFileName(dir + QStringLiteral("cgroup")); | ||||
207 | if(!mFile.open(QIODevice::ReadOnly)) | ||||
208 | return false; /* process has terminated in the meantime */ | ||||
209 | | ||||
210 | while( mFile.readLine( mBuffer, sizeof(mBuffer)) > 0) { //-1 indicates an error | ||||
211 | if ( mBuffer[0] == '0' && mBuffer[1] == ':' && mBuffer[2] == ':' ) { | ||||
212 | process->setCGroup(QString::fromLocal8Bit(&mBuffer[3])); | ||||
213 | break; | ||||
214 | } | ||||
215 | } | ||||
216 | mFile.close(); | ||||
217 | return true; | ||||
218 | } | ||||
219 | | ||||
203 | long ProcessesLocal::getParentPid(long pid) { | 220 | long ProcessesLocal::getParentPid(long pid) { | ||
204 | if (pid <= 0) | 221 | if (pid <= 0) | ||
205 | return -1; | 222 | return -1; | ||
206 | d->mFile.setFileName(QStringLiteral("/proc/") + QString::number(pid) + QStringLiteral("/stat")); | 223 | d->mFile.setFileName(QStringLiteral("/proc/") + QString::number(pid) + QStringLiteral("/stat")); | ||
207 | if(!d->mFile.open(QIODevice::ReadOnly)) | 224 | if(!d->mFile.open(QIODevice::ReadOnly)) | ||
208 | return -1; /* process has terminated in the meantime */ | 225 | return -1; /* process has terminated in the meantime */ | ||
209 | 226 | | |||
210 | int size; //amount of data read in | 227 | int size; //amount of data read in | ||
▲ Show 20 Lines • Show All 308 Lines • ▼ Show 20 Line(s) | |||||
519 | bool ProcessesLocal::updateProcessInfo( long pid, Process *process) | 536 | bool ProcessesLocal::updateProcessInfo( long pid, Process *process) | ||
520 | { | 537 | { | ||
521 | bool success = true; | 538 | bool success = true; | ||
522 | QString dir = QStringLiteral("/proc/") + QString::number(pid) + QLatin1Char('/'); | 539 | QString dir = QStringLiteral("/proc/") + QString::number(pid) + QLatin1Char('/'); | ||
523 | if(!d->readProcStat(dir, process)) success = false; | 540 | if(!d->readProcStat(dir, process)) success = false; | ||
524 | if(!d->readProcStatus(dir, process)) success = false; | 541 | if(!d->readProcStatus(dir, process)) success = false; | ||
525 | if(!d->readProcStatm(dir, process)) success = false; | 542 | if(!d->readProcStatm(dir, process)) success = false; | ||
526 | if(!d->readProcCmdline(dir, process)) success = false; | 543 | if(!d->readProcCmdline(dir, process)) success = false; | ||
544 | if(!d->readProcCGroup(dir, process)) success = false; | ||||
527 | if(!d->getNiceness(pid, process)) success = false; | 545 | if(!d->getNiceness(pid, process)) success = false; | ||
528 | if(mUpdateFlags.testFlag(Processes::IOStatistics) && !d->getIOStatistics(dir, process)) success = false; | 546 | if(mUpdateFlags.testFlag(Processes::IOStatistics) && !d->getIOStatistics(dir, process)) success = false; | ||
529 | 547 | | |||
530 | return success; | 548 | return success; | ||
531 | } | 549 | } | ||
532 | 550 | | |||
533 | QSet<long> ProcessesLocal::getAllPids( ) | 551 | QSet<long> ProcessesLocal::getAllPids( ) | ||
534 | { | 552 | { | ||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |