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