7

Running an app in the background can be done by adding ampersand (" &") at the end of the app or via screen (by opening a screen session) if the app needs input now and then.

Is there any other benefit apart from the one above (adding input to the application)?

I'm curious if there's any other benefit from a low level details perspective - for example I presume the changes for the app to be shut by the kernel are slightly small if it's run via screen rather than with & at the end.

2 Answers 2

10

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.
1
  • 1
    Added information: A shell can send signal one when it terminates. It does not have to do this and the default seems to be shifting from having thus turned on by default to having this turned off by default. How to check that depends per shell. For bash it is via the shell options command shopt.
    – Hennes
    Nov 27, 2013 at 15:44
6

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .