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

99封情书 提交于 2019-12-11 09:06:20

问题


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!


回答1:


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




回答2:


Try this:

#!/bin/bash
$0 &
$0 &
wait

Optionally insert echo $$ before the first $0



来源:https://stackoverflow.com/questions/5398866/writing-a-simple-intelligible-fork-bomb-in-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!