diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index e5a340239eb..c139c97be7b 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -39,7 +39,6 @@ enum ProcFileType { FI_Root_kmalloc, FI_Root_all, FI_Root_memstat, - FI_Root_summary, FI_Root_cpuinfo, FI_Root_inodes, FI_Root_dmesg, @@ -541,29 +540,6 @@ ByteBuffer procfs$kmalloc(InodeIdentifier) return builder.to_byte_buffer(); } -ByteBuffer procfs$summary(InodeIdentifier) -{ - InterruptDisabler disabler; - auto processes = Process::all_processes(); - StringBuilder builder; - builder.appendf("PID TPG PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n"); - for (auto* process : processes) { - builder.appendf("%-3u %-3u %-3u %-3u %-4u %-8s %-3u %-9u %-3u %-4s %s\n", - process->pid(), - process->tty() ? process->tty()->pgid() : 0, - process->pgid(), - process->sid(), - process->uid(), - to_string(process->state()), - process->ppid(), - process->main_thread().times_scheduled(), // FIXME(Thread): Bill all scheds to the process - process->number_of_open_file_descriptors(), - process->tty() ? strrchr(process->tty()->tty_name().characters(), '/') + 1 : "n/a", - process->name().characters()); - } - return builder.to_byte_buffer(); -} - ByteBuffer procfs$memstat(InodeIdentifier) { InterruptDisabler disabler; @@ -592,6 +568,7 @@ ByteBuffer procfs$all(InodeIdentifier) process_object.set("pid", process.pid()); process_object.set("times_scheduled", process.main_thread().times_scheduled()); process_object.set("pgid", process.tty() ? process.tty()->pgid() : 0); + process_object.set("pgp", process.pgid()); process_object.set("sid", process.sid()); process_object.set("uid", process.uid()); process_object.set("gid", process.gid()); @@ -1120,7 +1097,6 @@ ProcFS::ProcFS() m_entries[FI_Root_kmalloc] = { "kmalloc", FI_Root_kmalloc, procfs$kmalloc }; m_entries[FI_Root_all] = { "all", FI_Root_all, procfs$all }; m_entries[FI_Root_memstat] = { "memstat", FI_Root_memstat, procfs$memstat }; - m_entries[FI_Root_summary] = { "summary", FI_Root_summary, procfs$summary }; m_entries[FI_Root_cpuinfo] = { "cpuinfo", FI_Root_cpuinfo, procfs$cpuinfo }; m_entries[FI_Root_inodes] = { "inodes", FI_Root_inodes, procfs$inodes }; m_entries[FI_Root_dmesg] = { "dmesg", FI_Root_dmesg, procfs$dmesg }; diff --git a/Libraries/LibCore/CProcessStatisticsReader.cpp b/Libraries/LibCore/CProcessStatisticsReader.cpp index 74331797df7..d0e521762c3 100644 --- a/Libraries/LibCore/CProcessStatisticsReader.cpp +++ b/Libraries/LibCore/CProcessStatisticsReader.cpp @@ -28,6 +28,7 @@ HashMap CProcessStatisticsReader::get_all() process.pid = process_object.get("pid").to_u32(); process.times_scheduled = process_object.get("times_scheduled").to_u32(); process.pgid = process_object.get("pgid").to_u32(); + process.pgp = process_object.get("pgp").to_u32(); process.sid = process_object.get("sid").to_u32(); process.uid = process_object.get("uid").to_u32(); process.gid = process_object.get("gid").to_u32(); diff --git a/Libraries/LibCore/CProcessStatisticsReader.h b/Libraries/LibCore/CProcessStatisticsReader.h index 034b97a3638..1e15dbc5603 100644 --- a/Libraries/LibCore/CProcessStatisticsReader.h +++ b/Libraries/LibCore/CProcessStatisticsReader.h @@ -9,6 +9,7 @@ struct CProcessStatistics { pid_t pid; unsigned times_scheduled; unsigned pgid; + unsigned pgp; unsigned sid; uid_t uid; gid_t gid; diff --git a/Userland/ps.cpp b/Userland/ps.cpp index 2485b36057f..babb7674367 100644 --- a/Userland/ps.cpp +++ b/Userland/ps.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -8,13 +9,30 @@ int main(int argc, char** argv) (void)argc; (void)argv; - CFile f("/proc/summary"); - if (!f.open(CIODevice::ReadOnly)) { - fprintf(stderr, "open: failed to open /proc/summary: %s", f.error_string()); - return 1; + printf("PID TPG PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n"); + + auto all_processes = CProcessStatisticsReader::get_all(); + + for (const auto& it : all_processes) { + const auto& proc = it.value; + auto tty = proc.tty; + + if (tty != "notty") + tty = strrchr(tty.characters(), '/') + 1; + + printf("%-3u %-3u %-3u %-3u %-4u %-8s %-3u %-9u %-3u %-4s %s\n", + proc.pid, + proc.pgid, + proc.pgp, + proc.sid, + proc.uid, + proc.state.characters(), + proc.ppid, + proc.times_scheduled, + proc.nfds, + tty.characters(), + proc.name.characters()); } - const auto& b = f.read_all(); - for (auto i = 0; i < b.size(); ++i) - putchar(b[i]); + return 0; }