How to start GUI linux programs from the command line, but separate from the command line?

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 &)

Use nohup. Like this: nohup amarok &

Hope this helps.


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.