From f95dccdb45ad619549e74e4f480c041200de9dfa Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 9 Jun 2023 17:22:07 +0100 Subject: [PATCH] Kernel+LibCore: Add process creation time to `/sys/kernel/processes` --- Kernel/FileSystem/SysFS/Subsystems/Kernel/Processes.cpp | 1 + Userland/Libraries/LibCore/ProcessStatisticsReader.cpp | 1 + Userland/Libraries/LibCore/ProcessStatisticsReader.h | 2 ++ 3 files changed, 4 insertions(+) diff --git a/Kernel/FileSystem/SysFS/Subsystems/Kernel/Processes.cpp b/Kernel/FileSystem/SysFS/Subsystems/Kernel/Processes.cpp index 1b21e1b0e17..c07618cb8c4 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Kernel/Processes.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Kernel/Processes.cpp @@ -83,6 +83,7 @@ ErrorOr SysFSOverallProcesses::try_generate(KBufferBuilder& builder) } TRY(process.name().with([&](auto& process_name) { return process_object.add("name"sv, process_name->view()); })); TRY(process_object.add("executable"sv, process.executable() ? TRY(process.executable()->try_serialize_absolute_path())->view() : ""sv)); + TRY(process_object.add("creation_time"sv, process.creation_time().nanoseconds_since_epoch())); size_t amount_virtual = 0; size_t amount_resident = 0; diff --git a/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp b/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp index 651e3ad2642..aff504a9e45 100644 --- a/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp +++ b/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp @@ -42,6 +42,7 @@ ErrorOr ProcessStatisticsReader::get_all(SeekableStream& process.tty = process_object.get_deprecated_string("tty"sv).value_or(""); process.pledge = process_object.get_deprecated_string("pledge"sv).value_or(""); process.veil = process_object.get_deprecated_string("veil"sv).value_or(""); + process.creation_time = UnixDateTime::from_nanoseconds_since_epoch(process_object.get_i64("creation_time"sv).value_or(0)); process.amount_virtual = process_object.get_u32("amount_virtual"sv).value_or(0); process.amount_resident = process_object.get_u32("amount_resident"sv).value_or(0); process.amount_shared = process_object.get_u32("amount_shared"sv).value_or(0); diff --git a/Userland/Libraries/LibCore/ProcessStatisticsReader.h b/Userland/Libraries/LibCore/ProcessStatisticsReader.h index ffdd8a69dc7..c42576dab95 100644 --- a/Userland/Libraries/LibCore/ProcessStatisticsReader.h +++ b/Userland/Libraries/LibCore/ProcessStatisticsReader.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -49,6 +50,7 @@ struct ProcessStatistics { DeprecatedString tty; DeprecatedString pledge; DeprecatedString veil; + UnixDateTime creation_time; size_t amount_virtual; size_t amount_resident; size_t amount_shared;