Last active
May 4, 2018 09:26
-
-
Save operatorequals/99529276181e123840153c6a35fe0c56 to your computer and use it in GitHub Desktop.
Forks itself until condition, when met it goes Boom!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
#include "stdlib.h" | |
#include "unistd.h" | |
#include "time.h" | |
int check(int value){ | |
return (value % 53) == 0; | |
} | |
int exec(){ | |
// This can be replaced with say.. stager | |
printf("Boom!\n"); | |
return 0; | |
} | |
int main(){ | |
// Seeds the randomness | |
srand ( time(NULL) ); | |
while (1){ | |
// Get a Fork | |
int f = fork(); | |
if (f != 0){ // <--- Parent Exits | |
// printf("Forked to: %d\n",f); | |
return 0; | |
}else{ // <--- Child Continues | |
int r = rand(); // <--- Generates random value | |
// printf("%d\n", r); | |
if ( check(r) ){// <--- Checks it | |
exec(); // <--- Triggers if check succeeds | |
return 0; | |
} | |
// Becomes a Parent if the check fails | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment