/ factorpad.com / tech / linux-essentials / bg-command.html
An ad-free and cookie-free website.
Intermediate
Learn to move processes to the background at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux bg Command Summary with Examples (3:48)
Our sixtieth word, or command to memorize is
bg
from our category
System.
bg
allows you to move a process to
the background.
-options | description |
---|---|
%JOBSPEC |
Run process numbered JOBSPEC in the background |
Recall from the last video on
kill
, we terminated a process that
was working in the background, so here we'll see how to push a process
back.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The bg
command has
no options and the argument is what is called a
JOBSPEC, or an identifier of jobs.
Unlike most commands, help is not available with double-dash
--help
as
bg
is a shell built-in (builtin)
on most Linux distributions. While exhaustive, the
man bash
page has helpful details on
the topic of job control.
The JOBSPEC number refers to the process number, and we'll use this
%
symbol to prioritize the jobs.
So why is bg
an important command?
Well, computers are multitasking, so you'll need to send a process to
the background so you can start another.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. From the last video, we saw
ps
shows our two processes running.
So let's kick off a process two ways. The first way will be a little
slower, and here we'll use
sleep
because you can identify the run
time for the sleep command, and let's sleep for 10 minutes
sleep 10m
. That would be nice.
Next, since it's running in the foreground now, let's pause it with
Ctrl-z
.
Then use bg %1
for JOBSPEC [1].
So it's running in the background.
And last, here's a shortcut for starting and pushing another job right
to the background, and sleep 10s
with an
ampersand &
.
And see if you can follow the logic on JOBSPEC [2] as I run a few
ps
commands.
Very good.
Okay now you know how to use bg
.
And you know the syntax for commands, options and arguments.
One last tip about the bg
command. So while you're reading the
bash
manual, see how the
fg
command brings processes forward.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the bg
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Sometimes this text paired with video is just better, especially as the tutorials get more difficult. Connect at YouTube and see why.
kill
command,
hit Back.chsh
, click Next./ factorpad.com / tech / linux-essentials / bg-command.html
A newly-updated free resource. Connect and refer a friend today.