src/linux_parser.cpp
// Read and return the user associated with a process
Read and return the user associated with a process
Read and return the user associated with a process
string LinuxParser::User(int pid) { 
  string uid = LinuxParser::Uid(pid);
  string line, user, x, id;
  std::ifstream stream(kPasswordPath);
  if (stream.is_open()) {
    while (std::getline(stream, line)) {
      std::replace(line.begin(), line.end(), ':', ' ');
      std::istringstream linestream(line);
      while (linestream >> user >> x >> id) {
        if (id == uid) {
          return user;
        }
      }
    }
  }
  return user;
}
string LinuxParser :: User ( int pid ) { string uid = LinuxParser :: Uid ( pid ) ; string line , user , x , id ; std :: ifstream stream ( kPasswordPath ) ; if ( stream . is_open ( ) ) { while ( std :: getline ( stream , line ) ) { std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: istringstream linestream ( line ) ; while ( linestream >> user >> x >> id ) { if ( id == uid ) { return user ; } } } } return user ; }
Read and return the user associated with a process
Read and return the user associated with a process
// Grab the UID of the process using local class method  // Replace all colons with spaces to help parsing