8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol 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
42# if !ALIB_SINGLE_THREADED
72#if defined(__GLIBC__) && defined(__unix__) || defined(__ANDROID_NDK__)
76 std::ifstream file( fileName );
79 getline(file, buffer);
82 if (buffer.size() > 2 )
83 for(
size_t i= 0 ; i < buffer.size() -2 ; ++i )
84 if ( buffer[i] ==
'\0' )
87 result.
Reset( buffer.c_str() );
96 while ( --fieldNo >= 0 && (result= tknzr.HasNext()) )
99 target.
Reset( tknzr.Next() );
123 NString64 procDir(
"/proc/"); procDir._<NC>(
PID )._(
'/' );
124 integer procPathLen= procDir.Length();
127 procDir <<
"cmdline"; readProcFile( procDir,
CmdLine ); procDir.ShortenTo(procPathLen);
128 procDir <<
"stat"; readProcFile( procDir,
Stat ); procDir.ShortenTo(procPathLen);
135 || (
Name.Length() >= 2
136 &&
Name.CharAtStart<NC>()==
'('
137 &&
Name.CharAtEnd <NC>()==
')' ),
138 "CAMP",
"Error reading process Info" )
140 if (
Name.CharAtEnd () ==
')' )
Name.DeleteEnd <NC>( 1 );
141 if (
Name.CharAtStart() ==
'(' )
Name.DeleteStart<NC>( 1 );
151 ssize_t length= readlink( procDir, buffer, 2048 );
152 procDir.ShortenTo(procPathLen);
159 "Executable path does not contain directory separator character.\n"
172#elif defined (__APPLE__)
180 struct proc_bsdinfo proc;
181 int st = proc_pidinfo(
int(pid), PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE);
182 if (st != PROC_PIDTBSDINFO_SIZE)
190 Name._(
reinterpret_cast<const char*
>( proc.pbi_comm ) );
194 char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
196 if ( proc_pidpath (
int(
PID ), pathbuf, PROC_PIDPATHINFO_MAXSIZE) > 0 )
198 ExecFilePath._(
reinterpret_cast<const char*
>( pathbuf ) );
211#elif defined (_WIN32)
219 DWORD wPID= GetCurrentProcessId();
232 GetModuleFileNameA( NULL, buf, MAX_PATH );
236 "Executable path does not contain directory separator character: ",
242 STARTUPINFOA startupInfo;
243 GetStartupInfoA( &startupInfo );
250 #pragma message ("Unknown Platform in file: " __FILE__ )
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.)
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.)
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 IF_ALIB_THREADS(...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_LOCK_WITH(lock)
threads::Lock Lock
Type alias in namespace alib.
NLocalString< 64 > NString64
Type alias name for TLocalString<nchar,64>.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
strings::util::TTokenizer< character > Tokenizer
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
strings::TCString< nchar > NCString
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.