"Funny" bash command

0 views
Skip to first unread message

Adam Visegradi

unread,
Jan 22, 2007, 7:11:31 AM1/22/07
to Linux Users Group
Can anybody explain this bash command to me?
:(){ :|:&};:

It kills my computer in an eyeblink :D Mem usage climbs up to the
maximum and everything get unresponsive -- even the mouse stops moving.

Thx.

Sasquatch Brohan

unread,
Jan 22, 2007, 7:36:19 AM1/22/07
to linuxus...@googlegroups.com
Interesting, I can't read it fluently but it looks like it's just an infinite loop to me.... I dunno whether it should kill your MEM usage straight away though (how much RAM/SWAP do you have?)
 
In my experience I always find it easier to use perl to destroy my linux box....

Sasquatch Brohan

unread,
Jan 22, 2007, 7:40:05 AM1/22/07
to linuxus...@googlegroups.com
FYI: using perl
 
1) Open a console window.
2) perl -e 'while(1 == 1) { fork; }'
3) Wait for the system to crash to its knees. If it doesn't entirely lock up within a matter of seconds, you probably have ulimits enabled.

Mirko

unread,
Jan 22, 2007, 7:55:35 AM1/22/07
to linuxus...@googlegroups.com
Adam Visegradi schrieb:

It's a logic bomb writen in bash. Here's a more readable version:

function bomb ()
{
# use a pipe to invoke a new shell recursive
bomb | bomb & ;
}

Now, when you call this little devil, it will recursivly execute a new
shell running bomb, resulting in thousands of processes running. This
fires up your CPU load to 100% and fills up your memory.

Jeremiah Bess

unread,
Jan 22, 2007, 8:04:30 AM1/22/07
to linuxus...@googlegroups.com

Adam Visegradi

unread,
Jan 22, 2007, 8:09:01 AM1/22/07
to linuxus...@googlegroups.com
AAAARgh! I looked all around the bash manual for the colon and
unfortunately there is a colon command -- it does nothing. I would've
never think of that the colon is the function's name. LOL

Thanks!

PS.: Jeremiah! How do you do that you're the only one whose message is
"empty" when I recieve it via GMail. I always get only the quoted part
:)

On 1/22/07, Mirko <mka...@gmx.net> wrote:
>


--
Adam Visegradi

-----BEGIN GEEK CODE BLOCK-----
GCS/M a-- s+: dpu>d+ C++(++++)
UL++>+++ L+++>++++ W++ E(---) P+ N++
R !tv b+ D+ G++ e>++++ h-- r++ y++
------END GEEK CODE BLOCK------

Jeremiah Bess

unread,
Jan 22, 2007, 9:10:14 AM1/22/07
to linuxus...@googlegroups.com
Aw crap! I thought I had that fixed. I think Mike Meyers has the same problem once in a while. I will do some research. The text I write is sent, but you must click the "Show original", and it is mixed in with some HTML. Not a fix action, I know, but it's there.


--
Jeremiah E. Bess
Network Ninja, Penguin Geek, Father of three

Mirko

unread,
Jan 22, 2007, 9:12:53 AM1/22/07
to Linux Users Group
Just some additions to Sasquatch's reply.

I am not 100% sure if my this explation is completly correct, but for
all I know:

When using a pipe, the command in the left side of the pipe is executed
in a newly spawned sub-shell. By adding & to the rigth hand side, this
command get's also executed in a sub-shell. While your perl solution
just forks _one_ new process in every iteration, this bash beast forks
_two_ processes on each iteration. Consequently, both of the bomb
invocations will also spawn two sub-shells, resulting in 2, 4, 8, 16,
... running processes after the first, second, third fourh, ...
iteration.

This means, that after the 32. iteration, the perl script will have
spawned 32 processes, while the bash script will have spawned
4294967296 shells!

So even on a super-duper furture super-computer with several penta
bytes of RAM, this will fill up the memory in just some seconds.

Adam Visegradi

unread,
Jan 22, 2007, 9:39:27 AM1/22/07
to linuxus...@googlegroups.com
The fork method is exponential too. The fork doesn't wait the child to
be ended. After spawning a new process, the spawner continues the
iteration, so do its children and their children etc.
Assuming the iterations are synchronized, after the Nth there will be
2^N processes running -- the two methods have the same efficiency :)
I prefer a hammer. It has premanent effect.

