- This lesson is about interactive shell jobs.
When a user runs a command,
this command is started as a foreground job.
That means that you cannot do anything else anymore;
Your console is occupied.
One thing that might be useful is to
move a running process to the background.
You can do that by using Control + Z,
followed by the bg command.
To start a new process in the background
use Command followed by an &
and you'll never see it in the foreground.
It immediately goes to the background.
To get an overview of all the jobs
that are currently running in the background,
you can use the jobs command.
And the fg command is what you can use
to move a current job back-
And the fg command is what you use
to move a current background job back to the foreground.
Let me show you.
So let me start a command that's doing nothing.
dd if=/dev/zero of=/dev/null
It's basically copying nothing to nowhere.
If I press enter, it occupies my console, as you can see.
So there's nothing else that I can do anymore.
So I need Control + Z to temporarily stop it.
If you use the jobs command at this moment,
we can see that the job is temporarily stopped.
And that's because it's waiting for me to type bg
to continue running it in the background.
Now I can immediately run my jobs in the background
by putting an & behind it, as you can see right here.
And let's do that one more time
so that we have a couple of jobs
and here we have the jobs command
and the jobs command is showing all of them.
Now, if I want to move one of these jobs to the foreground,
I can use fg for foreground followed by job number.
And now job number two is running on the foreground.
And if I want to stop it,
then I'm using the generic Linux solution
to stop running things: Control + C
There, you can see that the command outputs
that it has copied 12 gigabyte of nothing to nowhere.
Very interesting.
And the jobs command is showing
the other job's still running.
Now, if you use fg,
then we move it to the foreground
and we can use Control + C to stop it.
And one more time, fg and Control + C.
And now they're all gone,
which can be verified with the jobs command.
Now this job management is convenient for users
because users can manage their own jobs.
Administrators can manage everybody's jobs
and that is what we are going to talk about next.