All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
 
#define s_myPid   (::getpid())
 

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 s_myPid   (::getpid())

Definition at line 373 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.

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