pctl format output as a table
This commit is contained in:
19
user/pctl/ls.c
Normal file
19
user/pctl/ls.c
Normal 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
6
user/pctl/ls.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef PCTL_LS_H_
|
||||||
|
#define PCTL_LS_H_
|
||||||
|
|
||||||
|
void pctl_ls(void);
|
||||||
|
|
||||||
|
#endif // PCTL_LS_H_
|
@ -1,12 +1,9 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <system/system.h>
|
|
||||||
#include <sysdefs/processctl.h>
|
|
||||||
#include <uprintf.h>
|
#include <uprintf.h>
|
||||||
#include <args/args.h>
|
#include <args/args.h>
|
||||||
#include <string/string.h>
|
#include <string/string.h>
|
||||||
#include <util/util.h>
|
#include "ls.h"
|
||||||
#include <errors.h>
|
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
if (argslen() == 0) {
|
if (argslen() == 0) {
|
||||||
@ -16,14 +13,7 @@ void main(void) {
|
|||||||
char *cmd = args()[0];
|
char *cmd = args()[0];
|
||||||
|
|
||||||
if (string_strcmp(cmd, "ls") == 0) {
|
if (string_strcmp(cmd, "ls") == 0) {
|
||||||
uint64_t procslen = processctl(-1, PCTL_PLS_SZ, 0, 0, 0);
|
pctl_ls();
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
uprintf("pctl: unknown command\n");
|
uprintf("pctl: unknown command\n");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user