Job Control

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hey, Cybrarians. Welcome back to
00:00
the Linux Plus course here at Cybrary.
00:00
I'm your instructor Rob Gills,
00:00
and in today's lesson we're going to
00:00
be covering job control.
00:00
Upon completion of this lesson,
00:00
you are going to be able to explain why job control is
00:00
important and we're going to learn
00:00
the ways that jobs are controlled.
00:00
What can you do to prevent a job from
00:00
tying up your shell or your terminal session?
00:00
Well, you can start a job in the background.
00:00
What if you've kicked off a
00:00
job and you want to cancel it?
00:00
Well then you can send what's
00:00
>> called an interrupt signal.
00:00
>> How about if you have
00:00
a job running but you just want to pause it?
00:00
You don't want to kill it.
00:00
What you can do then is you can send a stop signal.
00:00
Then what if you want a program that
00:00
run even after you log out
00:00
or have it run just in case you get
00:00
disconnected it won't die off?
00:00
Well, you can send a no hang-up signal.
00:00
Let's look at how to do all of these.
00:00
Now, we can send a process to
00:00
the background with the ampersand character.
00:00
For example, if we had this script,
00:00
some_script.sh we want it to run in
00:00
the background and not tie up the terminal window,
00:00
we can say some_script.sh ampersand.
00:00
Then we can see the job running in
00:00
the background by typing the jobs command.
00:00
We just type jobs and in this example,
00:00
we can see the Firefox and
00:00
Nautilus are both running in the background.
00:00
Now, if we wanted to bring one of these background and
00:00
jobs to the foreground, in other words,
00:00
bring it back and run in the terminal window,
00:00
we can use the foreground command, the FG command.
00:00
We can say specify FG and then the number 1.
00:00
That would bring that Firefox
00:00
>> window back to our screen.
00:00
>> Now if we're running a processor or a job and
00:00
maybe it accidentally kicks off,
00:00
or we just want to exit out of
00:00
it because it's taking too long,
00:00
we can use control plus C. Control plus C
00:00
is what's known as SIGINT or the signal interrupt.
00:00
It sends a signal interrupt to
00:00
the running process telling it to quit.
00:00
We're going to cover processing
00:00
those in the next lesson,
00:00
but SIGINT is also known as signal 2.
00:00
Now when a job's taken over
00:00
the terminal but you don't want to kill it,
00:00
you don't want to cancel it,
00:00
you can just pause the job with control Z.
00:00
Control Z is also known as signal stop,
00:00
SIGSTP, and uses the process signal 19.
00:00
It stops any process running in
00:00
the shell but doesn't terminate the process.
00:00
Remember that's SIGINT or control
00:00
C. What this does is it leaves a process in memory.
00:00
From here, once this is paused,
00:00
you can move that job into the
00:00
background with a BG command.
00:00
You just do BG and specify the job number.
00:00
The job's going to continue to
00:00
run but not in your terminal,
00:00
so you can use the terminal again.
00:00
This is similar to running a process in the background
00:00
by just adding an ampersand at the end of it.
00:00
Then if we want to,
00:00
we can bring that process back to the foreground with
00:00
FG and the job number just the same as before.
00:00
Now when you log off a shell or a terminal session,
00:00
what happens is by default,
00:00
a single hang-up is set.
00:00
It's called SIGHUP and has a process signal of one.
00:00
This is going to clean up all the processes that
00:00
are left behind by your terminal session and
00:00
make sure that it is exited
00:00
clean and there's nothing
00:00
still running in the background.
00:00
However, you can tell the system not
00:00
to run a SIGHUP on certain processes.
00:00
This is going to leave the process running
00:00
even after you log off.
00:00
Or a really good example is if you're running
00:00
something and you don't want
00:00
to accidentally get disconnected,
00:00
it needs to maintain and continue running,
00:00
you can do this with a no hang-up command or nohup.
00:00
For example, you can say nohup,
00:00
some_script.sh and then the ampersand.
00:00
In that example, the script will run in
00:00
the background even if you log out.
00:00
But with that, we've reached the end of the lesson.
00:00
In this lesson we covered
00:00
the importance of job control and
00:00
the ways that jobs are controlled
00:00
using job control commands.
00:00
Thanks so much for being here and I look
00:00
forward to seeing you in our next lesson.
Up Next