fix: fixes for shell/Terminal issues and CPU burn
This commit is contained in:
@@ -233,11 +233,14 @@ static int window_visible_rows() {
|
||||
return mtk::table_visible_rows(window_table_layout());
|
||||
}
|
||||
|
||||
static bool process_state_alive(uint8_t state) {
|
||||
return state == 1 || state == 2 || state == 3;
|
||||
}
|
||||
|
||||
static int live_process_count() {
|
||||
int count = 0;
|
||||
for (int i = 0; i < g_pm.proc_count; i++) {
|
||||
uint8_t state = g_pm.procs[i].state;
|
||||
if (state == 1 || state == 2 || state == 3)
|
||||
if (process_state_alive(g_pm.procs[i].state))
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
@@ -246,13 +249,24 @@ static int live_process_count() {
|
||||
static uint64_t total_process_heap() {
|
||||
uint64_t total = 0;
|
||||
for (int i = 0; i < g_pm.proc_count; i++) {
|
||||
uint8_t state = g_pm.procs[i].state;
|
||||
if (state == 1 || state == 2 || state == 3)
|
||||
if (process_state_alive(g_pm.procs[i].state))
|
||||
total += g_pm.procs[i].heapUsed;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static void collect_descendant_pids(int parent_pid, int* pids, int* count, int max_count) {
|
||||
for (int i = 0; i < g_pm.proc_count; i++) {
|
||||
if (!process_state_alive(g_pm.procs[i].state)) continue;
|
||||
if (g_pm.procs[i].parentPid != parent_pid) continue;
|
||||
|
||||
int child_pid = g_pm.procs[i].pid;
|
||||
collect_descendant_pids(child_pid, pids, count, max_count);
|
||||
if (*count < max_count)
|
||||
pids[(*count)++] = child_pid;
|
||||
}
|
||||
}
|
||||
|
||||
static int find_prev_cpu_snapshot(int pid) {
|
||||
for (int i = 0; i < g_pm.prev_cpu_count; i++) {
|
||||
if (g_pm.prev_cpu[i].pid == pid)
|
||||
@@ -390,7 +404,15 @@ static void kill_selected() {
|
||||
if (!can_kill_selected())
|
||||
return;
|
||||
|
||||
montauk::kill(g_pm.procs[g_pm.selected].pid);
|
||||
int root_pid = g_pm.procs[g_pm.selected].pid;
|
||||
int descendants[PM_MAX_PROCS];
|
||||
int descendant_count = 0;
|
||||
collect_descendant_pids(root_pid, descendants, &descendant_count, PM_MAX_PROCS);
|
||||
|
||||
for (int i = 0; i < descendant_count; i++)
|
||||
montauk::kill(descendants[i]);
|
||||
|
||||
montauk::kill(root_pid);
|
||||
refresh_state(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user