开发者

Writing a simple, intelligible fork bomb in bash? [closed]

This question is unlikely to help any fu开发者_开发问答ture visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