Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noent/pids #30

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion include/linux_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ long IdleJiffies();

// Processes
std::string Command(int pid);
std::string Ram(int pid);
std::string Ram(const int pid);
std::string Uid(int pid);
std::string User(int pid);
long int UpTime(int pid);
Expand Down
27 changes: 15 additions & 12 deletions include/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
#define PROCESS_H

#include <string>
/*
Basic class for Process representation
It contains relevant attributes as shown below
*/

using std::string;

class Process {
public:
int Pid(); // TODO: See src/process.cpp
std::string User(); // TODO: See src/process.cpp
std::string Command(); // TODO: See src/process.cpp
float CpuUtilization(); // TODO: See src/process.cpp
std::string Ram(); // TODO: See src/process.cpp
long int UpTime(); // TODO: See src/process.cpp
bool operator<(Process const& a) const; // TODO: See src/process.cpp
Process(int);
int Pid() const; // DONE: See src/process.cpp
string User() const; // DONE: See src/process.cpp
string Command() const; // DONE: See src/process.cpp
float CpuUtilization(); // DONE: See src/process.cpp
string Ram(); // DONE: See src/process.cpp
long int UpTime(); // DONE: See src/process.cpp
bool operator<(Process const& a); // DONE: See src/process.cpp

// TODO: Declare any necessary private members
// DONE: Declare any necessary private members
private:
int pid_;
string user_;
string command_;
};

#endif
17 changes: 9 additions & 8 deletions include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

class System {
public:
Processor& Cpu(); // TODO: See src/system.cpp
std::vector<Process>& Processes(); // TODO: See src/system.cpp
float MemoryUtilization(); // TODO: See src/system.cpp
long UpTime(); // TODO: See src/system.cpp
int TotalProcesses(); // TODO: See src/system.cpp
int RunningProcesses(); // TODO: See src/system.cpp
std::string Kernel(); // TODO: See src/system.cpp
std::string OperatingSystem(); // TODO: See src/system.cpp
System();
Processor& Cpu(); // DONE: See src/system.cpp
std::vector<Process>& Processes(); // DONE: See src/system.cpp
float MemoryUtilization(); // DONE: See src/system.cpp
long UpTime(); // DONE: See src/system.cpp
int TotalProcesses(); // DONE: See src/system.cpp
int RunningProcesses(); // DONE: See src/system.cpp
std::string Kernel(); // DONE: See src/system.cpp
std::string OperatingSystem(); // DONE: See src/system.cpp

// TODO: Define any necessary private members
private:
Expand Down
23 changes: 18 additions & 5 deletions src/format.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
#include <string>

#include "format.h"

#include <sstream>
#include <string>

using std::string;

// TODO: Complete this helper function
// DONE: Complete this helper function
// INPUT: Long int measuring seconds
// OUTPUT: HH:MM:SS
// REMOVE: [[maybe_unused]] once you define the function
string Format::ElapsedTime(long seconds[[maybe_unused]]) { return string(); }
string Format::ElapsedTime(long seconds) {
long hours = seconds / 3600;
long minutes = (seconds % 3600) / 60;
long secs = seconds % 3600 % 60;
std::ostringstream formatted_time{};
string s_hours =
hours <= 9 ? "0" + std::to_string(hours) : std::to_string(hours);
string s_minutes =
minutes <= 9 ? "0" + std::to_string(minutes) : std::to_string(minutes);
string s_seconds =
secs <= 9 ? "0" + std::to_string(secs) : std::to_string(secs);
formatted_time << s_hours << ":" << s_minutes << ":" << s_seconds;
return formatted_time.str();
};
Loading
Loading