10#if !defined(HPP_ALIB_CAMP_PROCESSINFO)
14#if !defined(HPP_ALIB_STRINGS_UTIL_TOKENIZER)
18#if ALIB_THREADS && !defined(HPP_ALIB_THREADS_THREADLOCKNR)
21#if !defined(HPP_ALIB_CAMP_MESSAGE_REPORT)
25#if defined(__GLIBCXX__) || defined(__ANDROID_NDK__)
27#elif defined(__APPLE__)
29 #include <sys/sysctl.h>
32#elif defined( _WIN32 )
35 #pragma message ("Unknown Platform in file: " __FILE__ )
38#if !defined(_GLIBCXX_FSTREAM) && !defined(_FSTREAM_)
45namespace alib {
namespace lang::system {
66#if defined(__GLIBC__) && defined(__unix__) || defined(__ANDROID_NDK__)
70 std::ifstream file( fileName );
73 getline(file, buffer);
76 if (buffer.size() > 2 )
77 for(
size_t i= 0 ; i < buffer.size() -2 ; ++i )
78 if ( buffer[i] ==
'\0' )
81 result.
Reset( buffer.c_str() );
90 while ( --fieldNo >= 0 && (result= tknzr.HasNext()) )
93 target.
Reset( tknzr.Next() );
105 newPID=
static_cast<uinteger>( np );
117 NString64 procDir(
"/proc/"); procDir._<
false>(
PID )._(
'/' );
118 integer procPathLen= procDir.Length();
121 procDir <<
"cmdline"; readProcFile( procDir,
CmdLine ); procDir.ShortenTo(procPathLen);
122 procDir <<
"stat"; readProcFile( procDir,
Stat ); procDir.ShortenTo(procPathLen);
132 "CAMP",
"Error reading process Info" )
134 if (
Name.CharAtEnd () == ')' )
Name.DeleteEnd <false>( 1 );
135 if (
Name.CharAtStart() == '(' )
Name.DeleteStart<false>( 1 );
145 ssize_t length= readlink( procDir, buffer, 2048 );
146 procDir.ShortenTo(procPathLen);
153 "Executable path does not contain directory separator character.\n"
166#elif defined (__APPLE__)
172 pid=
static_cast<uinteger>( getpid() );
174 struct proc_bsdinfo proc;
175 int st = proc_pidinfo(
static_cast<int>(pid), PROC_PIDTBSDINFO, 0, &proc, PROC_PIDTBSDINFO_SIZE);
176 if (st != PROC_PIDTBSDINFO_SIZE)
184 Name.
_(
reinterpret_cast<const char*
>( proc.pbi_comm ) );
188 char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
190 if ( proc_pidpath (
static_cast<int>(
PID ), pathbuf, PROC_PIDPATHINFO_MAXSIZE) > 0 )
205#elif defined (_WIN32)
213 DWORD wPID= GetCurrentProcessId();
227 GetModuleFileNameA( NULL, buf, MAX_PATH );
231 "Executable path does not contain directory separator character: ",
237 STARTUPINFOA startupInfo;
238 GetStartupInfoA( &startupInfo );
245 #pragma message ("Unknown Platform in file: " __FILE__ )
bool getStatField(int fieldNo, AString &target)
static ALIB_API const ProcessInfo & Current()
ALIB_API bool get(uinteger PID)
static ALIB_API ProcessInfo current
TAString & ShortenTo(integer newLength)
TAString & Append(const TCharSrc *src, integer srcLength)
TAString & _(const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN)
void SetLength(integer newLength)
constexpr bool IsEmpty() const
constexpr integer Length() const
TChar CharAtStart() const
ALIB_API int64_t ParseInt(integer startIdx=0, TNumberFormat< TChar > *numberFormat=nullptr, integer *newIdx=nullptr) const
ALIB_WARNINGS_RESTORE integer LastIndexOf(TChar needle, integer startIndex=MAX_LEN) const
#define ALIB_IF_THREADS(...)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_LOCK_WITH(lock)
platform_specific integer
platform_specific uinteger
lang::system::ProcessInfo ProcessInfo
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
NLocalString< 64 > NString64
Type alias name for TLocalString<nchar,64> .
strings::TString< nchar > NString
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.