diff --git a/Userland/Applications/SystemMonitor/ProcessModel.cpp b/Userland/Applications/SystemMonitor/ProcessModel.cpp index 28e247dd0ae..9b6e45b9cc6 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.cpp +++ b/Userland/Applications/SystemMonitor/ProcessModel.cpp @@ -440,10 +440,25 @@ static DeprecatedString read_command_line(pid_t pid) return string_or_error.release_value(); } +ErrorOr ProcessModel::initialize_process_statistics_file() +{ + if (!m_process_statistics_file || !m_process_statistics_file->is_open()) + m_process_statistics_file = TRY(Core::File::open("/sys/kernel/processes"sv, Core::File::OpenMode::Read)); + + return {}; +} + void ProcessModel::update() { + auto result = initialize_process_statistics_file(); + if (result.is_error()) { + dbgln("Process model couldn't be updated: {}", result.release_error()); + return; + } + + auto all_processes = Core::ProcessStatisticsReader::get_all(*m_process_statistics_file, true); + auto previous_tid_count = m_threads.size(); - auto all_processes = Core::ProcessStatisticsReader::get_all(true); HashTable live_tids; u64 total_time_scheduled_diff = 0; diff --git a/Userland/Applications/SystemMonitor/ProcessModel.h b/Userland/Applications/SystemMonitor/ProcessModel.h index 973008cf69a..6909196d961 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.h +++ b/Userland/Applications/SystemMonitor/ProcessModel.h @@ -240,6 +240,10 @@ private: int thread_model_row(Thread const& thread) const; + ErrorOr initialize_process_statistics_file(); + + OwnPtr m_process_statistics_file; + // The thread list contains the same threads as the Process structs. HashMap> m_threads; Vector> m_processes;