src/linux_parser.cpp
// Read and return the uptime of a process
Read and return the uptime of a process
Read and return the uptime of a process
long LinuxParser::UpTime(int pid) {
  string line, time;
  vector<string> timeValues;
  long timeInit = 0;
  std::ifstream stream(kProcDirectory + std::to_string(pid) + kStatFilename);
  if (stream.is_open()) {
    std::getline(stream, line);
    std::istringstream linestream(line);
    while (linestream >> time) {
      timeValues.push_back(time);
    }
  }
  try {
    timeInit = stol(timeValues[21]) / sysconf(_SC_CLK_TCK);
  } catch (...) {
    timeInit = 0;
  }
  return timeInit;
}
long LinuxParser :: UpTime ( int pid ) { string line , time ; vector < string > timeValues ; long timeInit = 0 ; std :: ifstream stream ( kProcDirectory + std :: to_string ( pid ) + kStatFilename ) ; if ( stream . is_open ( ) ) { std :: getline ( stream , line ) ; std :: istringstream linestream ( line ) ; while ( linestream >> time ) { timeValues . push_back ( time ) ; } } try { timeInit = stol ( timeValues [ 21 ] ) / sysconf ( _SC_CLK_TCK ) ; } catch ( ... ) { timeInit = 0 ; } return timeInit ; }
Read and return the uptime of a process
Read and return the uptime of a process