On 1/22/07, Mirko <mka...@gmx.net> wrote:
>

Mirko

unread,
Jan 22, 2007, 9:45:27 AM1/22/07
to Linux Users Group

Adam Visegradi schrieb:

> The fork method is exponential too. The fork doesn't wait the child to
> be ended. After spawning a new process, the spawner continues the
> iteration, so do its children and their children etc.
> Assuming the iterations are synchronized, after the Nth there will be
> 2^N processes running -- the two methods have the same efficiency :)
> I prefer a hammer. It has premanent effect.

Ahh, thanks for the correction! :)
I don't use perl much, so it looks as a plain linear iteration to me.

Sasquatch Brohan

unread,
Jan 23, 2007, 6:35:32 AM1/23/07
to linuxus...@googlegroups.com
Mirko: ah I see, damned exponential growth again... my least favourite thing since DIV/0, shoulda considered that I supppose.

Suren Karapetyan

unread,
Jan 23, 2007, 3:26:31 PM1/23/07
to linuxus...@googlegroups.com
The nice thing about linux is the kernel-level code will continue
working as needed(you'll still be able to ping the box)
And if you give the right nicelevels your web server will continue running too.
And even if you don't give any limits for the users, the kernel will
finally decide that the process is broken and kill it (well.. in fact
it may decide to kill some other process to free up memory)

For example you may make all the users login with 10 nicelevel.

Sasquatch Brohan

unread,
Jan 24, 2007, 5:13:32 AM1/24/07
to linuxus...@googlegroups.com
renicing is good, but generally only for server stuff. I have a 3GHz processor, and plenty of ram so it's never been much bother to me, unless I'm hash cracking of course...

Suren Karapetyan

unread,
Feb 2, 2007, 2:18:40 PM2/2/07
to linuxus...@googlegroups.com
Retested this thing a bit more....
Even ran it miwth the highest nicelevel (lowest priority) it doesn't
take even a second to Destroy "X". I even managed to ask a friend of
mine to run this on hist half-dedicated server....And you know what?
It stoped all 5 of his sites from running and all the other site on
the same server. It took him an hour to bring the server back to life.
I'm not quite sure I understand why this can harm the system when run
with low priority.

On 1/22/07, Adam Visegradi <a.vis...@gmail.com> wrote:
>

Jeremiah Bess

unread,
Feb 2, 2007, 3:29:45 PM2/2/07
to linuxus...@googlegroups.com

Mirko

unread,
Feb 2, 2007, 11:57:49 PM2/2/07
to Linux Users Group

On Feb 2, 9:29 pm, "Jeremiah Bess" <jeremiah.b...@gmail.com> wrote:


> On 2/2/07, Suren Karapetyan <surenkarapet...@gmail.com> wrote:
>
>
>
> > Retested this thing a bit more....
> > Even ran it miwth the highest nicelevel (lowest priority) it doesn't
> > take even a second to Destroy "X". I even managed to ask a friend of
> > mine to run this on hist half-dedicated server....And you know what?
> > It stoped all 5 of his sites from running and all the other site on
> > the same server. It took him an hour to bring the server back to life.
> > I'm not quite sure I understand why this can harm the system when run
> > with low priority.
>

> > On 1/22/07, Adam Visegradi <a.visegr...@gmail.com> wrote:
>
> > > Can anybody explain this bash command to me?
> > > :(){ :|:&};:
>
> > > It kills my computer in an eyeblink :D Mem usage climbs up to the
> > > maximum and everything get unresponsive -- even the mouse stops moving.
>
> > > Thx.
>

> I think you just lost faith and credibility from your friend. =( Hope you
> guys can patch your friendship soon! lol. Good story though.

Hmm, no admin should run such script without being aware of possible
consequences. ;)
Good story, anyway, yes.

I'm not sure about it. I didn't used nice much. But I suspect, that
even with high-nice, some million processes are just too much to
handle.

Sasquatch Brohan

unread,
Feb 5, 2007, 4:17:27 AM2/5/07
to linuxus...@googlegroups.com
 
explains all you will need to know. It's been a veritable lifesaver to me, and I haven't even read it all the way through yet.
Reply all
Reply to author
Forward
0 new messages