From 5fc6a119ac53ed508ee7b74756087ac2b4933c33 Mon Sep 17 00:00:00 2001 From: andreastaliad Date: Mon, 25 May 2026 15:44:19 +0300 Subject: [PATCH] Revert "made parent kill childeren" This reverts commit 8f176fdac8d0ef0f994fdd131395cbc1b9f1b6ec. --- fork_bomb/fork_bomb.c | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/fork_bomb/fork_bomb.c b/fork_bomb/fork_bomb.c index 84a8e04..579294c 100644 --- a/fork_bomb/fork_bomb.c +++ b/fork_bomb/fork_bomb.c @@ -7,6 +7,7 @@ #include #include #include +#include #define DEFAULT_NUM_LEN 512 @@ -201,36 +202,6 @@ static long read_self_ticks(void) { return utime + stime; } -static void kill_children_of(pid_t ppid) { - DIR *dir = opendir("/proc"); - if (!dir) { - return; - } - struct dirent *ent; - while ((ent = readdir(dir)) != NULL) { - if (ent->d_type != DT_DIR || !is_numeric_dir(ent->d_name)) { - continue; - } - char path[256]; - snprintf(path, sizeof(path), "/proc/%s/stat", ent->d_name); - FILE *f = fopen(path, "r"); - if (!f) { - continue; - } - long pid = 0; - long parent = 0; - char comm[256]; - char state = 0; - if (fscanf(f, "%ld (%255[^)]) %c %ld", &pid, comm, &state, &parent) == 4) { - if (parent == (long)ppid) { - kill((pid_t)pid, SIGKILL); - } - } - fclose(f); - } - closedir(dir); -} - static void read_cpu_total(long *total, long *idle) { FILE *f = fopen("/proc/stat", "r"); if (!f) { @@ -318,6 +289,12 @@ int main(void) } if (pid == 0) { + if (prctl(PR_SET_PDEATHSIG, SIGKILL) != 0) { + _exit(1); + } + if (getppid() == 1) { + _exit(0); + } pause(); return 0; } @@ -382,8 +359,6 @@ int main(void) } } - kill_children_of(getpid()); - fclose(csv); return 0;