This is my understanding about the usage of &, disown and nohup:
<command>: runs the process within the Terminal's currentbashinstance, in the foreground (i.e. the process is listed as abashforeground job andstdin,stdoutandstderrare still bound to the terminal); not immune to hangups;<command> &: runs the process within the Terminal's currentbashinstance, in the background (i.e. the process is listed as abashbackground job andstdin,stdoutandstderrare still bound to the terminal); not immune to hangups;<command> & disown: runs the process within the Terminal's currentbashinstance, in the background, but the process is detached from thebash's jobs' list (i.e. the process is not listed as abashforeground / background job andstdin,stdoutandstderrare still bound to the terminal); immune to hangups;nohup <command> & disown: runs the process within the Terminal's currentbashinstance, in the background, but the process is detached from thebash's jobs' list (i.e. the process is not listed as abashforeground / background job andstdin,stdoutandstderrare 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?
22 Answers
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,nohupwill already disown it for you.nohupis defined by POSIX whiledisownis not. This means that while many shells (e.g.bash,zsh,ksh) have it, others (for exampletcsh,csh,dashandsh) won't have it.disowncan be used after a command has been launched whilenohupmust 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:
2Your first to third points seem alright, although stdin, stdout and stderr are still bound to the terminal is not a right notion. stdin is always bound to terminal in the sense that you would always input the file name to a command via terminal or ways using terminal. stdout and stderr are still bound to the terminal is alright.
Your have stdin, stdout and stderr are not still bound to the terminal in the fourth point which is not right as mentioned in my earlier paragraph. Also here you are using /dev/null as the input file to the command, for example if the command is cat, you are using it as cat /dev/null.
The command on your 5th point is not correctly put, you used nohup <command> & disown, while using any one of nohup or disown the other one is not needed. Their purposes are the same (to ignore the SIGHUP) but they function in a bit different way. So the command can be simplified as nohup <command> &.