src/linux_parser.cpp
// Todo: Read and return the user ID associated with a process
// REMOVE: [[maybe_unused]] once you define the function
Read and return the user ID associated with a process
REMOVE: [[maybe_unused]] once you define the function
Read and return the user ID associated with a process REMOVE : [[ maybe_unused ]] once you define the function
string LinuxParser::Uid(int pid) { 
    string uid_name = "Uid";
    string filepath = kProcDirectory + "/" + std::to_string(pid) + kStatusFilename;
    std::ifstream file = GetStream(filepath);
    string line;
    string uid = "";
    while(std::getline(file, line)) {
        if(line.compare(0, uid_name.size(), uid_name) == 0) {
            std::istringstream buf(line);
            std::istream_iterator<string> beg(buf), end;
            std::vector<string> values(beg, end);
            uid = values[1];
            break;
        }
    }
    file.close();
    return uid;
}
string LinuxParser :: Uid ( int pid ) { string uid_name = " " ; string filepath = kProcDirectory + " " + std :: to_string ( pid ) + kStatusFilename ; std :: ifstream file = GetStream ( filepath ) ; string line ; string uid = " " ; while ( std :: getline ( file , line ) ) { if ( line . compare ( 0 , uid_name . size ( ) , uid_name ) == 0 ) { std :: istringstream buf ( line ) ; std :: istream_iterator < string > beg ( buf ) , end ; std :: vector < string > values ( beg , end ) ; uid = values [ 1 ] ; break ; } } file . close ( ) ; return uid ; }
Todo: Read and return the user ID associated with a process
REMOVE: [[maybe_unused]] once you define the function
Todo : Read and return the user ID associated with a process REMOVE : [[ maybe_unused ]] once you define the function