src/linux_parser.cpp
// TODO: Read and return the memory used by a process
Read and return the memory used by a process
Read and return the memory used by a process
string LinuxParser::Ram(int pid) {
  string line, key, memory, kb;
  string filePath =
      kProcDirectory + "/" + to_string(pid) + "/" + kStatusFilename;
  std::ifstream istream(filePath);
  if (istream.is_open()) {
    while (std::getline(istream, line)) {
      std::replace(line.begin(), line.end(), ':', ' ');
      std::istringstream istringstream(line);
      istringstream >> key >> memory >> kb;
      if (key == "VmSize") return memory;
    }
  }
  return string();
}
string LinuxParser :: Ram ( int pid ) { string line , key , memory , kb ; string filePath = kProcDirectory + " " + to_string ( pid ) + " " + kStatusFilename ; std :: ifstream istream ( filePath ) ; if ( istream . is_open ( ) ) { while ( std :: getline ( istream , line ) ) { std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: istringstream istringstream ( line ) ; istringstream >> key >> memory >> kb ; if ( key == " " ) return memory ; } } return string ( ) ; }
TODO: Read and return the memory used by a process
TODO : Read and return the memory used by a process