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) 
{
  std::string line;
  std::string col1, col2, col3;
  std::string user;
  std::string uid = Uid(pid);
  std::ifstream fileStream(kPasswordPath);
  if(fileStream.is_open())
  {
    while(getline(fileStream,line))
    {
      std::replace(line.begin(),line.end(),':',' ');
      std::stringstream linestream(line);
      linestream >> col1 >> col2 >> col3;
      if(col3 == uid)
      {
        user = col1;
        break;
      }
    }
  }
  return user;
}
string LinuxParser :: User ( int pid ) { std :: string line ; std :: string col1 , col2 , col3 ; std :: string user ; std :: string uid = Uid ( pid ) ; std :: ifstream fileStream ( kPasswordPath ) ; if ( fileStream . is_open ( ) ) { while ( getline ( fileStream , line ) ) { std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: stringstream linestream ( line ) ; linestream >> col1 >> col2 >> col3 ; if ( col3 == uid ) { user = col1 ; break ; } } } return user ; }
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