This is my understanding about the usage of &
, disown
and nohup
:
<command>
: runs the process within the Terminal's currentbash
instance, in the foreground (i.e. the process is listed as abash
foreground job andstdin
,stdout
andstderr
are still bound to the terminal); not immune to hangups;<command> &
: runs the process within the Terminal's currentbash
instance, in the background (i.e. the process is listed as abash
background job andstdin
,stdout
andstderr
are still bound to the terminal); not immune to hangups;<command> & disown
: runs the process within the Terminal's currentbash
instance, in the background, but the process is detached from thebash
's jobs' list (i.e. the process is not listed as abash
foreground / background job andstdin
,stdout
andstderr
are still bound to the terminal); immune to hangups;nohup <command> & disown
: runs the process within the Terminal's currentbash
instance, in the background, but the process is detached from thebash
's jobs' list (i.e. the process is not listed as abash
foreground / background job andstdin
,stdout
andstderr
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
andnohup
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 whiledisown
is not. This means that while many shells (e.g.bash
,zsh
,ksh
) have it, others (for exampletcsh
,csh
,dash
andsh
) won't have it.disown
can be used after a command has been launched whilenohup
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
andman 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:
disown -h
andnohup
work effectively the same?