/*
    * main.cpp
    * Process list command for MontaukOS userspace
    * Copyright (c) 2026 Daniel Hammer
*/

#include <montauk/syscall.h>
#include <libc/stdio.h>

extern "C" void _start() {
    static montauk::abi::ProcInfo processes[256];
    int n = montauk::proclist(processes, 256);

    if (n <= 0) {
        montauk::print("Failed to query processes.\n");
        montauk::exit(-1);
    }

    montauk::print("  PID\tHeap\tImage Name\n");

    for (int i = 0; i < n; i++) {
        unsigned heapMb = (unsigned)(processes[i].heapUsed / (1024 * 1024));

        printf("  %d\t%d MB\t%s\n", processes[i].pid, heapMb, processes[i].name);
    }

    montauk::exit(0);
}