Hmm. I've noticed that 'disown -a -h' does not suppress stderr output, which some programs generate a lot of. Is there any way to automatically suppress it when backgrounding a process, so it doesn't clog up my terminal?
I do not think so, at least not with the usual & syntax. You can do it for a given program at a time (see below) but I do not see a general solution. If you are concerned by the program foo, you can put the following in your ~/.bashrc
foo() {
foo 2> /dev/null
}
or more generally, you can define:
launch_in_background () {
"$@" 2> /dev/null &
}
The latter suggestion have problems with command completion (it is possible to correct it via programmable completion but my knowledge ends here).
]]>The only way emacs disappears is if I close the terminal window with 'Alt-F4'. I'm using Openbox as my WM and have Alt-F4 set up as:
<!-- Close window. -->
<keybind key="A-F4">
<action name="Close"/>
</keybind>
When I close the terminal by typing exit or using Ctrl-d, or by using the close window button (the button with the 'X'), emacs stays and is fully functional. But Alt-F4 makes emacs disappear.
Edit: I take back what I said about the close button. Its effect isn't consistent. Sometimes emacs stays and is functional, sometimes it stays and is partially locked up – menus won't close or won't function. Other times, emacs disappears with the terminal. I finally got a warning message with the start of emacs:
(emacs:1817): GLib-WARNING **: In call to g_spawn_sync(), exit status of a
child process was requested but SIGCHLD action was set to SIG_IGN and ECHILD
was received by waitpid(), so exit status can't be returned. This is a bug in
the program calling g_spawn_sync(); either don't request the exit status, or
don't set the SIGCHLD action.
nohup emacs &
and close the terminal. You will see that "nohup" just doesn't work.
It works just fine here.
Something is wrong with your setup if it doesn't. nohup means NO-HUP, as in the SIGHUP is not sent.
But one could also try setsid for even more "detachment".
]]>Re gvim, I was using it as an arbitrary example. I hadn't realized that it ignored HUP.
]]>man nohup
And experience it with emacs:
nohup emacs &
and close the terminal. You will see that "nohup" just doesn't work. The reason is that even when launched with nohup, emacs remain a bash "job" and receive the SIGHUP signal directly from bash. Moreover, my solution work without having to take extra care about program we launch in the background.
]]>firefox &
or
xeyes &
or
emacs &
Then close the terminal and see that firefox is closed. This is a feature of bash that send the SIGHUP signal to all the processes it has launched. Some people (including me) don't like it. Some GUI programs ignore the HUP signal and stay alive (it seems to be the case for gvim).
]]>alias x='setsid /usr/bin/startx -- -nolisten tcp &> ~/.xorg.log & logout'
Edit: I didn't have such a problem when I was running just plain "startx" either.
]]>gvim works fine for me - doesn't have that problem. I would suggest looking at your version of ncurses (lotsa patches, I'm upto patch 20130119) and gvim.
The problem is for graphical program (thus nothing to do with ncurses). Bash send a SIGHUP signal to all process it has launched when we close its terminal (try firefox & or emacs &). My solution automatically disown them and prevent this.
]]>requires the terminal to remain open or it will crash
gvim works fine for me - doesn't have that problem. I would suggest looking at your version of ncurses (lotsa patches, I'm upto patch 20130119) and gvim.
]]>