Defend Against This
While certainly not a new concept, I was thinking about the “Fork Bomb.” There are quite a few examples of doing this in different languages. This one takes all the CPUs to 100% and will essentially run the system out of memory:
#!/bin/bash STR="#" while true ; do for i in {1..10}; do STR="${STR}${STR}" done nohup $0 & > /dev/null 2>&1 done
If someone put something like this into an rc.local or similar startup script, what could you do to defend against it? Now, I know how you can remove it and reboot. I’m asking if anyone knows how you would terminate all the processes it spawns and restore a running system back to order.
2 thoughts on “Defend Against This”
https://unix.stackexchange.com/questions/264522/how-can-i-show-a-terminal-shells-process-tree-including-children
which references bunch of better answers with unix shell scripts
https://superuser.com/questions/363169/ps-how-can-i-recursively-get-all-child-process-for-a-given-pid/822450#822450
A couple of decades ago, someone did something similar on a development server then went home. I had to find the sysadmin who was able to kill programs running in other user ids. The system slowed down enough that new processes were not being created very fast. The sysadmin was able to kill them all with a very basic script being run a couple of times.
That looks like an interesting approach to solving that problem. Thanks for stopping by!