Skip to content

Instantly share code, notes, and snippets.

@operatorequals
Last active May 4, 2018 09:26
Show Gist options
  • Save operatorequals/99529276181e123840153c6a35fe0c56 to your computer and use it in GitHub Desktop.
Save operatorequals/99529276181e123840153c6a35fe0c56 to your computer and use it in GitHub Desktop.
Forks itself until condition, when met it goes Boom!
#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