pctl List procs by name
This commit is contained in:
@ -7,6 +7,18 @@
|
||||
#include <uprintf.h>
|
||||
#include <string/string.h>
|
||||
#include <dlmalloc/malloc.h>
|
||||
#include <args/args.h>
|
||||
#include "ls.h"
|
||||
#include "macros.h"
|
||||
|
||||
struct {
|
||||
char *specificproc;
|
||||
} PCTL_LS_CONFIG;
|
||||
|
||||
static Arg ARGS[] = {
|
||||
ARG("-proc", ARG_STRING, &PCTL_LS_CONFIG.specificproc),
|
||||
ARG_END(),
|
||||
};
|
||||
|
||||
const char *human_size(uint64_t bytes, char *buf, size_t bufsize) {
|
||||
static const char *units[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB" };
|
||||
@ -41,6 +53,12 @@ const char *human_size(uint64_t bytes, char *buf, size_t bufsize) {
|
||||
|
||||
|
||||
void pctl_ls(void) {
|
||||
int32_t ret;
|
||||
if ((ret = parse_args(SUBCMD_ARGS(), SUBCMD_ARGSLEN(), ARGS)) < 0) {
|
||||
uprintf("pctl ls: Could not parse args: %d\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
static const char *states[] = {"embryo", "ready", "zombie", "waiting", "died"};
|
||||
|
||||
uint64_t procslen = processctl(-1, PCTL_PLS_SZ, 0, 0, 0);
|
||||
@ -57,6 +75,11 @@ void pctl_ls(void) {
|
||||
|
||||
int32_t r = processctl(-1, PCTL_PLS_STAT, i, (uint64_t)&stat, 0);
|
||||
if (r == E_OK) {
|
||||
if (PCTL_LS_CONFIG.specificproc != NULL
|
||||
&& string_strcmp(stat.name, PCTL_LS_CONFIG.specificproc) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string_memcpy(namebuf, stat.name, 30);
|
||||
namebuf[31] = namebuf[32] = namebuf[33] = '.';
|
||||
|
||||
|
7
user/pctl/macros.h
Normal file
7
user/pctl/macros.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef PCTL_MACROS_H_
|
||||
#define PCTL_MACROS_H_
|
||||
|
||||
#define SUBCMD_ARGS() (args()+1)
|
||||
#define SUBCMD_ARGSLEN() (argslen()-1)
|
||||
|
||||
#endif // PCTL_MACROS_H_
|
Reference in New Issue
Block a user