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
18namespace KProcessList
19{
20class KProcessInfoPrivate;
21
22/**
23 * @brief Contains information about a process. This class is usually not used alone but rather returned by
24 * processInfoList and processInfo. To check if the data contained in this class is valid use the isValid method.
25 * @since 5.58
26 */
27class KCOREADDONS_EXPORT KProcessInfo
28{
29public:
30 KProcessInfo();
31 KProcessInfo(qint64 pid, const QString &command, const QString &user);
32 KProcessInfo(qint64 pid, const QString &command, const QString &name, const QString &user);
33
34 KProcessInfo(const KProcessInfo &other);
35 ~KProcessInfo();
36 KProcessInfo &operator=(const KProcessInfo &other);
37 /**
38 * @brief If the KProcessInfo contains valid information. If it returns true the pid, name and user function
39 * returns valid information, otherwise they return value is undefined.
40 */
41 bool isValid() const;
42 /**
43 * @brief The pid of the process
44 */
45 qint64 pid() const;
46 /**
47 * @brief The name of the process. The class will try to get the full path to the executable file for the process
48 * but if it is not available the name of the process will be used instead.
49 * e.g /bin/ls
50 */
51 QString name() const;
52 /**
53 * @brief The username the process is running under.
54 */
55 QString user() const;
56 /**
57 * @brief The command line running this process
58 * e.g /bin/ls /some/path -R
59 * @since 5.61
60 */
61 QString command() const;
62
63private:
64 QSharedDataPointer<KProcessInfoPrivate> d_ptr;
65};
66
67typedef QList<KProcessInfo> KProcessInfoList;
68
69/**
70 * @brief Retrieves the list of currently active processes.
71 * @since 5.58
72 */
73KCOREADDONS_EXPORT KProcessInfoList processInfoList();
74
75/**
76 * @brief Retrieves process information for a specific process-id. If the process is not found a KProcessInfo with
77 * isValid == false will be returned.
78 * @param pid The process-id to retrieve information for.
79 * @since 5.58
80 */
81KCOREADDONS_EXPORT KProcessInfo processInfo(qint64 pid);
82
83} // KProcessList namespace
84
85Q_DECLARE_TYPEINFO(KProcessList::KProcessInfo, Q_RELOCATABLE_TYPE);
86
87#endif // KPROCESSLIST_H
88

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