Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does this command does in bash: ,_,( ){ ,_,| ,_,&};,_,

Tags:

bash

fork

,_,( ){ ,_,| ,_,&};,_,

I am not sure what it means...

Looks like a bash command but it might be s bash shell directive or something would appreciate if someone can help understand this. It killed my bash when I ran it.

like image 277
Stock Avatar asked Nov 29 '14 00:11

Stock


People also ask

What does this bash command do?

bash is a sh-compatible command language interpreter that executes commands read from the standard input or from a file. bash also incorporates useful features from the Korn and C shells (ksh and csh).

What is $() called in bash?

It turns out, $() is called a command substitution. The command in between $() or backticks (“) is run and the output replaces $() . It can also be described as executing a command inside of another command.

What does $_ mean in bash?

$_ (dollar underscore) is another special bash parameter and used to reference the absolute file name of the shell or bash script which is being executed as specified in the argument list. This bash parameter is also used to hold the name of mail file while checking emails. $@

What does $# in bash mean?

$# is a special variable in bash , that expands to the number of arguments (positional parameters) i.e. $1, $2 ... passed to the script in question or the shell in case of argument directly passed to the shell e.g. in bash -c '...' .... .


1 Answers

It's a fork bomb; it will spawn a (potentially) infinite number of processes, until your system runs out of resources (and usually becomes inoperable).

It defines the function named ,_,, which runs itself (recursion), and piping the output to itself. The last ,_, is needed to start off the thing.

Formatted, and with ,_, replaced by fun, it looks like:

fun() {
   fun | fun &
};
fun

Every invocation of fun will spawn 2 more invocations of fun. The & starts the processes in the background (rate of process increase is exponential).

It's a variant of the better known :() { :|: & };:

There are ways to prevent your system from crashing, though; for example in Linux you can edit /etc/security/limit.conf & set the maximum number of processes for a user. Other systems have other (usually similar) methods.

Running a fork bomb and crashing your system seems to be something of a rite of passage for UNIX users; it teaches you:

  1. The importance of imposing resource limits of processes;
  2. that copying & executing commands you do not understand from untrusted sources (eg. the internet) is not a good idea
like image 161
Martin Tournoij Avatar answered Nov 06 '22 14:11

Martin Tournoij