All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
System::ProcessDescriptor Class Reference

Provides access to process information. More...

#include <src/Lib/ProcessDescriptor.h>

Collaboration diagram for System::ProcessDescriptor:

Classes

class  ProcessHandle
 

Public Member Functions

 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)
 

Private Attributes

long m_PRIORITYBOOST [2]
 
IO_COUNTERS m_IO_COUNTERS [2]
 
VM_COUNTERS m_VM_COUNTERS [2]
 
KERNEL_USER_TIMES m_KERNEL_USER_TIMES [2]
 
POOLED_USAGE_AND_LIMITS m_POOLED_USAGE_AND_LIMITS [2]
 
QUOTA_LIMITS m_QUOTA_LIMITS [2]
 
PROCESS_BASIC_INFORMATION m_PROCESS_BASIC_INFORMATION [2]
 

Detailed Description

Provides access to process information.

Author
M.Frank
Sebastien Ponce

Definition at line 110 of file ProcessDescriptor.h.

Constructor & Destructor Documentation

System::ProcessDescriptor::ProcessDescriptor ( )

Definition at line 428 of file ProcessDescriptor.cpp.

429 {
430 }
System::ProcessDescriptor::~ProcessDescriptor ( )
virtual

Definition at line 432 of file ProcessDescriptor.cpp.

432  {
433 }

Member Function Documentation

long System::ProcessDescriptor::query ( long  pid,
InfoType  info,
PROCESS_BASIC_INFORMATION buffer 
)

Definition at line 638 of file ProcessDescriptor.cpp.

640  {
641  long status = 1;
642  ProcessHandle h(pid);
643  PROCESS_BASIC_INFORMATION* vb = &m_PROCESS_BASIC_INFORMATION[h.item()];
644  if ( fetch == ProcessBasics ) {
645 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
646  status = NtApi::NtQueryInformationProcess(h.handle(),
648  vb,
649  sizeof(PROCESS_BASIC_INFORMATION),
650  0);
651  status = (status==0) ? 1 : 0;
652 #elif defined(_WIN32) // Windows 95,98...
653 #elif defined(__linux) // Linux
654  linux_proc prc;
655  readProcStat( processID(pid), prc);
656  vb->ExitStatus = 0;
657  vb->PebBaseAddress = (PPEB)prc.startcode;
658  vb->BasePriority = 2*15-prc.priority;
659  // std::cout << "Base Priority=" << vb->BasePriority << "|"
660  // << prc.priority << std::endl;
661  vb->AffinityMask = prc.flags;
662  // std::cout << "Flags =" << vb->AffinityMask << "|"
663  // << prc.flags << std::endl;
664  vb->UniqueProcessId = processID(pid);
665  vb->InheritedFromUniqueProcessId = prc.ppid;
666 #else // All Other
667 #endif // End ALL OS
668  }
669  if ( info ) *info = *vb;
670  return status;
671 }
unsigned long flags
void readProcStat(long pid, linux_proc &pinfo)
unsigned long startcode
struct _PEB * PPEB
Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.
PROCESS_BASIC_INFORMATION m_PROCESS_BASIC_INFORMATION[2]
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32
long System::ProcessDescriptor::query ( long  pid,
InfoType  info,
POOLED_USAGE_AND_LIMITS buffer 
)

Definition at line 468 of file ProcessDescriptor.cpp.

