Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Oct 16 '12 at 12:25

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 1 down vote accepted

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.
share|improve this answer
    
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 '13 at 15:44
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.