mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:28:11 +00:00
ProcessManager: Add process owner's username to table view.
This commit is contained in:
parent
62b4f39cd4
commit
c1f5f2694b
3 changed files with 18 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
||||||
#include "ProcessTableModel.h"
|
#include "ProcessTableModel.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
enum Column {
|
enum Column {
|
||||||
PID = 0,
|
PID = 0,
|
||||||
State,
|
State,
|
||||||
|
User,
|
||||||
Priority,
|
Priority,
|
||||||
Linear,
|
Linear,
|
||||||
Physical,
|
Physical,
|
||||||
|
@ -15,6 +17,10 @@ enum Column {
|
||||||
|
|
||||||
ProcessTableModel::ProcessTableModel()
|
ProcessTableModel::ProcessTableModel()
|
||||||
{
|
{
|
||||||
|
setpwent();
|
||||||
|
while (auto* passwd = getpwent())
|
||||||
|
m_usernames.set(passwd->pw_uid, passwd->pw_name);
|
||||||
|
endpwent();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessTableModel::~ProcessTableModel()
|
ProcessTableModel::~ProcessTableModel()
|
||||||
|
@ -36,6 +42,7 @@ String ProcessTableModel::column_name(int column) const
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case Column::PID: return "PID";
|
case Column::PID: return "PID";
|
||||||
case Column::State: return "State";
|
case Column::State: return "State";
|
||||||
|
case Column::User: return "User";
|
||||||
case Column::Priority: return "Priority";
|
case Column::Priority: return "Priority";
|
||||||
case Column::Linear: return "Linear";
|
case Column::Linear: return "Linear";
|
||||||
case Column::Physical: return "Physical";
|
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::PID: return { 30, TextAlignment::CenterRight };
|
||||||
case Column::State: return { 80, TextAlignment::CenterLeft };
|
case Column::State: return { 80, TextAlignment::CenterLeft };
|
||||||
case Column::Priority: return { 75, 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::Linear: return { 70, TextAlignment::CenterRight };
|
||||||
case Column::Physical: return { 70, TextAlignment::CenterRight };
|
case Column::Physical: return { 70, TextAlignment::CenterRight };
|
||||||
case Column::CPU: return { 30, TextAlignment::CenterRight };
|
case Column::CPU: return { 30, TextAlignment::CenterRight };
|
||||||
|
@ -87,6 +95,7 @@ String ProcessTableModel::data(int row, int column) const
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case Column::PID: return String::format("%d", process.current_state.pid);
|
case Column::PID: return String::format("%d", process.current_state.pid);
|
||||||
case Column::State: return process.current_state.state;
|
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::Priority: return process.current_state.priority;
|
||||||
case Column::Linear: return pretty_byte_size(process.current_state.linear);
|
case Column::Linear: return pretty_byte_size(process.current_state.linear);
|
||||||
case Column::Physical: return pretty_byte_size(process.current_state.physical);
|
case Column::Physical: return pretty_byte_size(process.current_state.physical);
|
||||||
|
@ -128,8 +137,13 @@ void ProcessTableModel::update()
|
||||||
state.nsched = nsched;
|
state.nsched = nsched;
|
||||||
unsigned uid = parts[5].to_uint(ok);
|
unsigned uid = parts[5].to_uint(ok);
|
||||||
ASSERT(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.priority = parts[16];
|
||||||
state.state = parts[7];
|
state.state = parts[7];
|
||||||
state.name = parts[11];
|
state.name = parts[11];
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
ProcessState previous_state;
|
ProcessState previous_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HashMap<uid_t, String> m_usernames;
|
||||||
HashMap<pid_t, OwnPtr<Process>> m_processes;
|
HashMap<pid_t, OwnPtr<Process>> m_processes;
|
||||||
Vector<pid_t> m_pids;
|
Vector<pid_t> m_pids;
|
||||||
int m_selected_row { -1 };
|
int m_selected_row { -1 };
|
||||||
|
|
|
@ -71,7 +71,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto* window = new GWindow;
|
auto* window = new GWindow;
|
||||||
window->set_title("ProcessManager");
|
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_main_widget(widget);
|
||||||
window->set_should_exit_app_on_close(true);
|
window->set_should_exit_app_on_close(true);
|
||||||
window->show();
|
window->show();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue