21#if defined(__GLIBC__) && defined(__unix__) || defined(__ANDROID_NDK__)
24 std::ifstream file( fileName );
27 getline(file, buffer);
30 if (buffer.size() > 2 )
31 for(
size_t i= 0 ; i < buffer.size() -2 ; ++i )
32 if ( buffer[i] ==
'\0' )
35 result.
Reset( buffer.c_str() );
43 while ( --fieldNo >= 0 && (result= tknzr.HasNext()) )
46 target.
Reset( tknzr.Next() );
68 NString64 procDir(
"/proc/"); procDir._<NC>(
PID )._(
'/' );
69 integer procPathLen= procDir.Length();
72 procDir <<
"cmdline"; readProcFile( procDir,
CmdLine ); procDir.ShortenTo(procPathLen);
73 procDir <<
"stat"; readProcFile( procDir,
Stat ); procDir.ShortenTo(procPathLen);
80 || (
Name.Length() >= 2
81 &&
Name.CharAtStart<NC>()==
'('
82 &&
Name.CharAtEnd <NC>()==
')' ),
83 "CAMP",
"Error reading process Info" )
85 if (
Name.CharAtEnd () ==
')' )
Name.DeleteEnd <NC>( 1 );
86 if (
Name.CharAtStart() ==
'(' )
Name.DeleteStart<NC>( 1 );
96 ssize_t length= readlink( procDir, buffer, 2048 );
97 procDir.ShortenTo(procPathLen);
103 "Executable path does not contain directory separator character.\n"
114#elif defined (__APPLE__)
122 struct proc_bsdinfo proc;
123 int st = proc_pidinfo(
int(pid), PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE);
124 if (st != PROC_PIDTBSDINFO_SIZE)
132 Name._(
reinterpret_cast<const char*
>( proc.pbi_comm ) );
136 char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
138 if ( proc_pidpath (
int(
PID ), pathbuf, PROC_PIDPATHINFO_MAXSIZE) > 0 )
140 ExecFilePath._(
reinterpret_cast<const char*
>( pathbuf ) );
153#elif defined (_WIN32)
161 DWORD wPID= GetCurrentProcessId();
174 GetModuleFileNameA( NULL, buf, MAX_PATH );
178 "Executable path does not contain directory separator character: ",
184 STARTUPINFOA startupInfo;
185 GetStartupInfoA( &startupInfo );
192 #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>".