pctl format output as a table

This commit is contained in:
2025-09-18 11:22:09 +02:00
parent e5e707eb54
commit 9e9d2c5190
3 changed files with 27 additions and 12 deletions

19
user/pctl/ls.c Normal file
View File

@ -0,0 +1,19 @@
#include <stddef.h>
#include <stdint.h>
#include <system/system.h>
#include <sysdefs/processctl.h>
#include <util/util.h>
#include <errors.h>
#include <uprintf.h>
void pctl_ls(void) {
uint64_t procslen = processctl(-1, PCTL_PLS_SZ, 0, 0, 0);
uprintf("%-80s %s %-6s\n", "NAME", "PID", "TYPE");
for (size_t i = 0; i < procslen; i++) {
ProcStat stat = ZERO(&stat);
int32_t r = processctl(-1, PCTL_PLS_STAT, i, (uint64_t)&stat, 0);
if (r == E_OK) {
uprintf("%-80s %3lu %-6s\n", stat.name, stat.pid, stat.kern ? "KERNEL" : "USER");
}
}
}

6
user/pctl/ls.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef PCTL_LS_H_
#define PCTL_LS_H_
void pctl_ls(void);
#endif // PCTL_LS_H_

View File

@ -1,12 +1,9 @@
#include <stddef.h>
#include <stdint.h>
#include <system/system.h>
#include <sysdefs/processctl.h>
#include <uprintf.h>
#include <args/args.h>
#include <string/string.h>
#include <util/util.h>
#include <errors.h>
#include "ls.h"
void main(void) {
if (argslen() == 0) {
@ -16,14 +13,7 @@ void main(void) {
char *cmd = args()[0];
if (string_strcmp(cmd, "ls") == 0) {
uint64_t procslen = processctl(-1, PCTL_PLS_SZ, 0, 0, 0);
for (size_t i = 0; i < procslen; i++) {
ProcStat stat = ZERO(&stat);
int32_t r = processctl(-1, PCTL_PLS_STAT, i, (uint64_t)&stat, 0);
if (r == E_OK) {
uprintf("%-30s %lu %-6s\n", stat.name, stat.pid, stat.kern ? "KERNEL" : "USER");
}
}
pctl_ls();
} else {
uprintf("pctl: unknown command\n");
}