ghosTzone
main(_){return _} && echo $? /* Keep It Simple Stupid | 本博客所有文章皆为原创 转载请注明 - ghosTM55 */

如何扼制fork炸弹

ghosTM55 posted @ 2008年11月25日 22:10 in bash , 9473 阅读

  众所周知,bash是一款极其强大的shell,提供了强大的交互与编程功能。这样的一款shell中自然不会缺少“函数”这个元素来帮助程序进行模块化的高效开发与管理。于是产生了由于其特殊的特性,bash拥有了fork炸弹。

  所谓fork炸弹是一种恶意程序,它的内部是一个不断在fork进程的无限循环,fork炸弹并不需要有特别的权限即可对系统造成破坏。现在来看一个最简单的fork炸弹:

:() { :|:& };:

  一行看似无法理解的只有13个字符的命令,即可占用掉所有系统的资源。其实,这行命令如果这样写成bash script就不难理解了:

:()
{
    :|: &
}
;
:

  冒号":"其实是函数名,这个bash脚本就是在不断的执行该函数,然后不断fork出新的进程。那么,有没有办法扼制这种情况的发生呢?答案是肯定的,只需设置进程的limit数即可:

txi@ghosTunix.org:~> ulimit -u
200

  使用工具ulimit即可设置各种限制数,具体的请参考该工具的manual page。在这里笔者限制了max user processes数为200,所以,可以安全地执行这个fork炸弹了:

txi@ghosTunix.org:~> :() { :|:& };:
[1] 9593
txi@ghosTunix.org:~> bash: fork: Resource temporarily unavailable
bash: fork: Resource temporarily unavailable
bash: fork: Resource temporarily unavailable
bash: fork: Resource temporarily unavailable
 

txi@ghosTunix.org:~> date
Tue Nov 25 14:11:51 CST 2008

Avatar_small
angry birds 说:
2019年2月22日 17:14

Hi there, You've done an incredible job. I will definitely digg it and in my view suggest to my friends.I am sure they will be benefited from this web site.

Avatar_small
cleaning services ab 说:
2019年9月24日 16:10

A large couple involving questions it is likely you ask on your own before setting up a purchase, “Is this specific worth the bucks? ” along with “Will this specific benefit my well being? ” The idea doesn’t subject if you’re getting a new set of two walking sneakers, an instapot or maybe a housecleaning assistance, the answer should be “Yes. ” Many of us wholeheartedly trust hiring a new maids service which keeps your household clean along with it’s not simply because it’s might know about do, but as a result of benefits it offers a superior.

Avatar_small
full time maids in d 说:
2021年9月08日 16:47

It's also possible to scroll down to check out reviews in particular screen cleaners via Yahoo testimonials and area search data. "Angies List" is usually a great method to find home elevators reputable firms and buyer testimonials. Please ask your current neighbors sometimes. You are going to be surprised the best way many men and women use solutions and word of mouth marketing is always the top reference.

Avatar_small
full time maids in d 说:
2021年9月20日 17:46

When you're trying to figure out how much it'll cost you to contain your your windows program cleaned utilizing a professional this post should end up helpful A good number of window washing laundry companies calculate windows to figure out a price for ones own estimate. Every very important guidelines you might use to be sure that the rate is fair so to help determine selecting cost effective to employ a professional maintaining service or do it yourself. A effective note: If your house is more then simply 1 story getting a pro is necessary.

Avatar_small
monthly cleaning ser 说:
2023年8月22日 17:22

Clearly define which property you are likely to working concerning by setting out its address and various other details should necessary. Using that much detail too, describe typically the painting work you are carrying out and then the quality values to which you're going to be working. Include details on all supports that should be painted, the actual paint that will be used and the sheer number of coats that will be applied. It might be common for the purpose of painters for you to do a full cleaning after job and lose any poisonous chemicals substances in the right way.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter