Page 1 of 1

Running commands in the background

Posted: 17 Oct 2016, 12:30
by viking60
I often start a command and watch the activity in the terminal. Sometimes I really don't need to see that activity and it is just a pointless wait.

Other times when you start a program from the terminal it needs the terminal will be occupied all the time while you are using it.

Not so anymore.

I came over a tip today that will detach your command from the terminal and run in the background. I update all my computers from one box with Salt
and it is convenient to simply run that in the background.

Yes I could do it with a Cron-job but sometimes I want to watch what happens so it is not an option to automate it completely.
So I start it with

Code: Select all

sudo salt '*' pkg.upgrade

..and hit CTRL+Z to abort it immediately. :!:

Then I simply type

Code: Select all

bg
..and this command will start to run in the background which will give me this message:

Code: Select all

[1]  + continued  sudo salt '*' pkg.upgrade

:tux5:
After it has finished it will display the status of the update in the terminal - it's quite handy!

Here is a test that you can run:

1 Start Firefox in a terminal
2 Break it off with CTRL+Z
3 Type bg in the terminal

Now you can surf on the internet and type commands in the terminal as you like.

If you want to see what jobs you have running in the background simply type:

Code: Select all

jobs


here is how it looks in the terminal:
:A
Image
http://showterm.io/624f6d03bf11f9c3a87bd