ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
processinfo.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_system of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace system {
9
10//==================================================================================================
11/// This class represents process information
12//==================================================================================================
14{
15 // #############################################################################################
16 // Fields
17 // #############################################################################################
18 protected:
19 /// Information on the current process. This is initialized once, with the first invocation
20 /// of #Current.
22
23 public:
24 /// The process id as AString.
26
27 /// The command line which invoked this process.
29
30 /// The name of the process.<br> Under GNU/Linux this is read from /proc/nnn/stat and may
31 /// differ from #ExecFileName. Under Windows OS, it is he same as field #ExecFileName.
33
34 /// The path of the executable (if available to us).
36
37 /// The file name of the executable (excluding #ExecFilePath). Under GNU/Linux,
38 /// if we have no access to read that value, field #ExecFilePath will be empty
39 /// while this field is filled with #Name.
41
42 // #############################################################################################
43 // Fields under unix like OS
44 // #############################################################################################
45 #if defined( __unix__ ) || DOXYGEN
46
47 /// The parent's process id as AString. (Unix like OS / Mac OS only.)
49
50 /// The contents of /proc/PID/stat file. (Unix like OS only.)
52
53 /// The state field (2) within \ref Stat. (Unix like OS only.)
55
56 /// The process group field (4) within \ref Stat. (Unix like OS only.)
58 #endif
59
60 // #############################################################################################
61 // Fields under Mac OS
62 // #############################################################################################
63 #if defined( __APPLE__ )
65 #endif
66
67 // #############################################################################################
68 // Fields under Windows OS
69 // #############################################################################################
70 #if defined( _WIN32 ) || DOXYGEN
71 public:
72
73 /// For console processes, this is the title displayed in the title bar. (Windows OS only.)
75 #endif
76
77
78 // #############################################################################################
79 // Protected methods
80 // #############################################################################################
81 protected:
82 //==========================================================================================
83 /// Default constructor to create an empty instance
84 //==========================================================================================
86
87
88 #if defined( __unix__ )
89 //======================================================================================
90 /// Reads a field from the data found in /proc/PID/stat.
91 /// @param fieldNo The field number to read
92 /// @param target The variable to store the result in
93 /// @returns \c true if successful.
94 //======================================================================================
95 bool getStatField( int fieldNo, AString& target );
96 #endif
97
98 //==========================================================================================
99 /// Internal get() method with different platform implementations.
100 ///
101 /// @param PID The ID of the process information is requested on.
102 /// If a \e nulled string is provided, the current process is addressed.
103 ///
104 /// @return \c true on success, \c false otherwise.
105 //==========================================================================================
106 ALIB_DLL bool get( uinteger PID );
107
108 // #############################################################################################
109 // Interface
110 // #############################################################################################
111 public:
112 #if defined( __unix__ ) || defined(__APPLE__)
113 //======================================================================================
114 /// Constructor that initializes this instance according to the process information
115 /// received from the system.
116 ///
117 /// \note
118 /// This method is implemented for Unix like OS (incl. Mac OS) only.
119 /// On Windows OS, only information about the current process can be received
120 /// using static method #Current.
121 ///
122 /// @param processID The ID of the process information is requested on.
123 /// If a \e nulled string is provided, the current process is
124 /// addressed.
125 //======================================================================================
126 ProcessInfo( uinteger processID ) { get( processID ); }
127
128 //======================================================================================
129 /// Fills the fields of this instance according to the process information received from
130 /// the system.
131 ///
132 /// \note
133 /// This method is implemented for Unix like OS (incl. Mac OS) only.
134 /// On Windows OS, only information about the current process can be received
135 /// using static method #Current.
136 ///
137 /// @param processID The ID of the process information is requested on.
138 /// If a \e nulled string is provided, the current process is
139 /// addressed.
140 ///
141 /// @return \c true on success, \c false otherwise.
142 //======================================================================================
143 ALIB_DLL bool Get( uinteger processID ) { return get( processID ); }
144 #endif
145
146 //==========================================================================================
147 /// Static method that receives information on the current process.
148 ///
149 /// @return A constant reference to a \c %ProcessInfo object representing the current process.
150 //==========================================================================================
151 ALIB_DLL static
152 const ProcessInfo& Current();
153};
154
155} // namespace [ system]
156
157/// Type alias in namespace \b alib.
159
160} // namespace [alib]
161
162
This class represents process information.
AString StatPGRP
The process group field (4) within Stat. (Unix like OS only.)
ProcessInfo()
Default constructor to create an empty instance.
AString Stat
The contents of /proc/PID/stat file. (Unix like OS only.)
ProcessInfo(uinteger processID)
ALIB_DLL bool get(uinteger PID)
uinteger PPID
The parent's process id as AString. (Unix like OS / Mac OS only.)
AString ExecFilePath
The path of the executable (if available to us).
AString StatState
The state field (2) within Stat. (Unix like OS only.)
ALIB_DLL bool Get(uinteger processID)
static ALIB_DLL ProcessInfo current
uinteger PID
The process id as AString.
static ALIB_DLL const ProcessInfo & Current()
AString CmdLine
The command line which invoked this process.
AString ConsoleTitle
For console processes, this is the title displayed in the title bar. (Windows OS only....
bool getStatField(int fieldNo, AString &target)
#define ALIB_DLL
Definition alib.inl:496
#define ALIB_EXPORT
Definition alib.inl:488
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
system::ProcessInfo ProcessInfo
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.inl:152