The Gaudi Framework  v29r0 (ff2e7097)
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

#define GAUDIKERNEL_PROCSTAT_CPP

Definition at line 15 of file ProcessDescriptor.cpp.

#define WINVER   0

Definition at line 72 of file ProcessDescriptor.cpp.

Function Documentation

void readProcStat ( long  pid,
linux_proc pinfo 
)

Definition at line 303 of file ProcessDescriptor.cpp.

304 {
305 
306  int cnt, fd;
307  char buf[512];
308 
309  std::ostringstream ost;
310 
311  ost << "/proc/" << pid << "/stat";
312  std::string fname = ost.str();
313  if ( ( fd = open( fname.c_str(), O_RDONLY ) ) < 0 ) {
314  std::cerr << "Failed to open " << ost.str() << std::endl;
315  return;
316  }
317 
318  lseek( fd, 0, SEEK_SET );
319  if ( ( cnt = read( fd, buf, sizeof( buf ) - 1 ) ) < 0 ) {
320  std::cout << "LINUX Read of Proc file failed:" << std::endl;
321  close( fd );
322  return;
323  }
324 
325  // Format
326  if ( cnt > 0 ) {
327  buf[cnt] = '\0';
328  sscanf( buf,
329  // 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
330  // 30 1 2 3 4 5
331  "%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 "
332  "%lu %lu %lu %lu %lu %lu %lu",
333  &pinfo.pid, pinfo.comm, &pinfo.state, &pinfo.ppid, &pinfo.pgrp, &pinfo.session, &pinfo.tty, &pinfo.tpgid,
334  &pinfo.flags, &pinfo.minflt, &pinfo.cminflt, &pinfo.majflt, &pinfo.cmajflt, &pinfo.utime, &pinfo.stime,
335  &pinfo.cutime, &pinfo.cstime, &pinfo.priority, &pinfo.nice, &pinfo.num_threads, &pinfo.itrealvalue,
336  &pinfo.starttime, &pinfo.vsize, &pinfo.rss, &pinfo.rlim, &pinfo.startcode, &pinfo.endcode,
337  &pinfo.startstack, &pinfo.kstkesp, &pinfo.kstkeip, &pinfo.signal, &pinfo.blocked, &pinfo.sigignore,
338  &pinfo.sigcatch, &pinfo.wchan );
339  }
340  close( fd );
341 }
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:22
STL class.
unsigned long vsize
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