The Gaudi Framework  master (26b0761c)
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 279 of file ProcessDescriptor.cpp.

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