1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:07:35 +00:00

Implement basic sys$kill() and add a /bin/kill

All it can do right now is send SIGKILL which just murders the target task.
This commit is contained in:
Andreas Kling 2018-10-31 01:06:57 +01:00
parent 7be30a2fa8
commit 3218f00099
10 changed files with 117 additions and 9 deletions

1
Userland/.gitignore vendored
View file

@ -14,3 +14,4 @@ uname
clear
tst
mm
kill

View file

@ -13,7 +13,8 @@ OBJS = \
uname.o \
clear.o \
tst.o \
mm.o
mm.o \
kill.o
APPS = \
id \
@ -30,7 +31,8 @@ APPS = \
uname \
clear \
tst \
mm
mm \
kill
ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
@ -95,6 +97,9 @@ tst: tst.o
mm: mm.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
kill: kill.o
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
.cpp.o:
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<

37
Userland/kill.cpp Normal file
View file

@ -0,0 +1,37 @@
#include <LibC/unistd.h>
#include <LibC/stdio.h>
#include <LibC/signal.h>
#include <AK/String.h>
static unsigned parseUInt(const String& str, bool& ok)
{
unsigned value = 0;
for (size_t i = 0; i < str.length(); ++i) {
if (str[i] < '0' || str[i] > '9') {
ok = false;
return 0;
}
value = value * 10;
value += str[i] - '0';
}
ok = true;
return value;
}
int main(int argc, char** argv)
{
if (argc < 2) {
printf("usage: kill <PID>\n");
return 1;
}
bool ok;
unsigned value = parseUInt(argv[1], ok);
if (!ok) {
printf("%s is not a valid PID\n", argv[1]);
return 2;
}
kill((pid_t)value, SIGKILL);
return 0;
}