1

This is quite an interesting thing I noticed, for instance:

  • I use Atom Editor and I call it via my Terminal using:

    $ atom
    

    and press Enter, which triggers the Editor and also make the terminal cursor point to the new line; making it (Terminal) free for further command line utilities.

  • However, when in use RhythmBox using rhythmbox as terminal command, it tends to work on the foreground (I guess) and keeps the terminal occupied till I close Rhythmbox or use CTRL+C.

I tried this with texmaker too and it performs similar thing as Rhythmbox. I know that & will take the process on the background but is there a logical explanation for some applications as mentioned here?

Any hacks or tips so that I can learn how to tweak things like this?

Note

I try using CTRL+Z on the above mentioned applications and the apps then gray out and become unresponsive and I have to force quit on them

Environment

  • Using Ubuntu 16.10

  • Gnome Terminal

  • echo $SHELL give /bin/bash

6
  • 3
    I believe their developers coded this behaviour ( free terminal) into them while others didn't Mar 17, 2017 at 12:59
  • George is right. Not a setting. Not tweak-able. Requires a patch the source code.
    – user535733
    Mar 17, 2017 at 13:01
  • You can press Ctrl+Z to "free the terminal", but keep the program open. OR many other ways
    – M. Becerra
    Mar 17, 2017 at 13:02
  • 1
    It behaves nasty when use CTRL+Z on both rhythmbox and texmaker @M.Becerra Both apps freeze and do not work. I have to forcefully kill them using their PID
    – Shan-Desai
    Mar 17, 2017 at 13:06
  • @user535733 technically, program itself isn't tweakable unless you modify the source code, but there are Linux tools to detach a program from controlling terminal. See my answer Mar 17, 2017 at 14:51

2 Answers 2

3

As has been pointed out in the comments, such behavior is specific to each application. Applications written in C programming language, for example, can employ setsid call to disconnect from controlling terminal, although they require call to fork() syscall first. Python, also has os.setsid() and os.fork() functions; although it is possible to simply use os.fork() to create a child process and kill the parent.

Another very frequent technique that software authors use is launching applications via wrapper script, and calling a new process via nohup. That's exactly what atom does:

$ file $(which atom)
/usr/bin/atom: Bourne-Again shell script, ASCII text executable
$ grep 'nohup' $(which atom)                                                            
    nohup "$ATOM_PATH" --executed-from="$(pwd)" --pid=$$ "$@" > "$ATOM_HOME/nohup.out" 2>&1
      cat "$ATOM_HOME/nohup.out"

You can do so as well. For instance, the way I tend to launch programs and detach them from terminal is via a function, that launches desired program with nohup already appended to the command:

runstuff() {
    nohup "$@" >/dev/null 2>&1 & 
} 

Once you define that in your .bashrc , you can launch firefox like so :

runstuff firefox

Another way, is via setsid command (which is named same as the C system call, but is actually a standalone binary):

setsid firefox
2
  • Definitely a thorough answer with a concise understanding. Thanks
    – Shan-Desai
    Mar 17, 2017 at 14:57
  • 1
    Yeah, yeah nice, nice. But my vote is for the avatar. Mar 17, 2017 at 15:02
1

If you use Ubuntu with X environemnt you can push Ctrl + F2 and then put the command you need (i.e. rythmbox). It won't have separate terminal where you can push ctrl+C.

You can also try to run nohup rythmbox &. It should run your player in backgroud and make it terminal-close-proof.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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