1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

ps: Port to using CProcessStatisticsReader and /proc/all

Drop /proc/summary in the process.
We only needed one new field here, thankfully, so this was quite straightforward.
This commit is contained in:
Robin Burchell 2019-07-17 21:24:47 +02:00 committed by Andreas Kling
parent a9d1a86e6e
commit 57da716be0
4 changed files with 28 additions and 32 deletions

View file

@ -1,4 +1,5 @@
#include <LibCore/CFile.h>
#include <LibCore/CProcessStatisticsReader.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
@ -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;
}