Anandh G wrote on Wed, Jan 07, 2004 at 05:41:51AM -0800:
,----
| What exectly does this mean. Is there any meaning to this
| command and what happenes when it is executed.
`----
I guess most people must have tried it by now.. so it should be 'okay'
to explain what it does now ;)
echo '. ./_ & . ./_' > ./_; . ./_
there are two parts of the command (seperated by the ';')
1. echo '. ./_ & . ./_' > ./_
2. . ./_
the fundamental part, as you would have realized by now, is the
'. ./_'.
the first command writes the string '. ./_ & . ./_' into the file ./_
However, the string is nothing but another shell command which forks
two such . ./_ processes. As you would have known, command1 &
command2 will make command1 to go into background and command2 to run
in the foreground. so one of the . ./_ will go into background (note
that each of this . ./_ will call another . ./_ & . ./_ pair) and the
other will stay in foreground.
so after, say, 10 levels of forking, you will have 2^10 = 1024
processes which are still busy doing nothing but fork! ps would give
you a list big enough (if your machine is powerful _and_ you did it
within a few seconds of typing the above). My pentium 100 saw instant
heating and it hung within 4 seconds or so (or so I remember :) )
the second command only tries to pull the first control rod that sets
off the reaction. :)
Such an attack is called a 'fork bomb' as it makes the kernel busy
doing fork()s.
So whats the fix?
ulimit is a program using which one can view/set many such limits for
a given shell. Limits like no of processes a shell can fork, allowed
resident memory, etc.,. If you type ulimit -u, you should be able to
see the number of allowed processes. And there is the ulimit -h,
always :).
In debian, these limits can be set in /etc/security/limits.conf (I
dont know whats the equivalent file on other systems. you should sure
be able to grep for 'nproc' in /etc/ atleast in rhl, mdk, etc.,. you
get the idea... ;) ). Its /etc/login.conf for FreeBSD.
cheers,
-Suraj
--
+--------------------------------------------------<suraj@xxxxxxxxxxx>--+
|One who avoids the wrong path of evil, |
|is secure from its ill effects |
|(fear of evil deeds - 10), Thirukkural |
+--<http://www.symonds.net/~suraj/>-------------------------------------+