Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the difference between

$ nohup foo


$ foo &


$ foo &
$ disown
share|improve this question
Wait, you can disown without specifying a PID ? Great! – ripper234 Nov 12 '10 at 11:20
There is also foo &! which should be equal to disowning it right from the start. – user4514 Nov 18 '12 at 19:02
Bash does not support &!. – Jonas Kongslund Jun 3 '13 at 4:35
@ripper234 help disown says "Remove jobs from current shell. Removes each JOBSPEC argument from the table of active jobs. Without any JOBSPECs, the shell uses its notion of the current job." – Mnemonic Flow Dec 27 '14 at 9:46
You can also use set -m to enable job control. See unix.stackexchange.com/questions/196603/… – A.Danischewski Jan 18 at 6:31
up vote 192 down vote accepted

Let's first look at what happens if a program is started from an interactive shell (connected to a terminal) without & (and without any redirection). So let's assume you've just typed foo:

  • The process running foo is created.
  • The process inherits stdin, stdout, and stderr from the shell. Therefore it is also connected to the same terminal.
  • If the shell receives a SIGHUP, it also sends a SIGHUP to the process (which normally causes the process to terminate).
  • Otherwise the shell waits (is blocked) until the process terminates.

Now, let's look what happens if you put the process in the background, that is, type foo &:

  • The process running foo is created.
  • The process inherits stdout/stderr from the shell (so it still writes to the terminal).
  • The process in principle also inherits stdin, but as soon as it tries to read from stdin, it is halted.
  • It is put into the list of background jobs the shell manages, which means especially:
    • It is listed with jobs and can be accessed using %n (where n is the job number).
    • It can be turned into a foreground job using fg, in which case it continues as if you would not have used & on it (and if it was stopped due to trying to read from standard input, it now can proceed to read from the terminal).
    • If the shell received a SIGHUP, it also sends a SIGHUP to the process. Depending on the shell and possibly on options set for the shell, when terminating the shell it will also send a SIGHUP to the process.

Now disown removes the job from the shell's job list, so all the subpoints above don't apply any more (including the process being sent a SIGHUP by the shell). However note that it still is connected to the terminal, so if the terminal is destroyed (which can happen if it was a pty, like those created by xterm or ssh, and the controlling program is terminated, by closing the xterm or terminating the SSH connection), the program will fail as soon as it tries to read from standard input or write to standard output.

What nohup does, on the other hand, is to effectively separate the process from the terminal:

  • It closes standard input (the program will not be able to read any input, even if it is run in the foreground. it is not halted, but will receive an error code or EOF).
  • It redirects standard output and standard error to the file nohup.out, so the program won't fail for writing to standard output if the terminal fails, so whatever the process writes is not lost.
  • It prevents the process from receiving a SIGHUP (thus the name).

Note that nohup does not remove the process from the shell's job control and also doesn't put it in the background (but since a foreground nohup job is more or less useless, you'd generally put it into the background using &). For example, unlike with disown, the shell will still tell you when the nohup job has completed (unless the shell is terminated before, of course).

So to summarize:

  • & 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 it 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 (although that's not very useful).
share|improve this answer
+1 Thanks. What happens when using disown, nohup and & together then? – Tim Apr 2 '15 at 14:27
If you use all three together, the process is running in the background, is removed from the shell's job control and is effectively disconnected from the terminal. – celtschk Apr 2 '15 at 15:46
I couldn't reproduce it until looking at this answer (which actually is a comment) to a related question. Given that Alt+F4 is a window manager key combination completely unrelated to the shell, I guess it is something the window manager does. However it doesn't seem to go via X events, as xev doesn't show something that I can recognize as causing a close. – celtschk Apr 2 '15 at 18:06
what's the difference between disown %1 and disown -h %1? The second one will keep as a regular job(but ignores the HUP signal) until the terminal exit? – schemacs Nov 3 '15 at 0:07

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 and 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 job first begins. 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

share|improve this answer
Minor difference between nohup and disown: the disown command will remove it from your jobs list; nohup will not. – Shawn J. Goff Nov 9 '10 at 16:41
nohup and disown both can be said to suppress SIGHUP, but in different ways. nohup makes the program ignore the signal initially (the program may change this). nohup also tries to arrange for the program not to have a controlling terminal, so that it won't be sent SIGHUP by the kernel when the terminal is closed. disown is purely internal to the shell; it causes the shell not to send SIGHUP when it terminates. – Gilles Nov 9 '10 at 18:26
@Gilles, your comment is worth an answer of itself. – lesmana Nov 10 '10 at 18:30
Just a clarification on @ShawnJ.Goff 's comment pertaining to disown removing the job from the jobs list. If you don't specify an option, it does remove it from the jobs list. However, if you specify the -h option, each jobspec is not removed from the table. Instead, it makes it so that SIGHUP is not sent to the job if the shell receives a SIGHUP. – nojak Nov 13 '13 at 6:54
Just to clarify, using & does not give you a terminal, it detaches stdin from the process and causes it to run in the background, but both stdout and stderr is still attached to the current tty. This means that you may get text from different programs mixed up together, which can be quite annoying if you do gimp & and get lots of GTK+ errors while trying to use that tty for something else. – Frank Jun 5 '14 at 21:18

Your Answer


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.