Added utility getParentName() (name of parent process)

This commit is contained in:
Gerhard Hoffmann 2023-09-04 11:42:12 +02:00
parent 1ef9853876
commit b14b296011
2 changed files with 27 additions and 0 deletions

View File

@ -2,6 +2,8 @@
#include "message_handler.h"
#include "git/git_client.h"
#include "unistd.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
@ -169,3 +171,25 @@ bool Utils::sameFilesInDirs(QDir const &dir1, QDir const &dir2,
return true;
}
QString Utils::getParentName() { // get name of parent process
QString ppid = QString("/proc/%1/status").arg(getppid());
QFile f(ppid);
if (f.exists()) {
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&f);
in.setCodec("UTF-8");
while(!in.atEnd()) {
// Name: ATBQT
QStringList line = in.readLine().split(':');
if (line.size() == 2) {
if (line[0].trimmed() == "Name") {
return line[1].trimmed();
}
}
}
}
}
return "";
}

View File

@ -19,6 +19,9 @@ namespace Utils {
QString rstrip(QString const &str);
bool sameFilesInDirs(QDir const &dir1, QDir const &dir2,
QStringList const &nameFilters = {"*.json"});
QString getParentName();
}
#endif // UTILS_H_INCLUDED