13

If I'm running a program in bash, I can suspend it by pressing Ctrl+Z. If I want to leave the program running, I can then use the bg command. Is there some way to directly put the program in the background, without having to type bg?

Clarification: I want to put the program in the background when it is already running, without suspending it.

4
  • 2
    This is not a duplicate. I don't want to keep a program running when the terminal window is closed, and I can't type a different command. I want to put a process in the background when it is already running. Sep 11, 2012 at 9:46
  • 1
    yes this is not a duplicate, please reopen this.
    – saji89
    Oct 3, 2012 at 11:05
  • Thanks for all those guys who helped in reopening this.. @Kalle, The question is now reopened.
    – saji89
    Oct 4, 2012 at 4:59
  • Thanks a lot! As to actually finding an answer for the question, I guess the only way is to suspend it first and then background it. Oct 4, 2012 at 9:18

3 Answers 3

5

I do not think it is possible to move a running program to background(while the process is still in running state).
However there is an application called GNU-Screen,using which you can run any number of console-based applications--interactive command shells, curses-based applications, text editors, etc.--within a single terminal.
Here is a nice tutorial on GNU-Screen.
Note that it does not do exactly what you asked,but serves the purpose anyway.
Example:
Here is the implementation of what you asked using GNU-Screen.

  1. Run screen
    You will get details about the software.Press return.
  2. Now,you will see your normal terminal.However it is a window of screen.Type any command say vlc. It will start the process within that window.
  3. Now to open a new window type Ctrl+A and then C.You can run a new command here.Note that the process which you started in window 1 is still running.
  4. To detach from screen press Ctrl+A and then D.You now return back to your old termianl.However any process that you started from screen would still be running.
4

To my best of knowledge you could run it and then append an & after it like this: myprogram &

I may be very wrong here however.

[EDIT]: Taking a closer look to this, if you run the above, the application will close when you close the terminal. If you would like the application to run in the background, then, as far as I know, the application needs to be written in such a way that supports daemon behavior.

[EDIT 2]: nohup command & appears to be closer to what you want to achieve. Nohup will allow an application to run, and will both ignore its input and redirect its output to a file called nohup.out in the current directory.

1
  • I don't really care if it's closed when I close the terminal window. All I'm looking for is a keyboard shortcut in bash that works like Ctrl+Z but will keep the process running in the background, instead of suspending it. Sep 11, 2012 at 9:33
0

This may not a real answer. I wonder what the different of Bash between Ubuntu with MSYS.

I running MSYS and when i run Application/Chrome &, it immediately go to background process. I can use the MSYS bash as next prompt start blinking.

And are this questions Move running program to background with similar intents?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .