File indexing completed on 2024-04-28 05:31:39

0001 /*
0002     SPDX-FileCopyrightText: 2007 John Tapsell <tapsell@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef PROCESSES_LOCAL_H_
0008 #define PROCESSES_LOCAL_H_
0009 
0010 #include "processes_base_p.h"
0011 #include <unistd.h> //For sysconf
0012 
0013 #include <QSet>
0014 
0015 namespace KSysGuard
0016 {
0017 class Process;
0018 
0019 /**
0020  * This is the OS specific code to get process information for the local host.
0021  */
0022 class ProcessesLocal : public AbstractProcesses
0023 {
0024 public:
0025     ProcessesLocal();
0026     ~ProcessesLocal() override;
0027     QSet<long> getAllPids() override;
0028     long getParentPid(long pid) override;
0029     bool updateProcessInfo(long pid, Process *process) override;
0030     Processes::Error sendSignal(long pid, int sig) override;
0031     Processes::Error setNiceness(long pid, int priority) override;
0032     Processes::Error setScheduler(long pid, int priorityClass, int priority) override;
0033     long long totalPhysicalMemory() override;
0034     Processes::Error setIoNiceness(long pid, int priorityClass, int priority) override;
0035     bool supportsIoNiceness() override;
0036     long numberProcessorCores() override
0037 #ifdef _SC_NPROCESSORS_ONLN
0038     {
0039         return sysconf(_SC_NPROCESSORS_ONLN);
0040     } // Should work on any recent posix system
0041 #else
0042         ;
0043 #endif
0044     void updateAllProcesses(Processes::UpdateFlags updateFlags) override
0045     {
0046         mUpdateFlags = updateFlags;
0047         emit processesUpdated();
0048     } // For local machine, there is no delay
0049 
0050 private:
0051     /**
0052      * You can use this for whatever data you want.
0053      * Be careful about preserving state in between getParentPid and updateProcessInfo calls
0054      * if you chose to do that. getParentPid may be called several times
0055      * for different pids before the relevant updateProcessInfo calls are made.
0056      * This is because the tree structure has to be sorted out first.
0057      */
0058     class Private;
0059     Private *d;
0060     Processes::UpdateFlags mUpdateFlags;
0061 };
0062 }
0063 #endif