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 "&"
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityYou 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.
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.
C-z
it will pause. If you execute bg
afterwards as well, it will continue.
Jan 27, 2016 at 14:46
C-z
, [at that point, the process is suspended and doesn't do anything other than wait], and then you allow it to continue running in the background by typing bg
. jobs
will show you the backgrounded jobs. To bring one in the foreground again (for example, to then be able to stop it), you type: fg %n
, n being the job's number (not its pid!). "
Jan 27, 2016 at 17:25