Sending an application from the foreground to the background requires cooperation from both the terminal and the shell. The terminal can't do it alone, because the shell has to set the foreground process group. The shell can't do it alone, because the terminal has to process the key press (the shell isn't in the foreground, so it can't receive a key press).
A close approximation is to send the application to the background really fast. After all, an application shares CPU time with others and a pause of a few hundredths of a second shouldn't matter. (It does for real-time applications, so make sure to start those in the background.) I use a shell binding for Ctrl+Z that sends the last-foregrounded job to the background. That way, pressing Ctrl+Z Ctrl+Z sends a job to the background with minimal suspension time.
Here's my zsh binding, which also “background” a half-typed command when the command line is not empty.
fancy-ctrl-z () {
emulate -LR zsh
if [[ $#BUFFER -eq 0 ]]; then
bg
zle redisplay
else
zle push-input
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
In English, for the non-zsh-users in the audience:
If you just want the backgrounding behavior regardless of whether the command line is empty:
function bg_ { builtin bg "$@"; }
zle -N bg_
bindkey '^Z' bg_
I don't know if you can do the same in bash. It should be as easy as bind -x '"\C-z": bg'
, except that bash leaves the tty stop character in place, so it never gets Ctrl+Z as input.
ctrl+z
followed by running the commandbg
. Is there a single keystroke combo to send the app to background? – trusktr Apr 09 '13 at 00:47