summaryrefslogtreecommitdiff
path: root/Userland/ps.cpp
blob: a56da0c12d9e816f3dad6aa7752e68b2519cb55f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <LibCore/CFile.h>
#include <LibCore/CProcessStatisticsReader.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char** argv)
{
    (void)argc;
    (void)argv;

    printf("PID TPG PGP SID UID  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.starts_with("/dev/"))
            tty = tty.characters() + 5;
        else
            tty = "n/a";

        printf("%-3u %-3u %-3u %-3u %-3u  %-11s  %-3u  %-9u  %-3u %-5s %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());
    }

    return 0;
}