Yes, just run the command in the background and exit the terminal emulator gracefully (use either Ctrl+D or exit
):
command &
For example, firefox &
.
In the BASH shell, the ampersand (&
) means "run this command as a backround process". If you close the terminal from which you launched it using either exit
or Ctrl+D, the program will keep running. If you close the terminal by clicking on it's windows "X" it will also kill the process.
To bring a process back to the foreground (from the same terminal or tty) run fg
. To send a process launched normally to the background, type Ctrl+Z in the terminal you launched it from.
Other ways to run processes in a way that is independent of the terminal emulator that launched them are the following (always using firefox as an example):
nohup
. From the nohup
manpage:
nohup - run a command immune to hangups, with output to a non-tty
If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal,
append output to nohup.out' if possible,
$HOME/nohup.out' otherwise. If standard error is a
terminal, redirect it to standard output. To save output to FILE, use `nohup COMMAND > FILE'.
Example:
nohup firefox
at
, from the at
manpage:
at, batch, atq, atrm - queue, examine or delete jobs for later execution
at executes commands at a specified time.
The usage is slightly more complex, you need to have a text file that contains the command(s) you want to run, one per line. Then you launch at
, telling it to execute at a specific time:
echo "firefox" > command.txt
at 14:56 < command.txt
The example above tells at
to launch the commands listed in the file command.txt
at 14:56 PM.
NOTE: Using either at
or nohup
, the process launched will keep running after exiting X.
1That doesn't work. It backgrounds the process so I can keep using the terminal, but when the terminal closes, the processes it has backgrounded close as well. – Will Kunkel – 2013-01-18T04:11:04.360
@LMJoy, that's strange, it should. Are you launching a graphical application or a CLI one? Anyway, see my updated answer for more choices. – terdon – 2013-01-18T13:44:33.043
it's the same with both GUI and CLI applications. And my issue with nohup is that the process becomes owned by init, not by xorg. So it won't exit when I exit X. – Will Kunkel – 2013-01-18T18:46:36.937
@LMJoy OK, I just checked, I get the same behavior you describe if I close the terminal by clicking the close window button (X at top right usually). However, if I exit the terminal emulator using Ctrl+D or
exit
the process keeps running. I am updating my answer now. – terdon – 2013-01-18T19:00:35.457@LMJoy Did you ever try to run a process and the exit the terminal using
exit
or Ctrl+D? I am curious if it is a gnome and variants specific feature or if it also works in openbox. – terdon – 2013-01-23T18:25:18.583