mirror of https://github.com/cutefishos/core
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
781 B
C++
32 lines
781 B
C++
#include "utils.h"
|
|
#include <QFile>
|
|
|
|
Utils::Utils(QObject *parent) : QObject(parent)
|
|
{
|
|
|
|
}
|
|
|
|
QString Utils::processNameFromPid(uint pid)
|
|
{
|
|
QFile file(QString("/proc/%1/cmdline").arg(pid));
|
|
QString name;
|
|
|
|
if (file.open(QIODevice::ReadOnly)) {
|
|
QByteArray cmd = file.readAll();
|
|
|
|
if (!cmd.isEmpty()) {
|
|
// extract non-truncated name from cmdline
|
|
int zeroIndex = cmd.indexOf('\0');
|
|
int processNameStart = cmd.lastIndexOf('/', zeroIndex);
|
|
if (processNameStart == -1) {
|
|
processNameStart = 0;
|
|
} else {
|
|
processNameStart++;
|
|
}
|
|
name = QString::fromLocal8Bit(cmd.mid(processNameStart, zeroIndex - processNameStart));
|
|
}
|
|
}
|
|
|
|
return name;
|
|
}
|