pctl Add kill command

This commit is contained in:
2025-09-29 21:43:28 +02:00
parent 46e52c8d48
commit 0fb63b4695
3 changed files with 37 additions and 0 deletions

28
user/pctl/kill.c Normal file
View File

@ -0,0 +1,28 @@
#include <stddef.h>
#include <stdint.h>
#include <ulib.h>
#include "kill.h"
#include "macros.h"
struct {
int32_t pid;
} PCTL_KILL_CONFIG = {
.pid = -1,
};
static Arg ARGS[] = {
ARG("-pid", ARG_INT, &PCTL_KILL_CONFIG.pid),
ARG_END(),
};
void pctl_kill(void) {
int32_t ret;
if ((ret = parse_args(SUBCMD_ARGS(), SUBCMD_ARGSLEN(), ARGS)) < 0) {
uprintf("pctl kill: Could not parse args: %d\n", ret);
return;
}
if (PCTL_KILL_CONFIG.pid != -1) {
processctl(PCTL_KILL_CONFIG.pid, PCTL_KILL, 0, 0, 0);
}
}

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

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

View File

@ -2,6 +2,7 @@
#include <stdint.h>
#include <ulib.h>
#include "ls.h"
#include "kill.h"
void main(void) {
if (argslen() == 0) {
@ -12,6 +13,8 @@ void main(void) {
if (string_strcmp(cmd, "ls") == 0) {
pctl_ls();
} else if (string_strcmp(cmd, "kill") == 0) {
pctl_kill();
} else {
uprintf("pctl: unknown command %s\n", cmd);
}