Super User is a question and answer site for computer enthusiasts and power users. 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

I've searched for this before, but have never been able to find an answer.

In Windows, if I have a console window open, type winmine, and press enter, Minesweeper will appear, completely separate from the cmd program. The Minesweeper instance is not tied to the command prompt in any way that I know of, with the exception of Minesweeper's parent being set to that instance of the command prompt. It's different in Linux, however.

In Linux, if I have a console window open, type emacs and press enter, Emacs will open, but it seems tied to the command line. Specifically, it appears that I can't use the command line anymore until that instance of Emacs is closed. Is there a way to replicate the Windows behavior in Linux?


share|improve this question

migrated from Aug 18 '10 at 6:10

This question came from our site for professional and enthusiast programmers.

dup… – behrooz Apr 25 '11 at 18:07
please give the answer to geekosaur. – Joshua Robison Sep 4 '15 at 13:30
in windows7 it's minesweeper.exe here C:\Program Files\Microsoft Games\Minesweeper so minesweeper.exe won't generally work.. as that directory is not in the path.. And anyhow, you should state windows version – barlop Nov 10 '15 at 0:15

12 Answers 12

Append & to the commandline:

emacs &

This will put emacs in the background and enable you to continue using your terminal.

Note that this will still leave emacs as a sub-process of your terminal, and when you exit the terminal it will also exit emacs. To avoid this, type:

(emacs &)

The parentheses tell the terminal to detach the emacs process from the terminal.

Still, stdout and stderr messages from the program will show up on the terminal. To prevent this, use:

(emacs &> /dev/null &)
share|improve this answer
That's exactly what I wanted. Thanks! – Jason Aug 18 '10 at 3:27
I especially like the (emacs &) tip. – Jason Aug 18 '10 at 5:05
if you have already started the task (emancs), then use CTRL-Z to put to sleep and then use command "bg" to send to background. – Jayan Aug 18 '10 at 5:16
@StackTrace: if you do that, and you close your terminal, it will also kill emacs. – Nathan Fellman Jul 2 '11 at 21:34
OK.. I used to use "nohup" detach this. It cannot be done once the process is started ... – Jayan Jul 4 '11 at 17:44

Use nohup. Like this: nohup amarok &

Hope this helps.

share|improve this answer

I posted an answer to an older thread of similar topic with answers from various sources. Following is a copy of that answer adapted for this thread.

Following works:

$ (gui_app &> /dev/null &)

This is Nathan Fellman's answer plus redirection.

"&> /dev/null" redirects both stdout and stderr to the null device. The last ampersand makes the process run in the background. The parentheses around the command will cause your "gui_app" to run in a subshell.

Doing this will detach the "gui_app" process from the console you execute this command from. So even if you close the window parent terminal emulator is running in, "gui_app" won't close. I ran this then looked at the process tree with "pstree" command and found an application started this way will become child process to "init".

For example,

$ gui_app &> /dev/null &

will run the application in the background, but it will become a child process of the console process and will terminate when you close the terminal. (Though exiting the terminal through bash by using the exit command or Ctrl-D will let bash clean up by handing off the background process to init.)

"nohup" works as NawaMan has suggested, but that redirects output & error to a file by default. As JeffG has answered, "disown" command (if available in shell) can detach process from terminal after you've started a background process:

$ gui_app &
$ disown

(BTW all of this applies to bash. I'm sure other shells have other methods/syntax for doing this.)

Some reference: Disowning Processes (UNIX Power Tools)

If it's a simple call to a GUI application - without complicated options and such - it seems using a launcher like "gmrun" or dmenu (warning: loud audio) is also a good option. Bind it to a key combination. I don't use a launcher yet but have tried those two.

NOTE: CarlF in the comments of the other thread reports GUI apps started via "gui_app &" method does not close when he exits from the parent terminal. I think that we were closing the terminal in different ways. I was closing the window the terminal emulator was running in. I think he may have been exiting the terminal emulator through the shell (exit command or Ctrl-D). I tested this and saw that exiting through bash does not stop GUI started as terminal's background process as CarlF says. It seems bash hands off background processes to init when it is given the chance to clean up. In fact, this must be the mechanism by which the background process started in a subshell gets handed off to init.

share|improve this answer

Try typing xemacs & to open XEmacs in the background.

Please don't refer to this as "emulating Windows behavior". Ouch.

You could also:

  • Open a new terminal
  • Use Alt+F2 or your window manager to launch the program, instead of using the terminal
  • Use GNU Screen
share|improve this answer

util-linux includes a tool called setsid which basically does what detach does:

$ setsid someprogram

This will run someprogram in a new session.

share|improve this answer

I put the following code in a an executable script file named "sbg" for "silent background". It does all the necessary things to completely disconnect the program being started from the shell: redirects stdin, stdout and stderr from/to /dev/null, ignores hangups, runs in background, and detaches.

nohup "$@" &>/dev/null & disown %%

Then you can just do sbg emacs. You can also pass any arguments you want to: sbg emacs --daemon FILE1 FILE2.

share|improve this answer
command &

Put an ampersand after the command.

share|improve this answer

if you are using bash, you can disown the process:

% firefox &
% disown 
share|improve this answer

In bash, detach is a built-in, used as follows:

emacs &
detach %+ # or % + the number in brackets printed after the above

In zsh, you can background and detach in a single operation:

emacs &|
share|improve this answer
thank you for the &| answer. this is the best answer – Joshua Robison Sep 4 '15 at 13:29

As the other answers say, you can use the following:

$ emacs &

If you forget the & though, just press Ctrl-z then use bg:

[1]+  Stopped                 emacs
$ bg
[1]+ emacs &

FYI: Ctrl-z stops the emacs process and bg sends into the background.

share|improve this answer

You can use this single line:

$ emacs & disown
share|improve this answer

just using & as in $ x & leaves the process attached to the terminal i picked up a small program called detach which i have aliased as d it is a bit like nohup but doesn't leave behind a log file i use it to detach mupdf: d mupdf x.pdf

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .