Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Sometimes I want to start a process and forget about it. If I start it from the command line, like this:


I can't close the terminal, or it will kill the process. Can I run a command in such a way that I can close the terminal without killing the process?

share|improve this question
Not a default install on all distros, but screen is your friend: en.wikipedia.org/wiki/GNU_Screen –  Zayne S Halsall Nov 13 '10 at 14:23

7 Answers 7

up vote 93 down vote accepted

One of the following 2 should work:

$ nohup redshift &


$ redshift &
$ disown

See the following for a bit more information on how this works:

share|improve this answer
The second one (redshift & disown) worked for me on Ubuntu 10.10. It seems to work fine putting it all on one line. Is there any reason that I shouldn't do this? –  Matthew Nov 13 '10 at 0:52
I'm not aware of any particular problem with that construction. –  Steven D Nov 13 '10 at 2:09
@Matthew The first should work fine too, it just doesn't background like the second (you possibly want nohup redshift & so it does background). And putting the second on one line is fine, although usually you separate with ; (redshift &; disown) –  Michael Mrozek Nov 13 '10 at 3:14
@Michael: Both ; and & are command separators and have equal precedence. The only difference is the synchronous versus asynchronous execution (respectively). There is no need to use &; in preference to just & (it works, but it is a bit redundant). –  Chris Johnsen Nov 13 '10 at 4:29
good answer, one might add that it would be a good idea to redirect stdout and stderr so that the terminal won't be spammed with debug output –  Kim Nov 13 '10 at 6:22

If your program is already running you can pause it with Ctrl-Z, pull it into the background with bg and then disown it, like this:

$ sleep 1000
[1]+  Stopped                 sleep 1000
$ bg
$ disown
$ exit
share|improve this answer
+1 for ctrl-z; I was unaware of it's function. –  virtualxtc Feb 16 '14 at 22:52
after disown how can I again read the stdout of the running process? –  neckTwi May 22 '14 at 10:59
@neckTwi, serverfault.com/questions/55880/… –  Stefan May 22 '14 at 11:23

Good answer is already posted by @StevenD, yet I think this might clarify it a bit more.

The reason that the process is killed on termination of the terminal is that the process you start is a child process of the terminal. Once you close the terminal, this will kill these child processes as well. You can see the process tree with pstree, for example when running kate & in Konsole:

     │         │      └─pstree
     │         └─2*[{konsole}]

To make the kate process detached from konsole when you terminate konsole, use nohup with the command, like this:

nohup kate &

After closing konsole, pstree will look like this:


and kate will survive. :)

An alternative is using screen/tmux/byobu, which will keep the shell running, independent of the terminal.

share|improve this answer

You can run the process like this in the terminal

setsid process

This will run the program in a new session. As explained http://hanoo.org/index.php?article=run-program-in-new-session-linux

share|improve this answer
What do you see as the advantages of setsid over nohup? –  itsbruce Oct 30 '12 at 10:52
1) It doesn't print an annoying message about nohup.out. 2) It doesn't remain in your shell's job list, so it doesn't clutter the output of jobs. –  Mikel Nov 6 '12 at 22:24

I have a script to:

  • Run arbitrary commands in the background

  • Stop them from being killed with the terminal window

  • Suppress their output

  • Handles exit status

I use it mainly for gedit, evince, inkscape etc that all have lots of annoying terminal output. If the command finishes before TIMEOUT, nohup's exit status is returned instead of zero.



#use nohup to run the command, suppressing its output and allowing the terminal to be closed
#also send nohup's output to /dev/null, supressing nohup.out
#run nohup in the background so this script doesn't block
nohup "${@}" >/dev/null 2>&1 &

#kill this script after a short time, exiting with success status - command is still running
#this is needed as there is no timeout argument for `wait` below
trap "exit 0" SIGINT SIGTERM
sleep $TIMEOUT && kill $MY_PID 2>/dev/null & #ignore "No such process" error if this exits normally

#if the command finishes before the above timeout, everything may be just fine or there could have been an error
#print an error if there was any. most commonly, there was a typo in the command
[ $NOHUP_STATUS != 0 ] && echo "Error ${@}"
#return the exit status of nohup, whatever it was


>>> run true && echo success || echo fail
>>> run false && echo success || echo fail
Error false
>>> run sleep 1000 && echo success || echo fail
>>> run notfound && echo success || echo fail
Error notfound
share|improve this answer

The shell-only way to do all this is to close stdin and background the command:

command <&- & 

Then it won't quit when you quit the shell. Redirecting stdout is a nice optional thing to do.

Disadvantage is that you can't do this after the fact.

share|improve this answer

Though all of the suggestions work well I've found my alternative is to use screen, a program that sets up a virtual terminal on your screen. You might consider starting it with screen -S and then a sessionname.Screen can be installed on virtually all linux and unix derivatives. Hitting control a and c will start a second session. This would allow you to toggle back and forth between the initial session by hitting control a 0 or the newer session by hitting control a 1. You can have up to ten sessions in one terminal. I used to start a session at work, go home, ssh into my work machine, and then invoke screen -d -R sessionname. This will reconnect you to that remote session.

share|improve this answer

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.