ALib C++ Framework
by
Library Version: 2605 R0
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 module \alib_system of the \aliblong.
4///
5/// Copyright 2013-2026 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 // Fields
16 //################################################################################################
17 protected:
18 /// Information on the current process. This is initialized once, with the first invocation
19 /// of #"Current".
21
22 public:
23 /// The process id as AString.
25
26 /// The command-line which invoked this process.
28
29 /// The name of the process.<br> Under GNU/Linux this is read from /proc/nnn/stat and may
30 /// differ from #"ExecFileName". Under Windows OS, it is he same as field #"ExecFileName".
32
33 /// The path of the executable (if available to us).
35
36 /// The file name of the executable (excluding #"ExecFilePath"). Under GNU/Linux,
37 /// if we have no access to read that value, field #"ExecFilePath" will be empty
38 /// while this field is filled with #".Name".
40
41 //################################################################################################
42 // Fields under unix like OS
43 //################################################################################################
44 #if defined( __unix__ ) || DOXYGEN
45
46 /// The parent's process id as AString. (Unix like OS / Mac OS only.)
48
49 /// The contents of /proc/PID/stat file. (Unix like OS only.)
51
52 /// The state field (2) within #"Stat". (Unix like OS only.)
54
55 /// The process group field (4) within #"Stat". (Unix like OS only.)
57 #endif
58
59 //################################################################################################
60 // Fields under Mac OS
61 //################################################################################################
62 #if defined( __APPLE__ )
64 #endif
65
66 //################################################################################################
67 // Fields under Windows OS
68 //################################################################################################
69 #if defined( _WIN32 ) || DOXYGEN
70 public:
71
72 /// For console processes, this is the title displayed in the title bar. (Windows OS only.)
74 #endif
75
76
77 //################################################################################################
78 // Protected methods
79 //################################################################################################
80 protected:
81 /// Default constructor to create an empty instance
83
84
85 #if defined( __unix__ )
86 /// Reads a field from the data found in /proc/PID/stat.
87 /// @param fieldNo The field number to read
88 /// @param target The variable to store the result in
89 /// @returns \c true if successful.
90 bool getStatField( int fieldNo, AString& target );
91 #endif
92
93 /// Internal get() method with different platform implementations.
94 ///
95 /// @param PID The ID of the process information is requested on.
96 /// If a \e nulled string is provided, the current process is addressed.
97 ///
98 /// @return \c true on success, \c false otherwise.
99 ALIB_DLL bool get( uinteger PID );
100
101 //################################################################################################
102 // Interface
103 //################################################################################################
104 public:
105 #if defined( __unix__ ) || defined(__APPLE__)
106 /// Constructor that initializes this instance according to the process information
107 /// received from the system.
108 ///
109 /// \note
110 /// This method is implemented for Unix like OS (incl. Mac OS) only.
111 /// On Windows OS, only information about the current process can be received
112 /// using static method #"Current".
113 ///
114 /// @param processID The ID of the process information is requested on.
115 /// If a \e nulled string is provided, the current process is
116 /// addressed.
117 ProcessInfo( uinteger processID ) { get( processID ); }
118
119 /// Fills the fields of this instance according to the process information received from
120 /// the system.
121 ///
122 /// \note
123 /// This method is implemented for Unix like OS (incl. Mac OS) only.
124 /// On Windows OS, only information about the current process can be received
125 /// using static method #"Current".
126 ///
127 /// @param processID The ID of the process information is requested on.
128 /// If a \e nulled string is provided, the current process is
129 /// addressed.
130 ///
131 /// @return \c true on success, \c false otherwise.
132 ALIB_DLL bool Get( uinteger processID ) { return get( processID ); }
133 #endif
134
135 /// Static method that receives information on the current process.
136 ///
137 /// @return A constant reference to a #"%ProcessInfo" object representing the current process.
138 ALIB_DLL static
139 const ProcessInfo& Current();
140};
141
142} // namespace [ system]
143
144/// Type alias in namespace #"%alib".
146
147} // namespace [alib]
#define ALIB_DLL
#define ALIB_EXPORT
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)
Definition alox.cpp:14
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.hpp:152