<command> :

Runs the process within the Terminal’s current bash instance, in the background (i.e. the process is listed as a bash background job and stdin, stdout and stderr are still bound to the terminal); not immune to hangups;

<command> & disown:

Runs the process within the Terminal’s current bash instance, in the background, but the process is detached from the bash’s jobs’ list (i.e. the process is not listed as a bash foreground / background job and stdin, stdout and stderr are still bound to the terminal); immune to hangups;

nohup <command> & disown:

  • Runs the process within the Terminal’s current bash instance, in the background, but the process is detached from the bash’s jobs’ list (i.e. the process is not listed as a bash foreground / background job and stdin, stdout and stderr are not still bound to the terminal);immune to hangups;
  • & puts the job in the background, that is, makes it block on attempting to read input, and makes the shell not wait for its completion.
  • disown removes the process from the shell’s job control, but still leaves it connected to the terminal. One of the results is that the shell won’t send it a SIGHUP. Obviously, it can only be applied to background jobs, because you cannot enter it when a foreground job is running.
  • nohup disconnects the process from the terminal, redirects its output to nohup.out and shields it from SIGHUP. One of the effects (the naming one) is that the process won’t receive any sent NOHUP. It is completely independent from job control and could in principle be used also for foreground jobs.
  • Using & causes the program to run in the background, so you’ll get a new shell prompt instead of blocking until the program ends.
  • nohup, disown are largely unrelated; they suppress SIGHUP (hangup) signals so the program isn’t automatically killed when the controlling terminal is closed. nohup does this when the begining.
  • If you don’t nohup a job when it begins, you can use disown to modify a running job; with no arguments it modifies the current job, which is the one that was just backgrounded
  • Using the ampersand (&) will run the command in a child process (child to the current bash session). But, when you exit the session, all child processes will be killed.
  • using nohup + ampersand (&) will do the same thing, except that when the session ends, the parent of the child process will be changed to “1” which is the “init” process, thus preserving the child from being killed.
  • The nohup command is a signal masking utility and catches the hangup signal. Where as ampersand doesn’t catch the hang up signals.
[ad type=”banner”]

Categorized in: