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) { 
  std::string userid = Uid(pid);
  std::ifstream UserNameFile(kPasswordPath);
  std::string line;
   while (std::getline(UserNameFile,line))
  {
  auto index =  line.find_first_of(':')+3; 
  int i=index;
  int counter=0;
  for(;;i++) 
    if(line[i] == ':')  
       {break;}
    else 
      counter++;
  if(line.substr(index,counter) == userid)
    return line.substr(0,line.find_first_of(':'));
  }
  return "";
 }
string LinuxParser :: User ( int pid ) { std :: string userid = Uid ( pid ) ; std :: ifstream UserNameFile ( kPasswordPath ) ; std :: string line ; while ( std :: getline ( UserNameFile , line ) ) { auto index = line . find_first_of ( ' ' ) + 3 ; int i = index ; int counter = 0 ; for ( ; ; i ++ ) if ( line [ i ] == ' ' ) { break ; } else counter ++ ; if ( line . substr ( index , counter ) == userid ) return line . substr ( 0 , line . find_first_of ( ' ' ) ) ; } return " " ; }
Read and return the user associated with a process
Read and return the user associated with a process