Suggested Reading Resources(Free of Cost!)
We all know that the simplest function in Linux is fork(). The fork is used create a child process which is an exact copy of the calling process (parent process). You might be thinking how can such a simple function reboot a linux machine. Well I must tell you that the program I am going to discuss today uses only this fork function and can force a Linux Server which can serve as many as 100 computers to get rebooted. I have tried this on my College’s Linux Server which Serves more than 200 computers at a time and I was lucky to get out of this situation.
Warning: I am not responsible to whatever happens to your computer after exceuting the following program on your computer.
I have written a simple C Program whose source is as follows:
#include<fcntl.h>
int main() { int i; for(i=1;i<=300;i++) { printf(”%d”,fork()); } return(1); }
- Open the Linux Shell. - Write the above program in your vi Editor and save it as reboot.c - Now compile the program using following command:
gcc -o reboot reboot.c - Now to execute the program type the following
./reboot and press Enter.
Explanation: In the above program, I have used a loop of 300 iterations. In the first iteration it will execute the fork command which will create a child process which is the exact copy of the parent process i.e. the child process will have the same code as the parent process and it will execute simultaneously with the parent process. So in the next iteration both parent process and the child process will execute fork command which will in turn create child processes with the exact copy of their parent processes and this process of creation of child processes will be in the power of 2 i.e. after the first iteration the total number of processes will be 1 parent and 1 child = 2 process. After 2nd iteration the number of process will be 1 parent and 3 child = 4 process. And this will continue to double and at the end the total number of processes will be 2300 which is quite a big number. If you try to calculate this value in your calc it will take atleast 1 hour. So when you will execute the above program your linux machine will get overloaded and will be forced to reboot.
I executed this program in college’s Computer Lab and all the computer got hanged and after 1 or 2 mins a Global message was displayed that “Linux server is going to Reboot”. Since nobody knew what had happened I could get away from that situation. Hope that my lab faculty don’t read this Article.
|