passwd* pwd = getpwuid(uid);
65 if(pwd && pwd->pw_name) {
66user.assign(pwd->pw_name);
69 #elif defined(NCBI_HAVE_GETPWUID_R) 72 charx_buf[
sizeof(*pwd) +
PWD_BUF];
77pwd = (
structpasswd*)
buf;
79 # if NCBI_HAVE_GETPWUID_R == 4 81pwd = getpwuid_r(uid, pwd, (
char*)(pwd + 1),
size);
83 # elif NCBI_HAVE_GETPWUID_R == 5 85 intx_errno = getpwuid_r(uid, pwd, (
char*)(pwd + 1),
size, &pwd);
92 # error "Unknown value of NCBI_HAVE_GETPWUID_R: 4 or 5 expected." 96 if(pwd || errno != ERANGE) {
102 # ifdef _SC_GETPW_R_SIZE_MAX 103 longsc = sysconf(_SC_GETPW_R_SIZE_MAX);
104maxsize = sc > 0 ? (size_t) sc :
size;
109 "getpwuid_r() parse buffer too small (" 111+
string(
size< maxsize
116 if(
size< maxsize) {
118 buf=
new char[
sizeof(*pwd) +
size];
131 buf=
new char[
sizeof(*pwd) +
size];
134 if(pwd && pwd->pw_name) {
135user.assign(pwd->pw_name);
151 #if defined(NCBI_OS_SOLARIS) || \ 152 (defined(HAVE_GETPWUID) && !defined(NCBI_HAVE_GETPWUID_R)) 154 const structpasswd* pwd = getpwnam(user.c_str());
155uid = pwd ? pwd->pw_uid : (uid_t)(-1);
157 #elif defined(NCBI_HAVE_GETPWUID_R) 160 charx_buf[
sizeof(*pwd) +
PWD_BUF];
165pwd = (
structpasswd*)
buf;
167 # if NCBI_HAVE_GETPWUID_R == 4 169pwd = getpwnam_r(user.c_str(), pwd, (
char*)(pwd + 1),
size);
171 # elif NCBI_HAVE_GETPWUID_R == 5 173 intx_errno = getpwnam_r(user.c_str(),
174pwd, (
char*)(pwd + 1),
size, &pwd);
181 # error "Unknown value of NCBI_HAVE_GETPWUID_R: 4 or 5 expected." 185 if(pwd || errno != ERANGE) {
191 # ifdef _SC_GETPW_R_SIZE_MAX 192 longsc = sysconf(_SC_GETPW_R_SIZE_MAX);
193maxsize = sc > 0 ? (size_t) sc :
size;
198 "getpwnam_r() parse buffer too small (" 200+
string(
size< maxsize
205 if(
size< maxsize) {
207 buf=
new char[
sizeof(*pwd) +
size];
220 buf=
new char[
sizeof(*pwd) +
size];
223uid = pwd ? pwd->pw_uid : (uid_t)(-1);
242 #if defined(NCBI_OS_SOLARIS) || \ 243 (defined(HAVE_GETPWUID) && !defined(NCBI_HAVE_GETPWUID_R)) 245 const structgroup* grp = getgrgid(gid);
246 if(grp && grp->gr_name) {
247group.assign(grp->gr_name);
250 #elif defined(NCBI_HAVE_GETPWUID_R) 253 charx_buf[
sizeof(*grp) +
GRP_BUF];
258grp = (
structgroup*)
buf;
260 # if NCBI_HAVE_GETPWUID_R == 4 262grp = getgrgid_r(gid, grp, (
char*)(grp + 1),
size);
264 # elif NCBI_HAVE_GETPWUID_R == 5 266 intx_errno = getgrgid_r(gid, grp,(
char*)(grp + 1),
size, &grp);
273 # error "Unknown value of NCBI_HAVE_GETPWUID_R: 4 or 5 expected." 277 if(grp || errno != ERANGE) {
283 # ifdef _SC_GETGR_R_SIZE_MAX 284 longsc = sysconf(_SC_GETGR_R_SIZE_MAX);
285maxsize = sc > 0 ? (size_t) sc :
size;
290 "getgrgid_r() parse buffer too small (" 292+
string(
size< maxsize
297 if(
size< maxsize) {
299 buf=
new char[
sizeof(*grp) +
size];
312 buf=
new char[
sizeof(*grp) +
size];
315 if(grp && grp->gr_name) {
316group.assign(grp->gr_name);
333 #if defined(NCBI_OS_SOLARIS) || \ 334 (defined(HAVE_GETPWUID) && !defined(NCBI_HAVE_GETPWUID_R)) 336 const structgroup* grp = getgrnam(group.c_str());
337gid = grp ? grp->gr_gid : (gid_t)(-1);
339 #elif defined(NCBI_HAVE_GETPWUID_R) 342 charx_buf[
sizeof(*grp) +
GRP_BUF];
347grp = (
structgroup*)
buf;
349 # if NCBI_HAVE_GETPWUID_R == 4 351grp = getgrnam_r(group.c_str(), grp, (
char*)(grp + 1),
size);
353 # elif NCBI_HAVE_GETPWUID_R == 5 355 intx_errno = getgrnam_r(group.c_str(),
356grp, (
char*)(grp + 1),
size, &grp);
363 # error "Unknown value of NCBI_HAVE_GETPWUID_R: 4 or 5 expected." 367 if(grp || errno != ERANGE) {
373 # ifdef _SC_GETGR_R_SIZE_MAX 374 longsc = sysconf(_SC_GETGR_R_SIZE_MAX);
375maxsize = sc > 0 ? (size_t) sc :
size;
380 "getgrnam_r() parse buffer too small (" 382+
string(
size< maxsize
387 if(
size< maxsize) {
389 buf=
new char[
sizeof(*grp) +
size];
402 buf=
new char[
sizeof(*grp) +
size];
405gid = grp ? grp->gr_gid : (gid_t)(-1);
420 #if defined(NCBI_OS_LINUX) 422 #define PROCFS(pid, file) \ 423 "/proc/"+ (!pid ? "self" : NStr::NumericToString(pid)) + "/" + file
427 size_ts_ReadFile(
const string& filename,
char*
buf,
size_t size)
446 size_ts_ParseStatusVmValue(
const char* name,
char*
buf,
size_t min_value= 0)
451 char* pos = strstr(
buf, name);
455 size_t n= NStr::StringToNumeric<size_t>(pos+strlen(name)+1
,
flags) * 1024;
466 n= s_ReadFile(PROCFS(pid,
"statm"),
buf,
sizeof(
buf));
471 usage.total *= page_size;
472 usage.resident *= page_size;
473 usage.shared *= page_size;
474 usage.text *= page_size;
475 usage.lib *= page_size;
481 n= s_ReadFile(PROCFS(pid,
"status"),
buf,
sizeof(
buf));
484 char* pos = strstr(
buf,
"Vm");
488 usage.total_peak = s_ParseStatusVmValue(
"VmPeak", pos,
usage.total);
489 usage.resident_peak = s_ParseStatusVmValue(
"VmHWM", pos,
usage.resident);
490 usage.data = s_ParseStatusVmValue(
"VmData", pos);
491 usage.swap = s_ParseStatusVmValue(
"VmSwap", pos);
493 usage.text = s_ParseStatusVmValue(
"VmExe", pos);
496 usage.lib = s_ParseStatusVmValue(
"VmLib", pos);
498 if(!
usage.stack) {
499 usage.stack = s_ParseStatusVmValue(
"VmStk", pos);
506 intCLinuxFeature::GetThreadCount(pid_t pid)
509 stringname = PROCFS(pid,
"task");
510DIR* dir = opendir(name.c_str());
512 while(readdir(dir) !=
NULL) {
526 intCLinuxFeature::GetFileDescriptorsCount(pid_t pid)
529 stringname = PROCFS(pid,
"fd");
530DIR* dir = opendir(name.c_str());
532 while(readdir(dir) !=
NULL) {
546CLinuxFeature::CProcStat::CProcStat(pid_t pid)
551 size_t n= s_ReadFile(PROCFS(pid,
"stat"),
buf,
sizeof(
buf));
553m_Storage.reserve(
n);
554m_Storage.assign(
buf,
n);
558 size_tp1 = m_Storage.find(
'(');
562m_List.push_back(
CTempString(m_Storage, 0, p1-1));
563 size_tp2 = m_Storage.find(
')', p1+1);
567m_List.push_back(
CTempString(m_Storage, p1+1, p2-p1-1));
568 NStr::Split(m_Storage.data() + p2 + 1,
" ", m_List);
Class for support low level input/output for files.
static unsigned long GetVirtualMemoryPageSize(void)
Return virtual memory page size.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
static string GetUserNameByUID(uid_t uid)
Look up user name by given numeric user ID.
static gid_t GetGroupGIDByName(const string &group)
Look up numeric group ID by symbolic group name.
static string GetGroupNameByGID(gid_t gid)
Look up group name by given numeric group ID.
static uid_t GetUserUIDByName(const string &user)
Look up numeric user ID by symbolic user name.
The NCBI C++ standard methods for dealing with std::string.
#define ERR_POST_ONCE(message)
Error posting only once during program execution.
void Critical(CExceptionArgs_Base &args)
void Error(CExceptionArgs_Base &args)
static void Set(ECode code)
Set last error using native error code enum.
@ eUnknown
Unknown error.
@ eRead
File can be read.
@ eOpen
Open an existing file, or create a new one.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define NCBI_AS_STRING(value)
Convert some value to string even if this value is macro itself.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
int TStringToNumFlags
Bitwise OR of "EStringToNumFlags".
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
@ fConvErr_NoThrow
Do not throw an exception on error.
@ fAllowTrailingSymbols
Ignore trailing non-numerics characters.
@ fAllowLeadingSpaces
Ignore leading whitespace characters in converted string.
Definition of all error codes used in corelib (xncbi.lib).
const struct ncbi::grid::netcache::search::fields::SIZE size
Private UNIX specific features.
bool GetMemoryUsage(size_t *total, size_t *resident, size_t *shared)
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Process memory usage information, in bytes.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4