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 = Uid(pid);
  string line, x, y, user;
  string name;
  std::ifstream stream(kPasswordPath);
  if (stream.is_open()) {
    while (std::getline(stream, line)) {
      std::replace(line.begin(), line.end(), ':', ' ');
      std::istringstream linestream(line);
      linestream >> x >> y >> user;
      if (user == uid) {
        name = x;
      }
    }
  }
  return name;
}
string LinuxParser :: User ( int pid ) { string uid = Uid ( pid ) ; string line , x , y , user ; string name ; std :: ifstream stream ( kPasswordPath ) ; if ( stream . is_open ( ) ) { while ( std :: getline ( stream , line ) ) { std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: istringstream linestream ( line ) ; linestream >> x >> y >> user ; if ( user == uid ) { name = x ; } } } return name ; }
Read and return the user associated with a process
Read and return the user associated with a process