8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Configuration MACRO ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
17# if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION) || defined(__ANDROID_NDK__)
19# if defined(__APPLE__)
21# include <sys/sysctl.h>
24# elif defined( _WIN32 )
27# pragma message ("Unknown Platform in file: " __FILE__ )
35# if !ALIB_SINGLE_THREADED
39 import ALib.Strings.Tokenizer;
42# if !ALIB_SINGLE_THREADED
70#if defined(__GLIBC__) && defined(__unix__) || defined(__ANDROID_NDK__)
73 std::ifstream file( fileName );
76 getline(file, buffer);
79 if (buffer.size() > 2 )
80 for(
size_t i= 0 ; i < buffer.size() -2 ; ++i )
81 if ( buffer[i] ==
'\0' )
84 result.
Reset( buffer.c_str() );
92 while ( --fieldNo >= 0 && (result= tknzr.HasNext()) )
95 target.
Reset( tknzr.Next() );
117 NString64 procDir(
"/proc/"); procDir._<NC>(
PID )._(
'/' );
118 integer procPathLen= procDir.Length();
121 procDir <<
"cmdline"; readProcFile( procDir,
CmdLine ); procDir.ShortenTo(procPathLen);
122 procDir <<
"stat"; readProcFile( procDir,
Stat ); procDir.ShortenTo(procPathLen);
129 || (
Name.Length() >= 2
130 &&
Name.CharAtStart<NC>()==
'('
131 &&
Name.CharAtEnd <NC>()==
')' ),
132 "CAMP",
"Error reading process Info" )
134 if (
Name.CharAtEnd () ==
')' )
Name.DeleteEnd <NC>( 1 );
135 if (
Name.CharAtStart() ==
'(' )
Name.DeleteStart<NC>( 1 );
145 ssize_t length= readlink( procDir, buffer, 2048 );
146 procDir.ShortenTo(procPathLen);
152 "Executable path does not contain directory separator character.\n"
163#elif defined (__APPLE__)
171 struct proc_bsdinfo proc;
172 int st = proc_pidinfo(
int(pid), PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE);
173 if (st != PROC_PIDTBSDINFO_SIZE)
181 Name._(
reinterpret_cast<const char*
>( proc.pbi_comm ) );
185 char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
187 if ( proc_pidpath (
int(
PID ), pathbuf, PROC_PIDPATHINFO_MAXSIZE) > 0 )
189 ExecFilePath._(
reinterpret_cast<const char*
>( pathbuf ) );
202#elif defined (_WIN32)
210 DWORD wPID= GetCurrentProcessId();
223 GetModuleFileNameA( NULL, buf, MAX_PATH );
227 "Executable path does not contain directory separator character: ",
233 STARTUPINFOA startupInfo;
234 GetStartupInfoA( &startupInfo );
241 #pragma message ("Unknown Platform in file: " __FILE__ )
#define IF_ALIB_THREADS(...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_LOCK_WITH(lock)
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.).
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()
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)
threads::Lock Lock
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
strings::TCString< nchar > NCString
Type alias in namespace alib.
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
NLocalString< 64 > NString64
Type alias name for #"TLocalString;TLocalString<nchar,64>".