File indexing completed on 2024-04-28 05:31:35
0001 /* 0002 SPDX-FileCopyrightText: 2019 David Edmundson <davidedmundson@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QList> 0010 #include <QScopedPointer> 0011 #include <QString> 0012 0013 #include <KService> 0014 0015 #include "processcore_export.h" 0016 0017 namespace KSysGuard 0018 { 0019 class Process; 0020 class CGroupPrivate; 0021 0022 /** 0023 * @brief The CGroup class represents a cgroup. This could be a 0024 * service, slice or scope 0025 */ 0026 class PROCESSCORE_EXPORT CGroup 0027 { 0028 public: 0029 virtual ~CGroup(); 0030 /** 0031 * @brief id 0032 * @return The cgroup ID passed from the constructor 0033 */ 0034 QString id() const; 0035 0036 /** 0037 * @brief Returns metadata about the given service 0038 * Only applicable for .service entries and really only useful for applications. 0039 * This KService object is always valid, but may not correspond to a real desktop entry 0040 * @return 0041 */ 0042 KService::Ptr service() const; 0043 0044 /** 0045 * @brief The list of pids contained in this group. 0046 * @return A Vector of pids 0047 */ 0048 QList<pid_t> pids() const; 0049 0050 /** 0051 * @internal 0052 */ 0053 void setPids(const QList<pid_t> &pids); 0054 0055 /** 0056 * Request fetching the list of processes associated with this cgroup. 0057 * 0058 * This is done in a separate thread. Once it has completed, \p callback is 0059 * called with the list of pids of this cgroup. 0060 * 0061 * It is the callers responsibility to call setPids in response. 0062 * 0063 * \param context An object that is used to track if the caller still exists. 0064 * \param callback A callback that gets called once the list of pids has 0065 * been retrieved. 0066 */ 0067 void requestPids(QObject *context, std::function<void(QList<pid_t>)> callback); 0068 0069 /** 0070 * Returns the base path to exposed cgroup information. Either /sys/fs/cgroup or /sys/fs/cgroup/unified as applicable 0071 * If cgroups are unavailable this will be an empty string 0072 */ 0073 static QString cgroupSysBasePath(); 0074 0075 private: 0076 /** 0077 * Create a new cgroup object for a given cgroup entry 0078 * The id is the fully formed separated path, such as 0079 * "system.slice/dbus.service" 0080 */ 0081 CGroup(const QString &id); 0082 0083 QScopedPointer<CGroupPrivate> d; 0084 friend class CGroupDataModel; 0085 friend class CGroupDataModelPrivate; 0086 }; 0087 0088 }