diff options
-rw-r--r-- | Applications/ProcessManager/ProcessTableModel.cpp | 18 | ||||
-rw-r--r-- | Applications/ProcessManager/ProcessTableModel.h | 1 | ||||
-rw-r--r-- | Applications/ProcessManager/main.cpp | 2 |
3 files changed, 18 insertions, 3 deletions
diff --git a/Applications/ProcessManager/ProcessTableModel.cpp b/Applications/ProcessManager/ProcessTableModel.cpp index 492717eb41..74cd8209d4 100644 --- a/Applications/ProcessManager/ProcessTableModel.cpp +++ b/Applications/ProcessManager/ProcessTableModel.cpp @@ -1,10 +1,12 @@ #include "ProcessTableModel.h" #include <fcntl.h> #include <stdio.h> +#include <pwd.h> enum Column { PID = 0, State, + User, Priority, Linear, Physical, @@ -15,6 +17,10 @@ enum Column { ProcessTableModel::ProcessTableModel() { + setpwent(); + while (auto* passwd = getpwent()) + m_usernames.set(passwd->pw_uid, passwd->pw_name); + endpwent(); } ProcessTableModel::~ProcessTableModel() @@ -36,6 +42,7 @@ String ProcessTableModel::column_name(int column) const switch (column) { case Column::PID: return "PID"; case Column::State: return "State"; + case Column::User: return "User"; case Column::Priority: return "Priority"; case Column::Linear: return "Linear"; case Column::Physical: return "Physical"; @@ -51,6 +58,7 @@ GTableModel::ColumnMetadata ProcessTableModel::column_metadata(int column) const case Column::PID: return { 30, TextAlignment::CenterRight }; case Column::State: return { 80, TextAlignment::CenterLeft }; case Column::Priority: return { 75, TextAlignment::CenterLeft }; + case Column::User: return { 60, TextAlignment::CenterLeft }; case Column::Linear: return { 70, TextAlignment::CenterRight }; case Column::Physical: return { 70, TextAlignment::CenterRight }; case Column::CPU: return { 30, TextAlignment::CenterRight }; @@ -87,6 +95,7 @@ String ProcessTableModel::data(int row, int column) const switch (column) { case Column::PID: return String::format("%d", process.current_state.pid); case Column::State: return process.current_state.state; + case Column::User: return process.current_state.user; case Column::Priority: return process.current_state.priority; case Column::Linear: return pretty_byte_size(process.current_state.linear); case Column::Physical: return pretty_byte_size(process.current_state.physical); @@ -128,8 +137,13 @@ void ProcessTableModel::update() state.nsched = nsched; unsigned uid = parts[5].to_uint(ok); ASSERT(ok); - //state.user = s_usernames->get(uid); - state.user = String::format("%u", uid); + { + auto it = m_usernames.find((uid_t)uid); + if (it != m_usernames.end()) + state.user = String::format("%s", (*it).value.characters()); + else + state.user = String::format("%u", uid); + } state.priority = parts[16]; state.state = parts[7]; state.name = parts[11]; diff --git a/Applications/ProcessManager/ProcessTableModel.h b/Applications/ProcessManager/ProcessTableModel.h index 4449a2bbc7..544aaeb5e8 100644 --- a/Applications/ProcessManager/ProcessTableModel.h +++ b/Applications/ProcessManager/ProcessTableModel.h @@ -40,6 +40,7 @@ private: ProcessState previous_state; }; + HashMap<uid_t, String> m_usernames; HashMap<pid_t, OwnPtr<Process>> m_processes; Vector<pid_t> m_pids; int m_selected_row { -1 }; diff --git a/Applications/ProcessManager/main.cpp b/Applications/ProcessManager/main.cpp index b5f6ce9258..24cd446be7 100644 --- a/Applications/ProcessManager/main.cpp +++ b/Applications/ProcessManager/main.cpp @@ -71,7 +71,7 @@ int main(int argc, char** argv) auto* window = new GWindow; window->set_title("ProcessManager"); - window->set_rect(20, 200, 600, 400); + window->set_rect(20, 200, 640, 400); window->set_main_widget(widget); window->set_should_exit_app_on_close(true); window->show(); |