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, value;
  std::ifstream stream(kProcDirectory + to_string(pid) + kStatFilename);
  if (stream.is_open()) {
    std::getline(stream, line);
    std::istringstream linestream(line);
    for (int i=1; i<=22; i++) {
      linestream >> value;
    }
  }
  return LinuxParser::UpTime() - (stol(value) / sysconf(_SC_CLK_TCK));
}
long LinuxParser :: UpTime ( int pid ) { string line , value ; std :: ifstream stream ( kProcDirectory + to_string ( pid ) + kStatFilename ) ; if ( stream . is_open ( ) ) { std :: getline ( stream , line ) ; std :: istringstream linestream ( line ) ; for ( int i = 1 ; i <= 22 ; i ++ ) { linestream >> value ; } } return LinuxParser :: UpTime ( ) - ( stol ( value ) / sysconf ( _SC_CLK_TCK ) ) ; }
Read and return the uptime of a process
Read and return the uptime of a process
// Only need to get the single line in stat and parse through that // Pop off values from the line stream until the 22nd value which is "starttime" // Cleaner way to do this??? // Convert clock ticks to seconds and return the (total system uptime - process start time)