src/linux_parser.cpp
// Todo: Read and return the number of running processes
Read and return the number of running processes
Read and return the number of running processes
int LinuxParser::RunningProcesses() { 
    string filepath = kProcDirectory + kStatFilename;
    std::ifstream file = GetStream(filepath);
    string name = "procs_running";
    string token;
    int running_procs = 0;
    while(file >> token) {
        if(token == name) {
            if(file >> running_procs) {
            } else {
                file.close();
                throw std::runtime_error("Couldn't read total processes!!");
                return running_procs;       
            }
        }
        file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    }
    file.close();
    return running_procs; 
}
int LinuxParser :: RunningProcesses ( ) { string filepath = kProcDirectory + kStatFilename ; std :: ifstream file = GetStream ( filepath ) ; string name = " " ; string token ; int running_procs = 0 ; while ( file >> token ) { if ( token == name ) { if ( file >> running_procs ) { } else { file . close ( ) ; throw std :: runtime_error ( " " ) ; return running_procs ; } } file . ignore ( std :: numeric_limits < std :: streamsize > :: max ( ) , ' \n ' ) ; } file . close ( ) ; return running_procs ; }
Todo: Read and return the number of running processes
Todo : Read and return the number of running processes
// ignore rest of the line