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) { 
  std::ifstream UPTimeFile(kProcDirectory+to_string(pid)+kStatFilename);
  std::string line,content;
  if(UPTimeFile.is_open())
  {
     std::getline(UPTimeFile,line);
    std::istringstream mystream(line);
    for(int i=1; i <= 22; i++)
         {
           mystream >> content;
            if(content[0] == '(' && content[content.length()-1] != ')') 
              i--;
         }
     return 
     static_cast<long>
    (static_cast<float>(std::atol(content.c_str()))/sysconf(_SC_CLK_TCK));         
  }
  return 0;
 }
long LinuxParser :: UpTime ( int pid ) { std :: ifstream UPTimeFile ( kProcDirectory + to_string ( pid ) + kStatFilename ) ; std :: string line , content ; if ( UPTimeFile . is_open ( ) ) { std :: getline ( UPTimeFile , line ) ; std :: istringstream mystream ( line ) ; for ( int i = 1 ; i <= 22 ; i ++ ) { mystream >> content ; if ( content [ 0 ] == ' ' && content [ content . length ( ) - 1 ] != ' ' ) i -- ; } return static_cast < long > ( static_cast < float > ( std :: atol ( content . c_str ( ) ) ) / sysconf ( _SC_CLK_TCK ) ) ; } return 0 ; }
Read and return the uptime of a process
Read and return the uptime of a process