How to turn current job in background?
I've ssh-ed to my ubuntu 15 server box.
And I run apt-get xxx. It takes too long to download, and I don't want to stop it.
How can I turn this job in background just like from the start I run it with "&"
You can background a process by typing C-z
, at that point, the process is suspended and doesn't do anything other than wait. Then execute bg
to allow the process to continue in the background.
jobs
will list all the process running/waiting in the background.
testarossa :: ~ % jobs
[1] + suspended sudo apt-get update
To bring it back to the foreground you can just execute fg
. In case you have many processes running in the background you can specify which one to bring to the foreground (or continue in the background) by specifying the process id (e.g., [1]
in the above example). So given the above example, bg 1
and bg
are equivalent. Note that this is not the pid!
Using a terminal multiplexer like screen
and tmux
would have prevented this. Might want to check those out.
Example
testarossa :: ~ % sudo apt-get update 1 ↵
[sudo] password for christophe:
Hit http://ppa.launchpad.net trusty InRelease
Hit http://ppa.launchpad.net trusty InRelease
Hit http://ppa.launchpad.net trusty InRelease
Hit http://ppa.launchpad.net trusty InRelease
Hit http://ppa.launchpad.net trusty/main amd64 Packages
Hit http://ppa.launchpad.net trusty/main i386 Packages
Hit http://ppa.launchpad.net trusty/main Translation-en
Ign http://us.archive.ubuntu.com trusty InRelease
Hit http://ppa.launchpad.net trusty/main amd64 Packages
Hit http://ppa.launchpad.net trusty/main i386 Packages
Get:1 https://get.docker.com docker InRelease
100% [Waiting for headers] [Connecting to security.ubuntu.com (91.189.91.14)] [^Z
[1] + 16963 suspended sudo apt-get update
testarossa :: ~ % bg 20 ↵
[1] + 16963 continued sudo apt-get update
Do mind that output from the process appears on your terminal! You can, however, just do normal stuff on the commandline as you wish.