Writing a simple, intelligible fork bomb in bash? [closed]
How can I do this?
I just wish to write something like
while(true) {
fork()
}
Is this possible in bash ? I don't want it for religious reasons, just to explain to a friend!
Try this:
#!/bin/bash
$0 &
$0 &
wait
Optionally insert echo $$
before the first $0
You cannot do it by bash alone since there isn't a fork() system call directly accessible in bash (at least as far as I can tell). You could do a 1 liner in Perl though.
perl -e 'while(1) { fork(); sleep(1); }'
This should spawn 2xnumber of processes per second. I.E. first spawn will give you 2, next run gives you 4, next run gives you 8 etc...
精彩评论