Running commands in the background

Every day solutions to every day challenges. + Brilliant stuff

Moderators: b1o, jkerr82508

Forum rules
Please feel free to post your tip it does not have to be advanced. Also ask questions directly related to the tip here. But do not start new threads with questions or ask for help here. That is what the help section is for. forum rules: http://bjoernvold.com/forum/viewtopic.php?f=8&t=568
User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Running commands in the background

Postby viking60 » 17 Oct 2016, 12:30

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
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

Return to “Tips & Tricks”