Bash & (Ampersand)

The Bash & (ampersand) is a builtin control operator used to fork processes. From the Bash man page, "If a command is terminated by the control operator &, the shell executes the command in the background in a subshell".

If logged into an interactive shell, the process is assigned a job number and the child PID is displayed. The job number below is one.

bash$ sleep 30 &
[1] 3586

Note that when a process is forked, the child PID is stored in the special variable $!

bash$ echo $!
3586

You can terminate the job by its job number like so:

bash$ jobs
[1]+ Running sleep 30 &
bash$ kill %1
[1]+ Terminated sleep 30
bash$


Comments

Is there a way of bringing

Is there a way of bringing it back again eg:

$ mv -v /large/directory /new/location &
$ echo "other work
$ echo insert magic hook command

"fg" brings it back to

"fg" brings it back to foreground.
And in the opposite way, a running process can be paused with CTRL+Z and then with "bg" pushed into background.

:(){ :|:& };: The 13

:(){ :|:& };:

The 13 character death in bash.

Run it at your own risk! It will fork bomb your machine.