Possible Duplicate:
How can I close a terminal without killing the command running in it?
How to launch a GUI application (e.g. gedit) from terminal and detach it from there in one step?
Possible Duplicate:
How can I close a terminal without killing the command running in it?
How to launch a GUI application (e.g. gedit) from terminal and detach it from there in one step?
The & operator enables the application to run in the background. Use
nohup gedit
or
nohup gedit &
(the latter lets you use the terminal after launching gedit, just press return to send it to the background). Nohup
dispatches the application completely from the terminal and session.
&!
. Combined with the >&
shortcut to redirect STDOUT and STDERR, I've made a convenient alias: alias -g S='>& /dev/null &!'
, to be used like so: gedit S
. This allows me to completely detach it and ignore any output it may give all in one fell swoop.
– Reid
Jul 23 '11 at 20:33
jobs
output a bit confusing.
– Mikel
Nov 06 '12 at 22:22
There are two steps involved. One is generally called "backgrounding" and the other "disowning".
&
after the command. This sends the job to the background and allows your shell to continue running. The command you backgrounded is still running as a child process of the shell. You can see it in the list of shell jobs bu running jobs
. You could run fg
(or fb %N
if you have more than one backgrounded job) to bring it to the foreground and send it things like CtrlC.disown %N
where N is the job number. If you only have one backgrounded job this would be disown %1
. This kicks the background job "out of the nest" so that it is no longer a child of the shell. You can then close the shell and the disowned program would keep running.Note: In ZSH you can shortcut the process of disowning by running command &!
. The &!
backgrounds and disowns in one step.
nohup
? Does it makes both steps? Is it such behavior of nohup
just a 'side-effect' and the command itself is intended for different purpose?
– Anton Moiseev
Jul 23 '11 at 13:06
nohup
and disown
are similar, just that disown
is a bash builtin and nohup
is a separate command.
– glenn jackman
Jul 23 '11 at 17:41
man nohup
says run a command immune to hangups. Basically "HUP" is than hang up signal. When you run a job in a shell (even in the background) the process will receive a "hangup" signal if the shell closes. Most programs would choose to close when receiving this, meaning anything you launched from a shell would die with it. Nohup blocks this. It launches your command as a child of itself, and when it receives the nohup signal intentionally does NOT pass it on to the child so that it will keep running even if it's parent dies. Disown is a shell builtin that removes the relationship.
– Caleb
Jul 23 '11 at 22:08
If you have already launched it, you can hit ctrl-z, enter bg
and then disown
. You will still get output from the application to the terminal though.
gedit
and log out, what's the point? When you logged back in, how would you reconnect to use it again? – Aaron D. Marasco Jul 23 '11 at 13:16X
. – Aaron D. Marasco Jul 23 '11 at 13:32