mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 19:35:06 +00:00
HackStudio: Show the slave pty's PGID in the ProcessStateWidget
This is the closest I could figure out how to get to what's actively running on the terminal view at the moment. Perhaps we can bundle up every process with the same tty and sum it all up somehow. I'm not sure.
This commit is contained in:
parent
ef64e26317
commit
bced810880
3 changed files with 12 additions and 9 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include <LibCore/CTimer.h>
|
#include <LibCore/CTimer.h>
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
#include <LibGUI/GLabel.h>
|
#include <LibGUI/GLabel.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
ProcessStateWidget::ProcessStateWidget(GWidget* parent)
|
ProcessStateWidget::ProcessStateWidget(GWidget* parent)
|
||||||
: GWidget(parent)
|
: GWidget(parent)
|
||||||
|
@ -40,7 +41,7 @@ ProcessStateWidget::~ProcessStateWidget()
|
||||||
|
|
||||||
void ProcessStateWidget::refresh()
|
void ProcessStateWidget::refresh()
|
||||||
{
|
{
|
||||||
if (m_pid == -1) {
|
if (m_tty_fd == -1) {
|
||||||
m_pid_label->set_text("(none)");
|
m_pid_label->set_text("(none)");
|
||||||
m_state_label->set_text("n/a");
|
m_state_label->set_text("n/a");
|
||||||
m_cpu_label->set_text("n/a");
|
m_cpu_label->set_text("n/a");
|
||||||
|
@ -48,8 +49,10 @@ void ProcessStateWidget::refresh()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t pid = tcgetpgrp(m_tty_fd);
|
||||||
|
|
||||||
auto processes = CProcessStatisticsReader::get_all();
|
auto processes = CProcessStatisticsReader::get_all();
|
||||||
auto child_process_data = processes.get(m_pid);
|
auto child_process_data = processes.get(pid);
|
||||||
|
|
||||||
if (!child_process_data.has_value())
|
if (!child_process_data.has_value())
|
||||||
return;
|
return;
|
||||||
|
@ -58,14 +61,14 @@ void ProcessStateWidget::refresh()
|
||||||
|
|
||||||
auto& data = active_process_data.value();
|
auto& data = active_process_data.value();
|
||||||
|
|
||||||
m_pid_label->set_text(String::format("%s(%d)", data.name.characters(), m_pid));
|
m_pid_label->set_text(String::format("%s(%d)", data.name.characters(), pid));
|
||||||
m_state_label->set_text(data.state);
|
m_state_label->set_text(data.state);
|
||||||
m_cpu_label->set_text(String::format("%d", data.times_scheduled));
|
m_cpu_label->set_text(String::format("%d", data.times_scheduled));
|
||||||
m_memory_label->set_text(String::format("%d", data.amount_resident));
|
m_memory_label->set_text(String::format("%d", data.amount_resident));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessStateWidget::set_pid(pid_t pid)
|
void ProcessStateWidget::set_tty_fd(int tty_fd)
|
||||||
{
|
{
|
||||||
m_pid = pid;
|
m_tty_fd = tty_fd;
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class ProcessStateWidget final : public GWidget {
|
||||||
public:
|
public:
|
||||||
virtual ~ProcessStateWidget() override;
|
virtual ~ProcessStateWidget() override;
|
||||||
|
|
||||||
void set_pid(pid_t);
|
void set_tty_fd(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ProcessStateWidget(GWidget* parent);
|
explicit ProcessStateWidget(GWidget* parent);
|
||||||
|
@ -24,5 +24,5 @@ private:
|
||||||
|
|
||||||
RefPtr<CTimer> m_timer;
|
RefPtr<CTimer> m_timer;
|
||||||
|
|
||||||
pid_t m_pid { -1 };
|
int m_tty_fd { -1 };
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,7 +45,7 @@ void TerminalWrapper::run_command(const String& command)
|
||||||
} else if (WIFSIGNALED(wstatus)) {
|
} else if (WIFSIGNALED(wstatus)) {
|
||||||
m_terminal_widget->inject_string(String::format("\033[34;1m(Command signaled with %s!)\033[0m\n", strsignal(WTERMSIG(wstatus))));
|
m_terminal_widget->inject_string(String::format("\033[34;1m(Command signaled with %s!)\033[0m\n", strsignal(WTERMSIG(wstatus))));
|
||||||
}
|
}
|
||||||
m_process_state_widget->set_pid(-1);
|
m_process_state_widget->set_tty_fd(-1);
|
||||||
m_pid = -1;
|
m_pid = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ void TerminalWrapper::run_command(const String& command)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent process, cont'd.
|
// Parent process, cont'd.
|
||||||
m_process_state_widget->set_pid(m_pid);
|
m_process_state_widget->set_tty_fd(ptm_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalWrapper::TerminalWrapper(GWidget* parent)
|
TerminalWrapper::TerminalWrapper(GWidget* parent)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue