ALib C++ Framework
by
Library Version: 2511 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 #"mainpage_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 #"Stat". (Unix like OS only.)
55
56 /// The process group field (4) within #"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 /// Default constructor to create an empty instance
84
85
86 #if defined( __unix__ )
87 /// Reads a field from the data found in /proc/PID/stat.
88 /// @param fieldNo The field number to read
89 /// @param target The variable to store the result in
90 /// @returns \c true if successful.
91 bool getStatField( int fieldNo, AString& target );
92 #endif
93
94 /// Internal get() method with different platform implementations.
95 ///
96 /// @param PID The ID of the process information is requested on.
97 /// If a \e nulled string is provided, the current process is addressed.
98 ///
99 /// @return \c true on success, \c false otherwise.
100 ALIB_DLL bool get( uinteger PID );
101
102 //################################################################################################
103 // Interface
104 //################################################################################################
105 public:
106 #if defined( __unix__ ) || defined(__APPLE__)
107 /// Constructor that initializes this instance according to the process information
108 /// received from the system.
109 ///
110 /// \note
111 /// This method is implemented for Unix like OS (incl. Mac OS) only.
112 /// On Windows OS, only information about the current process can be received
113 /// using static method #"Current".
114 ///
115 /// @param processID The ID of the process information is requested on.
116 /// If a \e nulled string is provided, the current process is
117 /// addressed.
118 ProcessInfo( uinteger processID ) { get( processID ); }
119
120 /// Fills the fields of this instance according to the process information received from
121 /// the system.
122 ///
123 /// \note
124 /// This method is implemented for Unix like OS (incl. Mac OS) only.
125 /// On Windows OS, only information about the current process can be received
126 /// using static method #"Current".
127 ///
128 /// @param processID The ID of the process information is requested on.
129 /// If a \e nulled string is provided, the current process is
130 /// addressed.
131 ///
132 /// @return \c true on success, \c false otherwise.
133 ALIB_DLL bool Get( uinteger processID ) { return get( processID ); }
134 #endif
135
136 /// Static method that receives information on the current process.
137 ///
138 /// @return A constant reference to a \c %ProcessInfo object representing the current process.
139 ALIB_DLL static
140 const ProcessInfo& Current();
141};
142
143} // namespace [ system]
144
145/// Type alias in namespace \b alib.
147
148} // namespace [alib]
#define ALIB_DLL
Definition alib.inl:573
#define ALIB_EXPORT
Definition alib.inl:562
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)
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.).
static ProcessInfo current
uinteger PID
The process id as AString.
static const ProcessInfo & Current()
bool Get(uinteger processID)
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)
system::ProcessInfo ProcessInfo
Type alias in namespace alib.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
Definition integers.inl:152