Last active
July 9, 2018 11:36
-
-
Save OdearOgy/5ca8e7448561b3bd77903a5a8ea7fe39 to your computer and use it in GitHub Desktop.
forkbomb on C lang
This file contains 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 <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