File indexing completed on 2024-05-19 03:56:25
0001 /* 0002 This file is part of the KDE Frameworks 0003 0004 SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). 0005 SPDX-FileCopyrightText: 2019 David Hallas <david@davidhallas.dk> 0006 0007 SPDX-License-Identifier: LGPL-2.1-only WITH Qt-LGPL-exception-1.1 OR LicenseRef-Qt-Commercial 0008 */ 0009 0010 #ifndef KPROCESSLIST_H 0011 #define KPROCESSLIST_H 0012 0013 #include <QList> 0014 #include <QSharedDataPointer> 0015 #include <QString> 0016 #include <kcoreaddons_export.h> 0017 0018 namespace KProcessList 0019 { 0020 class KProcessInfoPrivate; 0021 0022 /** 0023 * @brief Contains information about a process. This class is usually not used alone but rather returned by 0024 * processInfoList and processInfo. To check if the data contained in this class is valid use the isValid method. 0025 * @since 5.58 0026 */ 0027 class KCOREADDONS_EXPORT KProcessInfo 0028 { 0029 public: 0030 KProcessInfo(); 0031 KProcessInfo(qint64 pid, const QString &command, const QString &user); 0032 KProcessInfo(qint64 pid, const QString &command, const QString &name, const QString &user); 0033 0034 KProcessInfo(const KProcessInfo &other); 0035 ~KProcessInfo(); 0036 KProcessInfo &operator=(const KProcessInfo &other); 0037 /** 0038 * @brief If the KProcessInfo contains valid information. If it returns true the pid, name and user function 0039 * returns valid information, otherwise they return value is undefined. 0040 */ 0041 bool isValid() const; 0042 /** 0043 * @brief The pid of the process 0044 */ 0045 qint64 pid() const; 0046 /** 0047 * @brief The name of the process. The class will try to get the full path to the executable file for the process 0048 * but if it is not available the name of the process will be used instead. 0049 * e.g /bin/ls 0050 */ 0051 QString name() const; 0052 /** 0053 * @brief The username the process is running under. 0054 */ 0055 QString user() const; 0056 /** 0057 * @brief The command line running this process 0058 * e.g /bin/ls /some/path -R 0059 * @since 5.61 0060 */ 0061 QString command() const; 0062 0063 private: 0064 QSharedDataPointer<KProcessInfoPrivate> d_ptr; 0065 }; 0066 0067 typedef QList<KProcessInfo> KProcessInfoList; 0068 0069 /** 0070 * @brief Retrieves the list of currently active processes. 0071 * @since 5.58 0072 */ 0073 KCOREADDONS_EXPORT KProcessInfoList processInfoList(); 0074 0075 /** 0076 * @brief Retrieves process information for a specific process-id. If the process is not found a KProcessInfo with 0077 * isValid == false will be returned. 0078 * @param pid The process-id to retrieve information for. 0079 * @since 5.58 0080 */ 0081 KCOREADDONS_EXPORT KProcessInfo processInfo(qint64 pid); 0082 0083 } // KProcessList namespace 0084 0085 Q_DECLARE_TYPEINFO(KProcessList::KProcessInfo, Q_RELOCATABLE_TYPE); 0086 0087 #endif // KPROCESSLIST_H