File indexing completed on 2024-04-21 05:51:27
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef UNIXPROCESSINFO_H 0008 #define UNIXPROCESSINFO_H 0009 0010 #include "ProcessInfo.h" 0011 0012 #if defined(Q_OS_MACOS) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) 0013 #include <QSharedPointer> 0014 #include <sys/sysctl.h> 0015 #if defined(Q_OS_FREEBSD) || defined(Q_OS_OPEN_BSD) 0016 #include <sys/user.h> 0017 #endif 0018 #endif 0019 0020 namespace Konsole 0021 { 0022 #ifndef Q_OS_WIN 0023 /** 0024 * Implementation of ProcessInfo for Unix platforms which uses 0025 * the /proc filesystem 0026 */ 0027 class UnixProcessInfo : public ProcessInfo 0028 { 0029 public: 0030 /** 0031 * Constructs a new instance of UnixProcessInfo. 0032 * See ProcessInfo::newInstance() 0033 */ 0034 explicit UnixProcessInfo(int pid); 0035 0036 protected: 0037 /** 0038 * Implementation of ProcessInfo::readProcessInfo(); calls the 0039 * four private methods below in turn. 0040 */ 0041 void readProcessInfo(int pid) override; 0042 0043 void readUserName(void) override; 0044 0045 bool readArguments(int pid) override; 0046 0047 #if defined(Q_OS_MACOS) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) 0048 /** 0049 * Allocates an array of struct kinfo_proc and calls sysctl internally to fill it up 0050 * @param managementInfoBase management information base to pass to sysctl 0051 * @param mibCount number of elements in managementInfoBase, also passed as argument to sysctl 0052 * @return smart pointer to struct kinfo_proc[] and returns nullptr on failure 0053 */ 0054 QSharedPointer<struct kinfo_proc> getProcInfoStruct(int *managementInfoBase, int mibCount); 0055 #endif 0056 0057 private: 0058 /** 0059 * Read the standard process information -- PID, parent PID, foreground PID. 0060 * @param pid process ID to use 0061 * @return true on success 0062 */ 0063 virtual bool readProcInfo(int pid) = 0; 0064 }; 0065 #endif 0066 } 0067 0068 #endif