You are not logged in.
Hey, you know how you're typing away in Bash then you start running a program and then you realize you should have started it in the background (with "&") so then you press "Ctrl-Z" and type "bg"? That's waaay too much work.
Is there a way to send a program to the background with a single command?
Last edited by drcouzelis (2014-10-02 14:57:24)
Offline
Wow, I didn't even know a suspended process could be backgrounded at all. Thanks!
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
Is dtach what you're looking for?
Offline
Wow, I didn't even know a suspended process could be backgrounded at all. Thanks!
You're welcome. For your information "fg" will bring it back into the foreground.
The most annoying part of this "problem" is that "Ctrl-Z" will suspend the program until it's put into the background. It's usually never a problem with the average CLI or GUI application, but I always worry that it will get confused if it's in the middle of downloading something or compiling something... I don't want to suspend, I just want to put it in the background!
Is dtach what you're looking for?
Very interesting. I looked into it a bit just now. It seems a little more work that what I was hoping for, and since I already (occasionally) use tmux, I suppose I'll just stick with that when I need it.
I was hoping there was a super secret Bash command like "Ctrl-Meta-Z-X-C-PrtScn", but I guess that's not going to happen. Here's hoping for Bash v5.
Offline
What you would need is a bash signal handler to both pause and background. Then you'd also need a key binding to raise that signal.
Neither one of these currently exist (AFAIK), but they may be easy to implement. I don't have much experience with 'trap' but you should be able to use it to create a new bash signal handler (perhaps for SIG_USR1) and have that handler background the current process (or pause, then bg as needed). Then create a key binding in the shell or terminal that will send SIG_USR1 to the active process on a selected key press.
EDIT: Or, a slightly easier approach if you never ever need the normal ^Z break/pause behavior, you can just define a new signal handler for that signal and not bother with binding a new key. This way Ctrl-Z would break and background on one key combo.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I found a post that talks about something similar to what you said, Trilby: http://superuser.com/questions/378018/h … -backgroun
The sad news is that I think I'll give up on trying to find what I'm looking for (until it's inevitably implemented in system).
The good news is that, in educating myself on these matters, I just discovered "Ctrl-\". HOLY CRAP. Why have I never heard about this before? Talk about power. For others that don't know, "Ctrl-\" is what I call the "shotgun command", which means "Hey, I already asked you to quit by using Ctrl-C but you didn't listen, so now I'm going to take out my shotgut". Use responsibly.
Offline
Android operates that way even though people don't understand that it does that. They think they have to kill processes like Windows has taught us. But of course those are all js/java and not a command line process.
Last edited by nomorewindows (2014-10-02 17:10:27)
I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.
Offline
Android operates that way even though people don't understand that it does that. They think they have to kill processes like Windows has taught us. But of course those are all js/java and not a command line process.
it's better on your battery to not close them down, as reading from RAM is faster than disk
Offline
Android operates that way...
...What? Android? I'm so confused. O_o Why are you talking about Android?
Android operates in what way?
Offline
nomorewindows wrote:Android operates that way...
...What? Android? I'm so confused. O_o Why are you talking about Android?
Android operates in what way?
The apps run in the background automatically when switching from application to application. But they are java/js application more or less specifically written for android. I don't know of anyway to background applications on the fly in Linux other than planning ahead using screen or xpra.
I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.
Offline
*confused*
I don't see how the android comparison is related at all. That is a totally different meaning of 'backgrounding'. One could easily get the equivalent of android backgrounding by opening two terminal windows, run a command in one, then just raise the other terminal - and in the android sense the first process is "backgrounded". This, however, is not at all what is currently being discussed. The backgrounding being discussed here is the shell job control.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I think about the only thing you can do is renice a task that may still not totally accomplish the objective.
I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.
Offline