ProcessDescriptor.cpp File Reference
#include <errno.h>
#include <string>
#include "unistd.h"
#include "libgen.h"
#include <cstdio>
#include <sstream>
#include <iostream>
#include <fcntl.h>
#include "sys/times.h"
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/syscall.h>
#include <sys/procfs.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "ProcessDescriptor.h"
#include "GaudiKernel/ModuleInfo.h"
#include "GaudiKernel/System.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 74 of file ProcessDescriptor.cpp.

Function Documentation

void readProcStat ( long  pid,
linux_proc pinfo 
)

Definition at line 305 of file ProcessDescriptor.cpp.

305  {
306 
307  int cnt, fd;
308  char buf[512];
309 
310  std::ostringstream ost;
311 
312  ost << "/proc/" << pid << "/stat";
313  std::string fname = ost.str();
314  if((fd=open(fname.c_str(),O_RDONLY))<0) {
315  std::cerr << "Failed to open " << ost.str() << std::endl;
316  return;
317  }
318 
319  lseek(fd,0,SEEK_SET);
320  if((cnt=read(fd,buf,sizeof(buf)))<0) {
321  std::cout << "LINUX Read of Proc file failed:" << std::endl;
322  close(fd);
323  return;
324  }
325 
326  // Format
327  if(cnt>0) {
328  buf[cnt]='\0';
329  sscanf(buf,
330  //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 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 %lu %lu %lu %lu %lu %lu %lu",
332  &pinfo.pid,
333  pinfo.comm,
334  &pinfo.state,
335  &pinfo.ppid,
336  &pinfo.pgrp,
337  &pinfo.session,
338  &pinfo.tty,
339  &pinfo.tpgid,
340  &pinfo.flags,
341  &pinfo.minflt,
342  &pinfo.cminflt,
343  &pinfo.majflt,
344  &pinfo.cmajflt,
345  &pinfo.utime,
346  &pinfo.stime,
347  &pinfo.cutime,
348  &pinfo.cstime,
349  &pinfo.priority,
350  &pinfo.nice,
351  &pinfo.num_threads,
352  &pinfo.itrealvalue,
353  &pinfo.starttime,
354  &pinfo.vsize,
355  &pinfo.rss,
356  &pinfo.rlim,
357  &pinfo.startcode,
358  &pinfo.endcode,
359  &pinfo.startstack,
360  &pinfo.kstkesp,
361  &pinfo.kstkeip,
362  &pinfo.signal,
363  &pinfo.blocked,
364  &pinfo.sigignore,
365  &pinfo.sigcatch,
366  &pinfo.wchan
367  );
368  }
369  close(fd);
370 }
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:19
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