The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
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

namespace  System
 Note: OS specific details for environment resolution.
 

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)
 

Function Documentation

◆ readProcStat()

void readProcStat ( long pid,
linux_proc & pinfo )

Definition at line 274 of file ProcessDescriptor.cpp.

274 {
275
276 ssize_t cnt;
277 int fd;
278 char buf[512];
279
280 std::ostringstream ost;
281
282 ost << "/proc/" << pid << "/stat";
283 std::string fname = ost.str();
284 if ( ( fd = open( fname.c_str(), O_RDONLY ) ) < 0 ) {
285 std::cerr << "Failed to open " << ost.str() << std::endl;
286 return;
287 }
288
289 lseek( fd, 0, SEEK_SET );
290 if ( ( cnt = read( fd, buf, sizeof( buf ) - 1 ) ) < 0 ) {
291 std::cout << "LINUX Read of Proc file failed:" << std::endl;
292 close( fd );
293 return;
294 }
295
296 // Format
297 if ( cnt > 0 ) {
298 buf[cnt] = '\0';
299 sscanf(
300 buf,
301 // 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
302 // 30 1 2 3 4 5
303 "%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 "
304 "%lu %lu %lu %lu %lu %lu %lu",
305 &pinfo.pid, pinfo.comm, &pinfo.state, &pinfo.ppid, &pinfo.pgrp, &pinfo.session, &pinfo.tty, &pinfo.tpgid,
306 &pinfo.flags, &pinfo.minflt, &pinfo.cminflt, &pinfo.majflt, &pinfo.cmajflt, &pinfo.utime, &pinfo.stime,
307 &pinfo.cutime, &pinfo.cstime, &pinfo.priority, &pinfo.nice, &pinfo.num_threads, &pinfo.itrealvalue,
308 &pinfo.starttime, &pinfo.vsize, &pinfo.rss, &pinfo.rlim, &pinfo.startcode, &pinfo.endcode, &pinfo.startstack,
309 &pinfo.kstkesp, &pinfo.kstkeip, &pinfo.signal, &pinfo.blocked, &pinfo.sigignore, &pinfo.sigcatch,
310 &pinfo.wchan );
311 }
312 close( fd );
313}
read(f, regex=".*", skipevents=0)
unsigned long utime
unsigned long flags
unsigned long rlim
unsigned long vsize
unsigned long endcode
unsigned long startcode
unsigned long blocked
unsigned long signal
unsigned long cmajflt
unsigned long startstack
unsigned long majflt
unsigned long minflt
unsigned long stime
unsigned long long starttime
unsigned long sigcatch
unsigned long sigignore
unsigned long kstkeip
unsigned long kstkesp
unsigned long wchan
unsigned long cminflt