470  {
471  long status = 1;
472  ProcessHandle h(pid);
473  POOLED_USAGE_AND_LIMITS* vb = &m_POOLED_USAGE_AND_LIMITS[h.item()];
474  if ( fetch == Quota ) {
475 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
476  status = NtApi::NtQueryInformationProcess(h.handle(),
478  vb,
479  sizeof(POOLED_USAGE_AND_LIMITS),
480  0);
481  status = (status==0) ? 1 : 0;
482 #elif defined(_WIN32) // Windows 95,98...
483 #elif defined(__linux) // Linux
484  //rusage usage;
485  //getrusage(RUSAGE_SELF, &usage);
486  rlimit lim;
487 
488  getrlimit(RLIMIT_DATA, &lim);
489  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
490  vb->PeakPagedPoolUsage = lim.rlim_cur;
491  vb->PagedPoolUsage = lim.rlim_cur;
492  vb->PagedPoolLimit = lim.rlim_max;
493 
494  getrlimit(RLIMIT_STACK, &lim);
495  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
496  vb->PeakNonPagedPoolUsage = lim.rlim_cur;
497  vb->NonPagedPoolUsage = lim.rlim_cur;
498  vb->NonPagedPoolLimit = lim.rlim_max;
499 
500  linux_proc prc;
501  readProcStat(processID(pid), prc);
502  vb->PeakPagefileUsage = prc.rss * pg_size;
503  vb->PagefileUsage = prc.rss * pg_size;
504  vb->PagefileLimit = 0xFFFFFFFF;
505 #elif defined(__APPLE__)
506 #else // All Other
507 #endif // End ALL OS
508  }
509  if ( info ) *info = *vb;
510  return status;
511 }
void readProcStat(long pid, linux_proc &pinfo)
POOLED_USAGE_AND_LIMITS m_POOLED_USAGE_AND_LIMITS[2]
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32
long System::ProcessDescriptor::query ( long  pid,
InfoType  info,
KERNEL_USER_TIMES buffer 
)

Definition at line 673 of file ProcessDescriptor.cpp.

675  {
676  long status = 1;
677  ProcessHandle h(pid);
678  KERNEL_USER_TIMES* tb = &m_KERNEL_USER_TIMES[h.item()];;
679  if ( fetch == Times ) {
680 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
681  status = NtApi::NtQueryInformationProcess(h.handle(),
682  ProcessTimes,
683  tb,
684  sizeof(KERNEL_USER_TIMES),
685  0);
686  status = (status==0) ? 1 : 0;
687 #elif defined(_WIN32) // Windows 95,98...
688 #elif defined(__linux) // Linux
689  // prc.startup is in ticks since system start :
690  // need to offset for absolute time
691  tms tmsb;
692  static longlong prc_start = 0;
693  // static longlong offset = 100*longlong(time(0)) - longlong(times(0));
694  static longlong offset = 100*longlong(time(0)) - longlong(times(&tmsb));
695  if ( processID(pid) == s_myPid && prc_start == 0 ) {
696  linux_proc prc;
697  readProcStat( processID(pid), prc);
698  prc_start = prc.starttime+offset;
699  }
700 
701  if ( processID(pid) == s_myPid ) {
702  struct rusage r;
703  getrusage( RUSAGE_SELF, &r );
704  tb->UserTime = (static_cast<long long>(r.ru_utime.tv_sec) * 1000000 +
705  r.ru_utime.tv_usec) * 10;
706  tb->KernelTime = (static_cast<long long>(r.ru_stime.tv_sec) * 1000000 +
707  r.ru_stime.tv_usec) * 10;
708  tb->CreateTime = prc_start;
709  }
710  else {
711  linux_proc prc;
712  readProcStat( processID(pid), prc );
713 
714  tms t;
715  times(&t);
716  tb->UserTime = t.tms_utime * TICK_TO_100NSEC;
717  tb->KernelTime = t.tms_stime * TICK_TO_100NSEC;
718  tb->CreateTime = (prc.starttime+offset);
719  }
720  tb->CreateTime *= TICK_TO_100NSEC;
721  tb->ExitTime = 0;
722 
723  status = 1;
724 
725 #elif defined(__APPLE__)
726  // FIXME (MCl): Make an alternative function get timing on OSX
727  // times() seems to cause a segmentation fault
728 #else // no /proc file system: assume sys_start for the first call
729  tms tmsb;
730  static clock_t sys_start = times(0);
731  static longlong offset = 100*longlong(time(0)) - sys_start;
732  clock_t now = times(&tmsb);
733  tb->CreateTime = offset + now;
734  tb->UserTime = tmsb.tms_utime;
735  tb->KernelTime = tmsb.tms_stime;
736  tb->CreateTime *= TICK_TO_100NSEC;
737  tb->UserTime *= TICK_TO_100NSEC;
738  tb->KernelTime *= TICK_TO_100NSEC;
739  tb->ExitTime = 0;
740  status = 1;
741 #endif
742  }
743  if ( info ) *info = *tb;
744  return status;
745 }
KERNEL_USER_TIMES m_KERNEL_USER_TIMES[2]
void readProcStat(long pid, linux_proc &pinfo)
unsigned long long starttime
#define s_myPid
__longlong longlong
Definition: Kernel.h:58
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32
long System::ProcessDescriptor::query ( long  pid,
InfoType  info,
QUOTA_LIMITS buffer 
)

