KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
procutil.h
1/**
2 * @brief Static utilities for querying running Linux processes via /proc.
3 */
4#ifndef PROCUTIL_H
5#define PROCUTIL_H
6
7#include <QStringList>
8#include <Kanoop/kanoopcommon.h>
9
10/**
11 * @brief Static helper methods for enumerating and inspecting running processes.
12 *
13 * Reads process information from the Linux /proc filesystem.
14 */
15class KANOOP_EXPORT ProcUtil
16{
17public:
18 /**
19 * @brief Return the names of all running processes.
20 * @return List of process name strings
21 */
22 static QStringList runningProcessNames();
23
24 /**
25 * @brief Return the PIDs of all running processes.
26 * @return List of process ID integers
27 */
28 static QList<int> runningPids();
29
30 /**
31 * @brief Return the process name for a given PID.
32 * @param pid Process ID to look up
33 * @return Process name string, or empty string if not found
34 */
35 static QString processNameFromPid(int pid);
36
37private:
38 /** @brief Read a key-value field from a process's /proc/<pid>/status file. */
39 static QString readProcStatusString(int pid, const QString& key);
40 /** @brief Read a key-value field from a proc filesystem file. */
41 static QString readProcFileString(const QString& filename, const QString& key);
42 /** @brief Read the command-line tokens of a process. */
43 static QStringList readProcCommandLine(int pid);
44 /** @brief Extract the process name from a command-line string. */
45 static QString processNameFromCommandLine(const QString& commandLine);
46
47 static const QString ProcDir;
48 static const QString CmdLine;
49};
50
51#endif // PROCUTIL_H
Static utilities for querying running Linux processes via /proc.
Definition procutil.h:16
static QList< int > runningPids()
Return the PIDs of all running processes.
static QString processNameFromPid(int pid)
Return the process name for a given PID.
static QStringList runningProcessNames()
Return the names of all running processes.