#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <time.h>
+#include <unistd.h>
static const char* characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
return strtoul(argv[0], NULL, 10);
}
+static int fork_bomb(int argc, char* argv[]) {
+ // Fork this process
+ pid_t pid = fork();
+
+ // Parent
+ if (pid) {
+ printf("Forked child process with PID %d\n", pid);
+
+ // Wait until the child process went away
+ waitpid(pid, NULL, 0);
+
+ return 0;
+
+ // Child
+ } else {
+ // Fork again...
+ return fork_bomb(0, NULL);
+ }
+
+ return 0;
+}
+
static int lines(int argc, char* argv[]) {
size_t length = 0;
else if (strcmp(command, "exit-with-code") == 0)
callback = exit_with_code;
+ // Fork
+ else if (strcmp(command, "fork-bomb") == 0)
+ callback = fork_bomb;
+
// Print random lines
else if (strcmp(command, "lines") == 0)
callback = lines;