Definition at line 591 of file ProcessDescriptor.cpp.

593  {
594  long status = 1;
595  ProcessHandle h(pid);
596  QUOTA_LIMITS* vb = &m_QUOTA_LIMITS[h.item()];
597  if ( fetch == Quota ) {
598 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
599  status = NtApi::NtQueryInformationProcess(h.handle(),
601  vb,
602  sizeof(QUOTA_LIMITS),
603  0);
604  status = (status==0) ? 1 : 0;
605 #elif defined(_WIN32) // Windows 95,98...
606 #elif defined(__linux) // Linux
607  // On linux all this stuff typically is not set
608  // (ie. rlim_max=RLIM_INFINITY...)
609  rlimit lim;
610  getrlimit(RLIMIT_DATA, &lim);
611  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
612  vb->PagedPoolLimit = lim.rlim_max;
613 
614  getrlimit(RLIMIT_STACK, &lim);
615  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
616  vb->NonPagedPoolLimit = lim.rlim_max;
617  vb->MinimumWorkingSetSize = 0;
618 
619  getrlimit(RLIMIT_RSS, &lim);
620  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
621  vb->MaximumWorkingSetSize = lim.rlim_max;
622 
623  getrlimit(RLIMIT_AS, &lim);
624  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
625  vb->PagefileLimit = lim.rlim_max;
626 
627  getrlimit(RLIMIT_CPU, &lim);
628  if ( lim.rlim_max == RLIM_INFINITY ) lim.rlim_max = 0xFFFFFFFF;
629  vb->TimeLimit = lim.rlim_max;
630 #elif defined(__APPLE__)
631 #else // All Other
632 #endif // End ALL OS
633  }
634  if ( info ) *info = *vb;
635  return status;
636 }
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32
long System::ProcessDescriptor::query ( long  pid,
InfoType  info,
VM_COUNTERS buffer 
)

Definition at line 543 of file ProcessDescriptor.cpp.

545  {
546  long status = 1;
547  ProcessHandle h(pid);
548  VM_COUNTERS* vb = &m_VM_COUNTERS[h.item()];
549  if ( fetch == Memory ) {
550 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
551  status = NtApi::NtQueryInformationProcess(h.handle(),
553  vb,
554  sizeof(VM_COUNTERS),
555  0);
556  status = (status==0) ? 1 : 0;
557 #elif defined(_WIN32) // Windows 95,98...
558 #elif defined(__linux) // Linux
559  const ssize_t bufsize = 1024;
560  char buf[bufsize];
561  sprintf(buf,"/proc/%ld/statm", processID(pid));
562  long size, resident, share, trs, lrs, drs, dt;
563  int fd = open(buf,O_RDONLY);
564  ssize_t nread = read(fd, buf, bufsize);
565  close(fd);
566  if ( nread < bufsize && nread >= 0 )
567  buf[nread]='\0';
568  fd = sscanf(buf, "%ld %ld %ld %ld %ld %ld %ld",
569  &size, &resident, &share, &trs, &drs, &lrs, &dt);
570  linux_proc prc;
571  readProcStat( processID(pid), prc);
572  vb->PeakVirtualSize = prc.vsize;
573  vb->VirtualSize = prc.vsize;
574  vb->PeakWorkingSetSize = resident * pg_size;
575  vb->WorkingSetSize = resident * pg_size;
576  vb->QuotaPeakPagedPoolUsage = share * pg_size;
577  vb->QuotaPagedPoolUsage = share * pg_size;
578  vb->QuotaNonPagedPoolUsage = (trs+drs)* pg_size;// drs = data/stack size
579  vb->QuotaPeakNonPagedPoolUsage = (trs+drs)* pg_size;// trs = VmExe size
580  vb->PageFaultCount = prc.majflt + prc.minflt;
581  vb->PagefileUsage = prc.vsize-resident*pg_size;
582  vb->PeakPagefileUsage = prc.vsize-resident*pg_size;
583 #elif defined(__APPLE__)
584 #else // All Other
585 #endif // End ALL OS
586  }
587  if ( info ) *info = *vb;
588  return status;
589 }
unsigned long minflt
void readProcStat(long pid, linux_proc &pinfo)
unsigned long vsize
unsigned long majflt
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32
long System::ProcessDescriptor::query ( long  pid,
InfoType  info,
IO_COUNTERS buffer 
)

