The Gaudi Framework  v33r0 (d5ea422b)
ProcessDescriptor.cpp File Reference
#include "libgen.h"
#include "sys/times.h"
#include "unistd.h"
#include <cstdio>
#include <errno.h>
#include <fcntl.h>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/signal.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/procfs.h>
#include <sys/resource.h>
#include <sys/time.h>
#include "GaudiKernel/ModuleInfo.h"
#include "GaudiKernel/System.h"
#include "ProcessDescriptor.h"
Include dependency graph for ProcessDescriptor.cpp:

Go to the source code of this file.

Classes

struct  linux_proc
 

Namespaces

 System
 Note: OS specific details for environment resolution.
 

Macros

#define GAUDIKERNEL_PROCSTAT_CPP
 
#define WINVER   0
 

Enumerations

enum  System::ProcessInfoCommand {
  System::ProcessBasicInformation, System::ProcessQuotaLimits, System::ProcessIoCounters, System::ProcessVmCounters,
  System::ProcessTimes, System::ProcessBasePriority, System::ProcessRaisePriority, System::ProcessDebugPort,
  System::ProcessExceptionPort, System::ProcessAccessToken, System::ProcessLdtInformation, System::ProcessLdtSize,
  System::ProcessDefaultHardErrorMode, System::ProcessIoPortHandlers, System::ProcessPooledUsageAndLimits, System::ProcessWorkingSetWatch,
  System::ProcessUserModeIOPL, System::ProcessEnableAlignmentFaultFixup, System::ProcessPriorityClass, System::ProcessWx86Information,
  System::ProcessHandleCount, System::ProcessAffinityMask, System::ProcessPriorityBoost, System::MaxProcessInfoClass,
  System::ProcessEllapsedTime
}
 

Functions

void readProcStat (long pid, linux_proc &pinfo)
 

Macro Definition Documentation

◆ GAUDIKERNEL_PROCSTAT_CPP

#define GAUDIKERNEL_PROCSTAT_CPP

Definition at line 25 of file ProcessDescriptor.cpp.

◆ WINVER

#define WINVER   0

Definition at line 80 of file ProcessDescriptor.cpp.

Function Documentation

◆ readProcStat()

void readProcStat ( long  pid,
linux_proc pinfo 
)

Definition at line 311 of file ProcessDescriptor.cpp.

311  {
312 
313  int cnt, fd;
314  char buf[512];
315 
316  std::ostringstream ost;
317 
318  ost << "/proc/" << pid << "/stat";
319  std::string fname = ost.str();
320  if ( ( fd = open( fname.c_str(), O_RDONLY ) ) < 0 ) {
321  std::cerr << "Failed to open " << ost.str() << std::endl;
322  return;
323  }
324 
325  lseek( fd, 0, SEEK_SET );
326  if ( ( cnt = read( fd, buf, sizeof( buf ) - 1 ) ) < 0 ) {
327  std::cout << "LINUX Read of Proc file failed:" << std::endl;
328  close( fd );
329  return;
330  }
331 
332  // Format
333  if ( cnt > 0 ) {
334  buf[cnt] = '\0';
335  sscanf( buf,
336  // 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 20 1 2 3 4 5 6 7 8 9
337  // 30 1 2 3 4 5
338  "%d %s %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %llu %lu %ld %lu %lu %lu %lu "
339  "%lu %lu %lu %lu %lu %lu %lu",
340  &pinfo.pid, pinfo.comm, &pinfo.state, &pinfo.ppid, &pinfo.pgrp, &pinfo.session, &pinfo.tty, &pinfo.tpgid,
341  &pinfo.flags, &pinfo.minflt, &pinfo.cminflt, &pinfo.majflt, &pinfo.cmajflt, &pinfo.utime, &pinfo.stime,
342  &pinfo.cutime, &pinfo.cstime, &pinfo.priority, &pinfo.nice, &pinfo.num_threads, &pinfo.itrealvalue,
343  &pinfo.starttime, &pinfo.vsize, &pinfo.rss, &pinfo.rlim, &pinfo.startcode, &pinfo.endcode,
344  &pinfo.startstack, &pinfo.kstkesp, &pinfo.kstkeip, &pinfo.signal, &pinfo.blocked, &pinfo.sigignore,
345  &pinfo.sigcatch, &pinfo.wchan );
346  }
347  close( fd );
348 }
unsigned long minflt
unsigned long kstkesp
unsigned long signal
unsigned long wchan
unsigned long sigcatch
T sscanf(T... args)
unsigned long flags
T endl(T... args)
def read(f, regex='.*', skipevents=0)
Definition: hivetimeline.py:33
STL class.
unsigned long vsize
T str(T... args)
unsigned long startstack
unsigned long cminflt
unsigned long majflt
unsigned long long starttime
unsigned long cmajflt
unsigned long kstkeip
unsigned long startcode
T c_str(T... args)
unsigned long utime
unsigned long blocked
unsigned long endcode
unsigned long stime
unsigned long sigignore
unsigned long rlim