From 224d867b5068c540417c927604c347ec9f41e9d9 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 30 Sep 2016 23:43:52 +0200 Subject: [PATCH] [TASK] Initial commit --- .gitignore | 1 + zombiebomb.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .gitignore create mode 100644 zombiebomb.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50eb0ec --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +zombiebomb diff --git a/zombiebomb.c b/zombiebomb.c new file mode 100644 index 0000000..49b9051 --- /dev/null +++ b/zombiebomb.c @@ -0,0 +1,68 @@ +#define _GNU_SOURCE +#include +#include +#include +#include + +int childMain(void* args) { + return 0; +} + +void spawnZombies(int number) { + int numForks = 0; + int neverStop; + int forkResult; + + if(number > 0) { + printf("I will try to spawn %d zombies.\n", number); + neverStop = 0; + } else if(number == 0) { + printf("I will spawn as many zombies as possible.\n"); + neverStop = 1; + } else { + printf("I have no idea what to do, doing nothing instead!"); + return; + } + + while(neverStop == 1 || numForks < number) { + //forkResult = clone(childMain, (void*) NULL, 0, (void*) NULL, (pid_t*) NULL, (struct user_desc*) NULL, (pid_t*) NULL); + forkResult = fork(); + + switch(forkResult) { + case -1: + // Forking did not work + break; + case 0: + // Child process at work, let's end this. + exit(0); + break; + default: + // Parent shall continue forking ... + numForks++; + break; + } + + } +} + +int main(int argc, char* argv[]) { + int targetNumber; + if(argc == 2) { + targetNumber = atoi(argv[1]); + } else { + printf("Usage: %s number, pass 0 to spawn as many zombies as possible\n", argv[0]); + return 1; + } + + spawnZombies(targetNumber); + + printf("All zombies have been spawned. Use CTRL+C to exit.\n"); + + // Wait + while(1) { + sleep(60); + } + + // That's it. Let somebody else clean up this mess. + return 0; +}