If I run the classic bash forkbomb:
:(){ :&:&};:
my system freezes in a few seconds.
I tried writing forkbomb in C, here is the code:
#include <unistd.h> int main( ) { while(1) { fork(); } return 0; }
When I start it, the system becomes less responsive, but I can kill this process (even after a few minutes) just by pressing ^C
The above code is different from the original bash forkbomb I posted: it is something more similar:
:( ) { while true do : done }
(I did not test it, I do not know if it hung the system).
Therefore, I also tried to implement the original version; here is the code:
#include <unistd.h> inline void colon( const char *path ) { pid_t pid = fork( ); if( pid == 0 ) { execl( path, path, 0 ); } } int main( int argc, char **argv ) { colon( argv[0] ); colon( argv[0] ); return 0; }
But still nothing: I can run it and then easily kill it. This is not my system hanging.
Why?
What is so special about bash forkbombs? Is it because bash uses a lot more memory / processor? Since bash processes handle far more system calls (for example, to access the file system) than mine?
c ++ c linux bash fork
peoro Nov 22 2018-10-10T00: 10-11
source share