src/linux_parser.cpp
// TODO: Read and return the uptime of a process
// REMOVE: [[maybe_unused]] once you define the function
Read and return the uptime of a process
REMOVE: [[maybe_unused]] once you define the function
Read and return the uptime of a process REMOVE : [[ maybe_unused ]] once you define the function
long LinuxParser::UpTime(int pid) {
  vector<string> data;
  string line, value;
  long upTime;
  std::ifstream stream(kProcDirectory + std::to_string(pid) + kStatFilename); 
  if (stream.is_open()) { 
    std::getline(stream, line); 
    std::istringstream linestream(line); 
    while (linestream >> value) { 
			data.push_back(value); 
        }
    }
    try{
      upTime = LinuxParser::UpTime() - std::stol(data[21]) / sysconf(_SC_CLK_TCK); 
    }
    catch (std::runtime_error& e) {
          std::cout << "Exception occurred" << std::endl << e.what();
    }
   return upTime;
}
long LinuxParser :: UpTime ( int pid ) { vector < string > data ; string line , value ; long upTime ; std :: ifstream stream ( kProcDirectory + std :: to_string ( pid ) + kStatFilename ) ; if ( stream . is_open ( ) ) { std :: getline ( stream , line ) ; std :: istringstream linestream ( line ) ; while ( linestream >> value ) { data . push_back ( value ) ; } } try { upTime = LinuxParser :: UpTime ( ) - std :: stol ( data [ 21 ] ) / sysconf ( _SC_CLK_TCK ) ; } catch ( std :: runtime_error & e ) { std :: cout << " " << std :: endl << e . what ( ) ; } return upTime ; }
TODO: Read and return the uptime of a process
REMOVE: [[maybe_unused]] once you define the function
TODO : Read and return the uptime of a process REMOVE : [[ maybe_unused ]] once you define the function
//Create a steam for reading Process data //Open file //Read line //convert line to line stream //read word by word in the line till finished //Add each word to vector to use later to access each data seperatly  // Convert from CLK ticket to Seconds