The Gaudi Framework  master (37c0b60a)
ProcessDescriptor.cpp File Reference
#include <cstdio>
#include <errno.h>
#include <fcntl.h>
#include <iostream>
#include <libgen.h>
#include <sstream>
#include <string>
#include <sys/signal.h>
#include <sys/syscall.h>
#include <sys/times.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/procfs.h>
#include <sys/resource.h>
#include <sys/time.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

◆ GAUDIKERNEL_PROCSTAT_CPP

#define GAUDIKERNEL_PROCSTAT_CPP

Definition at line 26 of file ProcessDescriptor.cpp.

◆ WINVER

#define WINVER   0

Definition at line 81 of file ProcessDescriptor.cpp.

Function Documentation

◆ readProcStat()

void readProcStat ( long  pid,
linux_proc pinfo 
)

Definition at line 310 of file ProcessDescriptor.cpp.

310  {
311 
312  ssize_t cnt;
313  int 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(
336  buf,
337  // 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
338  // 30 1 2 3 4 5
339  "%d %400s %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 "
340  "%lu %lu %lu %lu %lu %lu %lu",
341  &pinfo.pid, pinfo.comm, &pinfo.state, &pinfo.ppid, &pinfo.pgrp, &pinfo.session, &pinfo.tty, &pinfo.tpgid,
342  &pinfo.flags, &pinfo.minflt, &pinfo.cminflt, &pinfo.majflt, &pinfo.cmajflt, &pinfo.utime, &pinfo.stime,
343  &pinfo.cutime, &pinfo.cstime, &pinfo.priority, &pinfo.nice, &pinfo.num_threads, &pinfo.itrealvalue,
344  &pinfo.starttime, &pinfo.vsize, &pinfo.rss, &pinfo.rlim, &pinfo.startcode, &pinfo.endcode, &pinfo.startstack,
345  &pinfo.kstkesp, &pinfo.kstkeip, &pinfo.signal, &pinfo.blocked, &pinfo.sigignore, &pinfo.sigcatch,
346  &pinfo.wchan );
347  }
348  close( fd );
349 }
linux_proc::blocked
unsigned long blocked
Definition: ProcessDescriptor.cpp:299
linux_proc::vsize
unsigned long vsize
Definition: ProcessDescriptor.cpp:290
linux_proc::rss
long rss
Definition: ProcessDescriptor.cpp:291
std::string
STL class.
linux_proc::endcode
unsigned long endcode
Definition: ProcessDescriptor.cpp:294
linux_proc::comm
char comm[400]
Definition: ProcessDescriptor.cpp:269
linux_proc::starttime
unsigned long long starttime
Definition: ProcessDescriptor.cpp:289
linux_proc::tty
int tty
Definition: ProcessDescriptor.cpp:274
gaudirun.fd
fd
Definition: gaudirun.py:630
linux_proc::startcode
unsigned long startcode
Definition: ProcessDescriptor.cpp:293
linux_proc::itrealvalue
long itrealvalue
Definition: ProcessDescriptor.cpp:288
linux_proc::wchan
unsigned long wchan
Definition: ProcessDescriptor.cpp:302
std::sscanf
T sscanf(T... args)
linux_proc::ppid
int ppid
Definition: ProcessDescriptor.cpp:271
linux_proc::tpgid
int tpgid
Definition: ProcessDescriptor.cpp:275
linux_proc::priority
long priority
Definition: ProcessDescriptor.cpp:285
linux_proc::majflt
unsigned long majflt
Definition: ProcessDescriptor.cpp:279
linux_proc::flags
unsigned long flags
Definition: ProcessDescriptor.cpp:276
linux_proc::stime
unsigned long stime
Definition: ProcessDescriptor.cpp:282
linux_proc::num_threads
long num_threads
Definition: ProcessDescriptor.cpp:287
linux_proc::rlim
unsigned long rlim
Definition: ProcessDescriptor.cpp:292
std::cerr
std::string::c_str
T c_str(T... args)
linux_proc::startstack
unsigned long startstack
Definition: ProcessDescriptor.cpp:295
linux_proc::cminflt
unsigned long cminflt
Definition: ProcessDescriptor.cpp:278
linux_proc::signal
unsigned long signal
Definition: ProcessDescriptor.cpp:298
linux_proc::minflt
unsigned long minflt
Definition: ProcessDescriptor.cpp:277
linux_proc::pgrp
int pgrp
Definition: ProcessDescriptor.cpp:272
linux_proc::kstkesp
unsigned long kstkesp
Definition: ProcessDescriptor.cpp:296
linux_proc::sigcatch
unsigned long sigcatch
Definition: ProcessDescriptor.cpp:301
linux_proc::pid
int pid
Definition: ProcessDescriptor.cpp:268
std::ostringstream
STL class.
hivetimeline.read
def read(f, regex=".*", skipevents=0)
Definition: hivetimeline.py:32
std::endl
T endl(T... args)
linux_proc::state
char state
Definition: ProcessDescriptor.cpp:270
linux_proc::sigignore
unsigned long sigignore
Definition: ProcessDescriptor.cpp:300
linux_proc::session
int session
Definition: ProcessDescriptor.cpp:273
std::ostringstream::str
T str(T... args)
linux_proc::cmajflt
unsigned long cmajflt
Definition: ProcessDescriptor.cpp:280
linux_proc::kstkeip
unsigned long kstkeip
Definition: ProcessDescriptor.cpp:297
linux_proc::utime
unsigned long utime
Definition: ProcessDescriptor.cpp:281
linux_proc::nice
long nice
Definition: ProcessDescriptor.cpp:286
linux_proc::cstime
long cstime
Definition: ProcessDescriptor.cpp:284
linux_proc::cutime
long cutime
Definition: ProcessDescriptor.cpp:283