Running Linux commands in the background: ampersand (&) or screen

Using & will cause the program to run in the background and wait if it needs input. Which makes it only useful for programs that do not need input.

The program will also terminate if you log out, unless you using the nohup command. That will capture the signal 1 (HangUP) and write all output to a file.

If you do need to give input now and then then there are three options:

  1. Manually bring the program to the foreground using fg.
    Or fg jobnumber. (See jobs). Disadvantages: 1) Extra work 2) How do you know it is waiting for input unless you tail -f nohup.out?
  2. Use Screen.
  3. Use tmux.

If you run it in screen you can close your terminal and it is still running.

If you run it via "&" the application receives a HUP command, causing it to quit, if you close your current terminal.

You can combine it with nohup:

nohup /bin/mycommand &

to keep it running.