You are not logged in.

#1 2014-10-01 18:53:10

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

[GAVE UP] Single command to send to background?

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

#2 2014-10-01 19:29:25

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [GAVE UP] Single command to send to background?

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

#3 2014-10-02 08:43:58

theGunslinger
Member
Registered: 2011-05-20
Posts: 300

Re: [GAVE UP] Single command to send to background?

Is dtach what you're looking for?

Offline

#4 2014-10-02 13:24:17

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [GAVE UP] Single command to send to background?

alphaniner wrote:

Wow, I didn't even know a suspended process could be backgrounded at all. Thanks!

You're welcome. smile 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! tongue

theGunslinger wrote:

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. smile

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. hmm

Offline

#5 2014-10-02 13:37:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [GAVE UP] Single command to send to background?

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

#6 2014-10-02 14:57:06

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [GAVE UP] Single command to send to background?

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). wink

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. big_smile

Offline

#7 2014-10-02 17:07:01

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,362

Re: [GAVE UP] Single command to send to background?

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

#8 2014-10-02 17:11:21

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: [GAVE UP] Single command to send to background?

nomorewindows wrote:

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

#9 2014-10-02 17:50:42

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [GAVE UP] Single command to send to background?

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?

Offline

#10 2014-10-02 17:58:16

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,362

Re: [GAVE UP] Single command to send to background?

drcouzelis wrote:
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

#11 2014-10-02 18:00:10

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: [GAVE UP] Single command to send to background?

*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

#12 2014-10-02 18:08:08

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,362

Re: [GAVE UP] Single command to send to background?

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

Board footer

Powered by FluxBB