Skip to content

Commit

Permalink
Userland+LibC: Add "kill -l" to show all known signal names/numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Oct 29, 2020
1 parent 662959b commit 77e9ead
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Libraries/LibC/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,13 @@ int getsignalbyname(const char* name)
errno = EINVAL;
return -1;
}

const char* getsignalname(int signal)
{
if (signal < 0 || signal >= NSIG) {
errno = EINVAL;
return nullptr;
}
return signal_names[signal];
}
}
1 change: 1 addition & 0 deletions Libraries/LibC/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int sigpending(sigset_t*);
int sigsuspend(const sigset_t*);
int raise(int sig);
int getsignalbyname(const char*);
const char* getsignalname(int);

extern const char* sys_siglist[NSIG];

Expand Down
10 changes: 10 additions & 0 deletions Userland/kill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ int main(int argc, char** argv)
return 1;
}

if (argc == 2 && !strcmp(argv[1], "-l")) {
for (size_t i = 0; i < NSIG; ++i) {
if (i && !(i % 5))
outln("");
new_out("{:2}) {:10}", i, getsignalname(i));
}
outln("");
return 0;
}

if (argc != 2 && argc != 3)
print_usage_and_exit();
unsigned signum = SIGTERM;
Expand Down

0 comments on commit 77e9ead

Please sign in to comment.