Definition at line 435 of file ProcessDescriptor.cpp.

437  {
438  long status = 1;
439  ProcessHandle h(pid);
440  IO_COUNTERS* vb = &m_IO_COUNTERS[h.item()];
441  if ( fetch == IO ) {
442 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
443  status = NtApi::NtQueryInformationProcess(h.handle(),
445  vb,
446  sizeof(IO_COUNTERS),
447  0);
448  status = (status==0) ? 1 : 0;
449 #elif defined(_WIN32) // Windows 95,98...
450 #elif defined(__linux)
451  linux_proc prc;
452  readProcStat(processID(pid), prc);
453  rusage usage;
454  getrusage(RUSAGE_SELF, &usage);
455  vb->ReadOperationCount = usage.ru_inblock;
456  vb->WriteOperationCount = usage.ru_oublock;
457  vb->OtherOperationCount = 0;
458  vb->ReadTransferCount = usage.ru_inblock;
459  vb->WriteTransferCount = usage.ru_oublock;
460  vb->OtherTransferCount = 0;
461 #else // All Other
462 #endif // End ALL OS
463  }
464  if ( info ) *info = *vb;
465  return status;
466 }
void usage(std::string argv0)
void readProcStat(long pid, linux_proc &pinfo)
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32
long System::ProcessDescriptor::query ( long  pid,
InfoType  info,
long *  buffer 
)

Definition at line 513 of file ProcessDescriptor.cpp.

513  {
514  long status = 1, *vb = &status;
515  ProcessHandle h(pid);
516  vb = &m_PRIORITYBOOST[h.item()];
517  *vb = 0;
518  switch ( fetch ) {
519  case PriorityBoost:
520 #if defined(_WIN32) && WINVER>=0x0400 // Windows NT
521  status = NtApi::NtQueryInformationProcess(h.handle(),
523  vb,
524  sizeof(long),
525  0);
526 #elif defined(_WIN32) // Windows 95,98...
527 #else
528  // Not applicable
529  status = 0;
530  *vb = 0;
531 #endif // End ALL OS
532  status = (status==0) ? 1 : 0;
533  break;
534  default:
535  status = -1;
536  vb = &status;
537  break;
538  }
539  if ( info ) *info = *vb;
540  return status;
541 }
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32

Member Data Documentation

IO_COUNTERS System::ProcessDescriptor::m_IO_COUNTERS[2]
private

Definition at line 125 of file ProcessDescriptor.h.

KERNEL_USER_TIMES System::ProcessDescriptor::m_KERNEL_USER_TIMES[2]
private

Definition at line 127 of file ProcessDescriptor.h.

POOLED_USAGE_AND_LIMITS System::ProcessDescriptor::m_POOLED_USAGE_AND_LIMITS[2]
private

Definition at line 128 of file ProcessDescriptor.h.

long System::ProcessDescriptor::m_PRIORITYBOOST[2]
private

Definition at line 124 of file ProcessDescriptor.h.

PROCESS_BASIC_INFORMATION System::ProcessDescriptor::m_PROCESS_BASIC_INFORMATION[2]
private

Definition at line 130 of file ProcessDescriptor.h.

QUOTA_LIMITS System::ProcessDescriptor::m_QUOTA_LIMITS[2]
private

Definition at line 129 of file ProcessDescriptor.h.

VM_COUNTERS System::ProcessDescriptor::m_VM_COUNTERS[2]
private

Definition at line 126 of file ProcessDescriptor.h.


The documentation for this class was generated from the following files: