Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there any way to run a command from a terminal emulator in Openbox, so that Openbox would own the process, rather than the terminal? So that I could launch a program from a terminal emulator that would stay running when I closed the terminal emulator, but would exit when X11 exits?

share|improve this question
add comment

1 Answer

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

  1. 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
    
  2. 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.

share|improve this answer
1  
That 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. –  William Kunkel Jan 18 '13 at 4:11
    
@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 Jan 18 '13 at 13:44
    
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. –  William Kunkel Jan 18 '13 at 18:46
    
@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 Jan 18 '13 at 19:00
    
@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 Jan 23 '13 at 18:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.