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 415 of file ProcessDescriptor.cpp.
418 static bool first =
true;
421 void* mh = ::LoadLibrary(
"NTDll.dll");
423 NtApi::NtQueryInformationProcess = (NtApi::__NtQueryInformationProcess)
424 ::GetProcAddress((HINSTANCE)mh,
"NtQueryInformationProcess");
System::ProcessDescriptor::~ProcessDescriptor |
( |
| ) |
|
|
virtual |
Definition at line 642 of file ProcessDescriptor.cpp.
645 if (info==0)
return 0;
649 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT 651 status = NtApi::NtQueryInformationProcess(
h.handle(),
654 sizeof(PROCESS_BASIC_INFORMATION),
656 status = (status==0) ? 1 : 0;
657 #elif defined(_WIN32) // Windows 95,98... 658 #elif defined(__linux) // Linux 660 pid = processID(pid);
662 info->ExitStatus = 0;
664 info->BasePriority = 2*15-prc.
priority;
667 info->AffinityMask = prc.
flags;
670 info->UniqueProcessId = pid;
671 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 466 of file ProcessDescriptor.cpp.
469 if (info==0)
return 0;
472 if ( fetch ==
Quota ) {
473 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT 475 status = NtApi::NtQueryInformationProcess(
h.handle(),
478 sizeof(POOLED_USAGE_AND_LIMITS),
480 status = (status==0) ? 1 : 0;
481 #elif defined(_WIN32) // Windows 95,98... 482 #elif defined(__linux) // Linux 487 getrlimit(RLIMIT_DATA, &lim);
488 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
489 info->PeakPagedPoolUsage = lim.rlim_cur;
490 info->PagedPoolUsage = lim.rlim_cur;
491 info->PagedPoolLimit = lim.rlim_max;
493 getrlimit(RLIMIT_STACK, &lim);
494 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
495 info->PeakNonPagedPoolUsage = lim.rlim_cur;
496 info->NonPagedPoolUsage = lim.rlim_cur;
497 info->NonPagedPoolLimit = lim.rlim_max;
501 info->PeakPagefileUsage = prc.
rss * pg_size;
502 info->PagefileUsage = prc.
rss * pg_size;
503 info->PagefileLimit = 0xFFFFFFFF;
504 #elif defined(__APPLE__)
void readProcStat(long pid, linux_proc &pinfo)
void * ProcessHandle
Definition of the process handle.
Definition at line 678 of file ProcessDescriptor.cpp.
681 if (info==0)
return 0;
684 if ( fetch ==
Times ) {
685 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT 687 status = NtApi::NtQueryInformationProcess(
h.handle(),
690 sizeof(KERNEL_USER_TIMES),
692 status = (status==0) ? 1 : 0;
693 #elif defined(_WIN32) // Windows 95,98... 694 #elif defined(__linux) // Linux 696 bool myself = pid<=0 || pid==::getpid();
697 if ( myself && prc_start == 0 ) {
703 prc_start = (prc.
starttime+offset) * TICK_TO_100NSEC;
709 info->UserTime = tmsb.tms_utime * TICK_TO_100NSEC;
710 info->KernelTime = tmsb.tms_stime * TICK_TO_100NSEC;
711 info->CreateTime = prc_start;
721 info->UserTime = t.tms_utime * TICK_TO_100NSEC;
722 info->KernelTime = t.tms_stime * TICK_TO_100NSEC;
723 info->CreateTime = (prc.
starttime+offset) * TICK_TO_100NSEC;
729 #elif defined(__APPLE__) 732 #else // no /proc file system: assume sys_start for the first call 734 static clock_t sys_start = times(0);
736 clock_t now = times(&tmsb);
737 info->CreateTime = offset + now;
738 info->UserTime = tmsb.tms_utime;
739 info->KernelTime = tmsb.tms_stime;
740 info->CreateTime *= TICK_TO_100NSEC;
741 info->UserTime *= TICK_TO_100NSEC;
742 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 592 of file ProcessDescriptor.cpp.
595 if (info==0)
return 0;
598 if ( fetch ==
Quota ) {
599 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT 601 status = NtApi::NtQueryInformationProcess(
h.handle(),
604 sizeof(QUOTA_LIMITS),
606 status = (status==0) ? 1 : 0;
607 #elif defined(_WIN32) // Windows 95,98... 608 #elif defined(__linux) // Linux 612 if (pid>0 && pid!=::getpid())
return 0;
615 getrlimit(RLIMIT_DATA, &lim);
616 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
617 info->PagedPoolLimit = lim.rlim_max;
619 getrlimit(RLIMIT_STACK, &lim);
620 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
621 info->NonPagedPoolLimit = lim.rlim_max;
622 info->MinimumWorkingSetSize = 0;
624 getrlimit(RLIMIT_RSS, &lim);
625 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
626 info->MaximumWorkingSetSize = lim.rlim_max;
628 getrlimit(RLIMIT_AS, &lim);
629 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
630 info->PagefileLimit = lim.rlim_max;
632 getrlimit(RLIMIT_CPU, &lim);
633 if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
634 info->TimeLimit = lim.rlim_max;
635 #elif defined(__APPLE__)
void * ProcessHandle
Definition of the process handle.
Definition at line 543 of file ProcessDescriptor.cpp.
546 if (info==0)
return 0;
550 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT 552 status = NtApi::NtQueryInformationProcess(
h.handle(),
557 status = (status==0) ? 1 : 0;
558 #elif defined(_WIN32) // Windows 95,98... 559 #elif defined(__linux) // Linux 560 const ssize_t bufsize = 1024;
562 pid = processID(pid);
563 sprintf(buf,
"/proc/%ld/statm", pid);
564 long size, resident, share, trs, lrs, drs, dt;
565 int fd = open(buf,O_RDONLY);
566 ssize_t nread = read(fd, buf, bufsize);
568 if ( nread < bufsize && nread >= 0 )
570 fd =
sscanf(buf,
"%ld %ld %ld %ld %ld %ld %ld",
571 &size, &resident, &share, &trs, &drs, &lrs, &dt);
574 info->PeakVirtualSize = prc.
vsize;
575 info->VirtualSize = prc.
vsize;
576 info->PeakWorkingSetSize = resident * pg_size;
577 info->WorkingSetSize = resident * pg_size;
578 info->QuotaPeakPagedPoolUsage = share * pg_size;
579 info->QuotaPagedPoolUsage = share * pg_size;
580 info->QuotaNonPagedPoolUsage = (trs+drs)* pg_size;
581 info->QuotaPeakNonPagedPoolUsage = (trs+drs)* pg_size;
583 info->PagefileUsage = prc.
vsize-resident*pg_size;
584 info->PeakPagefileUsage = prc.
vsize-resident*pg_size;
585 #elif defined(__APPLE__)
void readProcStat(long pid, linux_proc &pinfo)
void * ProcessHandle
Definition of the process handle.
Definition at line 433 of file ProcessDescriptor.cpp.
436 if (info==0)
return 0;
440 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT 442 status = NtApi::NtQueryInformationProcess(
h.handle(),
447 status = (status==0) ? 1 : 0;
448 #elif defined(_WIN32) // Windows 95,98... 449 #elif defined(__linux) 453 getrusage(RUSAGE_SELF, &usage);
454 info->ReadOperationCount = usage.ru_inblock;
455 info->WriteOperationCount = usage.ru_oublock;
456 info->OtherOperationCount = 0;
457 info->ReadTransferCount = usage.ru_inblock;
458 info->WriteTransferCount = usage.ru_oublock;
459 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 512 of file ProcessDescriptor.cpp.
514 if (info==0)
return 0;
519 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT 521 status = NtApi::NtQueryInformationProcess(
h.handle(),
526 #elif defined(_WIN32) // Windows 95,98... 529 if (pid>0) status = 0;
533 status = (status==0) ? 1 : 0;
void * ProcessHandle
Definition of the process handle.
The documentation for this class was generated from the following files: