src/linux_parser.cpp
// TODO: Read and return the memory used by a process
// REMOVE: [[maybe_unused]] once you define the function
Read and return the memory used by a process
REMOVE: [[maybe_unused]] once you define the function
Read and return the memory used by a process REMOVE : [[ maybe_unused ]] once you define the function
string LinuxParser::Ram(int pid) {
  string line, key, value, kB;
  int val;
  value = "NA"; 
  std::ifstream stream(kProcDirectory + std::to_string(pid) + kStatusFilename);
  if (stream.is_open()) {
    while (std::getline(stream, line)){
  		std::istringstream linestream(line);
    	while (linestream >> key >> value >> kB) {
        	if (key == "VmSize:") {
                val = std::stoi(value)/1024;
            	  return std::to_string(val); 
              }
        	}
      	}
    }
  return value; 
}
string LinuxParser :: Ram ( int pid ) { string line , key , value , kB ; int val ; value = " " ; std :: ifstream stream ( kProcDirectory + std :: to_string ( pid ) + kStatusFilename ) ; if ( stream . is_open ( ) ) { while ( std :: getline ( stream , line ) ) { std :: istringstream linestream ( line ) ; while ( linestream >> key >> value >> kB ) { if ( key == " " ) { val = std :: stoi ( value ) / 1024 ; return std :: to_string ( val ) ; } } } } return value ; }
TODO: Read and return the memory used by a process
REMOVE: [[maybe_unused]] once you define the function
TODO : Read and return the memory used by a process REMOVE : [[ maybe_unused ]] once you define the function
//initilization value if not found // Value returned is converted to Mb