Sometimes I start a graphical app from within a terminal, for instance because opening the app via a double-click doesn't do anything (for instance, if a Wine app won't start because of a missing DLL file - I can only see this error message if I try to start the app from within a terminal).
But then I want to close the terminal but still keep the graphical app running. Closing the terminal would kill the graphical app too, unless you can somehow detach it completely from the terminal.
For the example I'll run gedit, GNOME's default text editing program, from a gnome-terminal terminal window.
1) Start the graphical app from the terminal
$ geditNow, gedit is running and I don't get a shell prompt in this terminal again unless the app terminates.
2) Temporarily suspend the process with Ctrl-Z
^ZThis suspends the currently running process (gedit), giving us a shell prompt again. Since gedit is suspended, its graphical window will become unresponsive -- you can't click any buttons or type. The process is suspended so it can't respond to events like these.
The terminal will tell you which "job number" it has given to the suspended process. This will usually be 1 unless you have other jobs running:
+ Stopped gedit3) Background the gedit process
$ bg 1We run the
bgcommand and give it the job number, 1. This puts the process into the background (no longer suspended) and lets it run. So gedit can be running and respond to mouse and keyboard events and you still get a shell prompt in the terminal. However, it isn't yet detached from the terminal. If you close the terminal, gedit will still terminate.
4) Disown all jobs from this terminal
$ disown -hThis command will disown all the current jobs from the terminal. The
-hoption sets all the jobs to "nohup" mode, so that if the shell that launched the process receives the HUP signal (such as when you close the shell), the signal isn't forwarded to its jobs. So now we can close the gnome-terminal and gedit will continue to run!
This can also be used to detach command-line applications, too - especially if it will be a long-running process (for example, to back up a large folder over the network) and when you don't really care about its output; you just want it to continue running until it's done, but you need to close your terminal.
There are 2 comments on this page. Add yours.
No.It fails for Me,when "gxine" was invoked.it tells "gxine: killed by watchdog bite" followed by "1]+ Aborted gxine" . Any Idea?
Nice. Thanks. I had always used
&, good to know there's an alternative if I forget it.