Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
bin: Added kall as a killall5 alternative.
Browse files Browse the repository at this point in the history
This way we remove the dependency on killall5 and
its basic functionality while at the same time
making our init base more portable across diffeent
init systems.

The name and usage differs so as to not conflict
in any way with killall5 via usage or assumption.
  • Loading branch information
dylanaraps committed Feb 25, 2020
1 parent d81c1db commit 16cdac7
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions bin/kall.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#define _POSIX_SOURCE
#include <dirent.h>
#include <inttypes.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
struct dirent *ent;
DIR *dir;
int pid, sig = SIGTERM;

if (argc > 1)
sig = strtoimax(argv[1], 0, 10);

if (!(dir = opendir("/proc")))
return 1;

kill(-1, SIGSTOP);

while ((ent = readdir(dir))) {
pid = strtoimax(ent->d_name, 0, 10);

if (pid < 2 || pid == getpid() ||
getsid(pid) == getsid(0) || getsid(pid) == 0)
continue;

kill(pid, sig);
}
closedir(dir);

kill(-1, SIGCONT);

return 0;
}

0 comments on commit 16cdac7

Please sign in to comment.