Provides access to process information.
More...
#include <src/Lib/ProcessDescriptor.h>
|
| ProcessDescriptor () |
|
virtual | ~ProcessDescriptor () |
|
long | query (long pid, InfoType info, PROCESS_BASIC_INFORMATION *buffer) |
|
long | query (long pid, InfoType info, POOLED_USAGE_AND_LIMITS *buffer) |
|
long | query (long pid, InfoType info, KERNEL_USER_TIMES *buffer) |
|
long | query (long pid, InfoType info, QUOTA_LIMITS *buffer) |
|
long | query (long pid, InfoType info, VM_COUNTERS *buffer) |
|
long | query (long pid, InfoType info, IO_COUNTERS *buffer) |
|
long | query (long pid, InfoType info, long *buffer) |
|
Provides access to process information.
- Author
- M.Frank
-
Sebastien Ponce
Definition at line 109 of file ProcessDescriptor.h.
System::ProcessDescriptor::ProcessDescriptor |
( |
| ) |
|
Definition at line 385 of file ProcessDescriptor.cpp.
388 static bool first =
true;
391 void* mh = ::LoadLibrary(
"NTDll.dll" );
393 NtApi::NtQueryInformationProcess =
394 ( NtApi::__NtQueryInformationProcess )::GetProcAddress( (HINSTANCE)mh,
"NtQueryInformationProcess" );
System::ProcessDescriptor::~ProcessDescriptor |
( |
| ) |
|
|
virtual |
Definition at line 587 of file ProcessDescriptor.cpp.
589 if ( info == 0 )
return 0;
593 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT 596 sizeof( PROCESS_BASIC_INFORMATION ), 0 );
597 status = ( status == 0 ) ? 1 : 0;
598 #elif defined( _WIN32 ) // Windows 95,98... 599 #elif defined( __linux ) // Linux 601 pid = processID( pid );
603 info->ExitStatus = 0;
605 info->BasePriority = 2 * 15 - prc.
priority;
608 info->AffinityMask = prc.
flags;
611 info->UniqueProcessId = pid;
612 info->InheritedFromUniqueProcessId = prc.
ppid;
void readProcStat(long pid, linux_proc &pinfo)
struct _PEB * PPEB
Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.
void * ProcessHandle
Definition of the process handle.
Definition at line 430 of file ProcessDescriptor.cpp.
432 if ( info == 0 )
return 0;
435 if ( fetch ==
Quota ) {
436 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT 439 sizeof( POOLED_USAGE_AND_LIMITS ), 0 );
440 status = ( status == 0 ) ? 1 : 0;
441 #elif defined( _WIN32 ) // Windows 95,98... 442 #elif defined( __linux ) // Linux 447 getrlimit( RLIMIT_DATA, &lim );
448 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
449 info->PeakPagedPoolUsage = lim.rlim_cur;
450 info->PagedPoolUsage = lim.rlim_cur;
451 info->PagedPoolLimit = lim.rlim_max;
453 getrlimit( RLIMIT_STACK, &lim );
454 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
455 info->PeakNonPagedPoolUsage = lim.rlim_cur;
456 info->NonPagedPoolUsage = lim.rlim_cur;
457 info->NonPagedPoolLimit = lim.rlim_max;
461 info->PeakPagefileUsage = prc.
rss * pg_size;
462 info->PagefileUsage = prc.
rss * pg_size;
463 info->PagefileLimit = 0xFFFFFFFF;
464 #elif defined( __APPLE__ )
void readProcStat(long pid, linux_proc &pinfo)
void * ProcessHandle
Definition of the process handle.
Definition at line 619 of file ProcessDescriptor.cpp.
621 if ( info == 0 )
return 0;
624 if ( fetch ==
Times ) {
625 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT 627 status = NtApi::NtQueryInformationProcess( h.handle(),
ProcessTimes, info,
sizeof( KERNEL_USER_TIMES ), 0 );
628 status = ( status == 0 ) ? 1 : 0;
629 #elif defined( _WIN32 ) // Windows 95,98... 630 #elif defined( __linux ) // Linux 632 bool myself = pid <= 0 || pid == ::getpid();
633 if ( myself && prc_start == 0 ) {
639 prc_start = ( prc.
starttime + offset ) * TICK_TO_100NSEC;
645 info->UserTime = tmsb.tms_utime * TICK_TO_100NSEC;
646 info->KernelTime = tmsb.tms_stime * TICK_TO_100NSEC;
647 info->CreateTime = prc_start;
656 info->UserTime = t.tms_utime * TICK_TO_100NSEC;
657 info->KernelTime = t.tms_stime * TICK_TO_100NSEC;
658 info->CreateTime = ( prc.
starttime + offset ) * TICK_TO_100NSEC;
664 #elif defined( __APPLE__ ) 667 #else // no /proc file system: assume sys_start for the first call 669 static clock_t sys_start = times( 0 );
671 clock_t now = times( &tmsb );
672 info->CreateTime = offset + now;
673 info->UserTime = tmsb.tms_utime;
674 info->KernelTime = tmsb.tms_stime;
675 info->CreateTime *= TICK_TO_100NSEC;
676 info->UserTime *= TICK_TO_100NSEC;
677 info->KernelTime *= TICK_TO_100NSEC;
void readProcStat(long pid, linux_proc &pinfo)
unsigned long long starttime
void * ProcessHandle
Definition of the process handle.
Definition at line 542 of file ProcessDescriptor.cpp.
544 if ( info == 0 )
return 0;
547 if ( fetch ==
Quota ) {
548 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT 550 status = NtApi::NtQueryInformationProcess( h.handle(),
ProcessQuotaLimits, info,
sizeof( QUOTA_LIMITS ), 0 );
551 status = ( status == 0 ) ? 1 : 0;
552 #elif defined( _WIN32 ) // Windows 95,98... 553 #elif defined( __linux ) // Linux 557 if ( pid > 0 && pid != ::getpid() )
return 0;
560 getrlimit( RLIMIT_DATA, &lim );
561 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
562 info->PagedPoolLimit = lim.rlim_max;
564 getrlimit( RLIMIT_STACK, &lim );
565 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
566 info->NonPagedPoolLimit = lim.rlim_max;
567 info->MinimumWorkingSetSize = 0;
569 getrlimit( RLIMIT_RSS, &lim );
570 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
571 info->MaximumWorkingSetSize = lim.rlim_max;
573 getrlimit( RLIMIT_AS, &lim );
574 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
575 info->PagefileLimit = lim.rlim_max;
577 getrlimit( RLIMIT_CPU, &lim );
578 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
579 info->TimeLimit = lim.rlim_max;
580 #elif defined( __APPLE__ )
void * ProcessHandle
Definition of the process handle.
Definition at line 500 of file ProcessDescriptor.cpp.
502 if ( info == 0 )
return 0;
506 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT 508 status = NtApi::NtQueryInformationProcess( h.handle(),
ProcessVmCounters, info,
sizeof( VM_COUNTERS ), 0 );
509 status = ( status == 0 ) ? 1 : 0;
510 #elif defined( _WIN32 ) // Windows 95,98... 511 #elif defined( __linux ) // Linux 512 const ssize_t bufsize = 1024;
514 pid = processID( pid );
515 sprintf( buf,
"/proc/%ld/statm", pid );
516 long size, resident, share, trs, lrs, drs, dt;
517 int fd = open( buf, O_RDONLY );
518 ssize_t nread =
read( fd, buf, bufsize );
520 if ( nread < bufsize && nread >= 0 ) buf[nread] =
'\0';
521 fd =
sscanf( buf,
"%ld %ld %ld %ld %ld %ld %ld", &size, &resident, &share, &trs, &drs, &lrs, &dt );
524 info->PeakVirtualSize = prc.
vsize;
525 info->VirtualSize = prc.
vsize;
526 info->PeakWorkingSetSize = resident * pg_size;
527 info->WorkingSetSize = resident * pg_size;
528 info->QuotaPeakPagedPoolUsage = share * pg_size;
529 info->QuotaPagedPoolUsage = share * pg_size;
530 info->QuotaNonPagedPoolUsage = ( trs + drs ) * pg_size;
531 info->QuotaPeakNonPagedPoolUsage = ( trs + drs ) * pg_size;
533 info->PagefileUsage = prc.
vsize - resident * pg_size;
534 info->PeakPagefileUsage = prc.
vsize - resident * pg_size;
535 #elif defined( __APPLE__ )
def read(f, regex='.*', skipevents=0)
void readProcStat(long pid, linux_proc &pinfo)
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
void * ProcessHandle
Definition of the process handle.
Definition at line 402 of file ProcessDescriptor.cpp.
404 if ( info == 0 )
return 0;
408 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT 410 status = NtApi::NtQueryInformationProcess( h.handle(),
ProcessIoCounters, info,
sizeof( IO_COUNTERS ), 0 );
411 status = ( status == 0 ) ? 1 : 0;
412 #elif defined( _WIN32 ) // Windows 95,98... 413 #elif defined( __linux ) 417 getrusage( RUSAGE_SELF, &usage );
418 info->ReadOperationCount = usage.ru_inblock;
419 info->WriteOperationCount = usage.ru_oublock;
420 info->OtherOperationCount = 0;
421 info->ReadTransferCount = usage.ru_inblock;
422 info->WriteTransferCount = usage.ru_oublock;
423 info->OtherTransferCount = 0;
void usage(std::string argv0)
void readProcStat(long pid, linux_proc &pinfo)
void * ProcessHandle
Definition of the process handle.
long System::ProcessDescriptor::query |
( |
long |
pid, |
|
|
InfoType |
info, |
|
|
long * |
buffer |
|
) |
| |
Definition at line 472 of file ProcessDescriptor.cpp.
475 if ( info == 0 )
return 0;
480 #if defined( _WIN32 ) && WINVER >= 0x0400 // Windows NT 482 status = NtApi::NtQueryInformationProcess( h.handle(),
ProcessPriorityBoost, info,
sizeof( long ), 0 );
483 #elif defined( _WIN32 ) // Windows 95,98... 486 if ( pid > 0 ) status = 0;
490 status = ( status == 0 ) ? 1 : 0;
void * ProcessHandle
Definition of the process handle.
The documentation for this class was generated from the following files: