1/*
2 This file is part of the KDE Frameworks
3
4 SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies).
5 SPDX-FileCopyrightText: 2019 David Hallas <david@davidhallas.dk>
6
7 SPDX-License-Identifier: LGPL-2.1-only WITH Qt-LGPL-exception-1.1 OR LicenseRef-Qt-Commercial
8*/
9
10#ifndef KPROCESSLIST_H
11#define KPROCESSLIST_H
12
13#include <QList>
14#include <QSharedDataPointer>
15#include <QString>
16#include <kcoreaddons_export.h>
17
18/*!
19 * \namespace KProcessList
20 * \inmodule KCoreAddons
21 */
22namespace KProcessList
23{
24class KProcessInfoPrivate;
25
26/*!
27 * \class KProcessList::KProcessInfo
28 * \inmodule KCoreAddons
29 *
30 * \brief Contains information about a process.
31 *
32 * This class is usually not used alone but rather returned by
33 * processInfoList and processInfo. To check if the data contained in this class is valid use the isValid method.
34 * \since 5.58
35 */
36class KCOREADDONS_EXPORT KProcessInfo
37{
38public:
39 /*!
40 *
41 */
42 KProcessInfo();
43
44 /*!
45 *
46 */
47 KProcessInfo(qint64 pid, const QString &command, const QString &user);
48
49 /*!
50 *
51 */
52 KProcessInfo(qint64 pid, const QString &command, const QString &name, const QString &user);
53
54 KProcessInfo(const KProcessInfo &other);
55 ~KProcessInfo();
56 KProcessInfo &operator=(const KProcessInfo &other);
57 /*!
58 * If the KProcessInfo contains valid information. If it returns true the pid, name and user function
59 * returns valid information, otherwise they return value is undefined.
60 */
61 bool isValid() const;
62 /*!
63 * The pid of the process
64 */
65 qint64 pid() const;
66 /*!
67 * The name of the process.
68 *
69 * The class will try to get the full path to the executable file for the process
70 * but if it is not available the name of the process will be used instead.
71 * e.g /bin/ls
72 */
73 QString name() const;
74 /*!
75 * The username the process is running under.
76 */
77 QString user() const;
78 /*!
79 * The command line running this process
80 * e.g /bin/ls /some/path -R
81 * \since 5.61
82 */
83 QString command() const;
84
85private:
86 QSharedDataPointer<KProcessInfoPrivate> d_ptr;
87};
88
89/*!
90 * \typedef KProcessList::KProcessInfoList
91 */
92typedef QList<KProcessInfo> KProcessInfoList;
93
94/*!
95 * Retrieves the list of currently active processes.
96 * \since 5.58
97 */
98KCOREADDONS_EXPORT KProcessInfoList processInfoList();
99
100/*!
101 * Retrieves process information for a specific process-id. If the process is not found a KProcessInfo with
102 * isValid == false will be returned.
103 *
104 * \a pid The process-id to retrieve information for.
105 *
106 * \since 5.58
107 */
108KCOREADDONS_EXPORT KProcessInfo processInfo(qint64 pid);
109
110} // KProcessList namespace
111
112Q_DECLARE_TYPEINFO(KProcessList::KProcessInfo, Q_RELOCATABLE_TYPE);
113
114#endif // KPROCESSLIST_H
115

source code of kcoreaddons/src/lib/util/kprocesslist.h