libos+apps: Add kill
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-07-10 22:17:05 +02:00
parent 86d14e0d0e
commit 82411789e8
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 39 additions and 0 deletions

View File

@ -40,3 +40,4 @@ luna_app(mktemp.cpp mktemp)
luna_app(sysfuzz.cpp sysfuzz)
luna_app(pivot_root.cpp pivot_root)
luna_app(cp.cpp cp)
luna_app(kill.cpp kill)

23
apps/kill.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <os/ArgumentParser.h>
#include <os/Process.h>
#include <stdlib.h>
Result<int> luna_main(int argc, char** argv)
{
StringView signo_sv = "15";
StringView process;
os::ArgumentParser parser;
parser.add_description("Send a signal to another process."_sv);
parser.add_system_program_info("kill"_sv);
parser.add_value_argument(signo_sv, 's', "signal", "the signal number to send");
parser.add_positional_argument(process, "pid", true);
parser.parse(argc, argv);
int signo = atoi(signo_sv.chars());
pid_t pid = atoi(process.chars());
TRY(os::Process::kill(pid, signo));
return 0;
}

View File

@ -72,5 +72,14 @@ namespace os
* child argument if ANY_CHILD was passed).
*/
static Result<pid_t> wait(pid_t child, int* status, int options = 0);
/**
* @brief Send a signal to a process.
*
* @param pid The process ID of the process.
* @param signo The signal number to send. Can be 0 to simply test for a process's existence.
* @return Result<void> Whether the function succeeded.
*/
static Result<void> kill(pid_t pid, int signo);
};
}

View File

@ -68,4 +68,10 @@ namespace os
long rc = syscall(SYS_waitpid, child, status, options);
return Result<pid_t>::from_syscall(rc);
}
Result<void> Process::kill(pid_t pid, int signo)
{
long rc = syscall(SYS_kill, pid, signo);
return Result<void>::from_syscall(rc);
}
}