src/linux_parser.cpp
// TODO: Read and return the user associated with a process
// REMOVE: [[maybe_unused]] once you define the function
Read and return the user associated with a process
REMOVE: [[maybe_unused]] once you define the function
Read and return the user associated with a process REMOVE : [[ maybe_unused ]] once you define the function
string LinuxParser::User(int pid) { 
  string uid, userid, x, username, line;
  username = "unassigned"; 
  uid = LinuxParser::Uid(pid);
  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 >> username >> x >> userid) {
        	if (userid == uid) { return username;}
        	}
      	}
    }
  return username;
}
string LinuxParser :: User ( int pid ) { string uid , userid , x , username , line ; username = " " ; uid = LinuxParser :: Uid ( pid ) ; 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 >> username >> x >> userid ) { if ( userid == uid ) { return username ; } } } } return username ; }
TODO: Read and return the user associated with a process
REMOVE: [[maybe_unused]] once you define the function
TODO : Read and return the user associated with a process REMOVE : [[ maybe_unused ]] once you define the function
//initial value to username if not found