Command Line – Differences Between ‘ & disown’ and ‘nohup & disown’

background-processbashcommand linenohup

This is my understanding about the usage of &, disown and nohup:

  • <command>: runs the process within the Terminal's current bash instance, in the foreground (i.e. the process is listed as a bash foreground job and stdin, stdout and stderr are still bound to the terminal); not immune to hangups;
  • <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;

So, aside from nohup <command> & disown blocking stdin and redirecting stdout and stderr to nohup.out by default, it seems to me like it can be considered totally equivalent to <command> & disown.

Is the above all correct? Any misconception?

Best Answer

Your understanding is basically correct. Both disown and nohup are used to allow you to exit a running shell session without stopping running jobs. Some clarifications:

  • There's no reason to run nohup command & disown, nohup will already disown it for you.

  • nohup is defined by POSIX while disown is not. This means that while many shells (e.g. bash, zsh, ksh) have it, others (for example tcsh, csh, dash and sh) won't have it.

  • disown can be used after a command has been launched while nohup must be used before.

As far as I can tell, the actual effect of the two commands is the same. They each have features that the other lacks (see help disown and man nohup) but their basic function is the same, yes.

For a far more detailed discussion of these tools and the differences between them, have a look at the answers here: