Time
8 hours 30 minutes
Difficulty
Beginner
CEU/CPE
10

Video Transcription

00:02
Okay, Welcome to 13.5.
00:05
Creating Monterey and killing processes.
00:08
It's kind of funny. Welcome to one of three down five. Sounds like I'm talking about a radio station.
00:13
Anyway,
00:14
processes are
00:17
linked to everything that's happening within your operating system, so we need to be able to
00:22
find the appropriate process based on its I d. Number who owns it? Which group? It belongs to some portion of the name
00:30
and be able to manipulate the process to serve our needs as administrators. Shutting things down, grace believe versus killing them,
00:40
changing the priority of processes. These are all important considerations.
00:45
So you have a big list of commands here.
00:48
We'll learn how to put processes into the background and bring him back to the foreground. Kill them.
00:53
Look at various listing methods
00:56
so that you can see the information that you're you're
01:00
interested in in a more efficient way.
01:06
So when we run a job in the foreground, we have to wait for that job to complete before the prompt returns to the shelves.
01:14
Sometimes that's not a problem, but certain things that may take a long time. We might want to put into the background so that we're not waiting for that to complete.
01:23
If you only had a single terminal connection, you have to do a lot of background work, because otherwise you'd be waiting all the time for things to finish.
01:30
So it's a great way to be more productive because you can
01:34
run a bunch of Koreans, keep putting them in the background, check on their status, and as they complete, you
01:40
do other work.
01:41
So we put a process in the background by adding an ampersand after the process or after the command name on the command prompt.
01:49
Once that happens that a job gets created
01:52
and the jobs will be begin a job number one and we'll increment as required.
01:57
We can just look at those jobs by running the job's command,
02:00
listing them, listing their their process I d numbers and then put them in the foreground and background
02:07
and we'll see how this works.
02:21
So what? I hope so. Sorry about that.
02:25
A convenient way to demonstrate this is to run the sleep command
02:30
because I can just tell it to sleep for 5000 seconds.
02:34
This gives me time to, um,
02:37
I shall do it differently.
02:42
We'll do a sleep command for 100 seconds,
02:45
asleep for 500 seconds.
02:53
3000
02:55
4000.
03:00
You'll notice I forgot to put him presents behind a couple of these.
03:06
That means the 1st 2 would have gone to the background, but the 2nd 2 would not.
03:09
All right,
03:17
sure it did. There is fine.
03:36
All right, so I've got several jobs created. We can see the numbers here. Job 123 and four with the associate ID process ideas.
03:44
I could run the job's command by itself,
03:47
and it shows me that data
03:50
a plus sign here means that's the most recently run job, and the minus sign is the one right before that.
03:55
So it's a nice little extra bit of information that I can use
04:00
now if I run jobs. Dash L.
04:06
This shows me the process I d. Number with the
04:11
the job numbers.
04:12
So it's a long listing form,
04:15
or I can run jobs Dash P
04:16
to just look at the process I d. S.
04:19
Either way, it's pretty useful.
04:21
No,
04:23
what I can do is take one of these jobs that's currently the background. I could bring it to the foreground that might increase its processing priority.
04:31
There's there's reasons for doing that.
04:34
So what I can do is run the f G command for foreground
04:39
and I'm gonna run it for job number four.
04:43
So sleep 2000 was that job. Now, of course, it's in the foreground. So I have to wait until
04:48
this job completes. In order to, uh, get my prompt back,
04:54
I could open another shell, but these jobs are specific to this instance of the shell, so I won't see those jobs in another show. We contest that
05:01
control shifty.
05:03
I can become roots
05:08
and I run the drops Command. I don't see anything because I haven't created any jobs here.
05:15
Create job. I've got it. But now I can't see that job number one is specific to This show doesn't belong to the other show.
05:24
I'm gonna go ahead and exit out of that
05:27
here. If I want to get my prom back, I could do a control. See,
05:30
that particular job is now no longer running.
05:34
Job number one was sleep 100.
05:38
So if I look,
05:40
it says that one's done
05:41
because I basically I exited by by using interrupt control. See,
05:46
Haven't you jobs are still going?
05:49
No, Uh, I could
05:54
also take a job that's currently in the foreground and push it to the background,
05:59
and that's pretty useful
06:01
as well.
06:03
All right, so now that I've got my sleep jobs in the background, all running,
06:08
I might decide that I need to interact with one of these jobs,
06:13
but a backup script. Who knows what these things might be in a production situation here. We're just illustrating it with the sleep command.
06:20
What I can do. Since I know the job numbers,
06:24
I can take more of the jobs and bring it into the foreground by using the F G command.
06:30
So job number one, I'm gonna make that a foreground job.
06:33
Now you'll notice my command show is no longer available to me. I can't. I can't interact with it
06:40
as it is because the jobs in the foreground, as if I never ran it in the background to begin with.
06:46
What I can do is hit control Z
06:47
control Z
06:49
prints to the screen
06:51
and it stops the job.
06:55
Now, if I run my job status,
06:57
I can see that job number one is has now stopped.
07:03
Now, once I Once I've done this, I can, uh,
07:09
decide that I want to put this job into the background again. Maybe I'm done with whatever interaction I needed.
07:14
So I can just run the BG command
07:15
job number one,
07:17
and it's back into the background.
07:20
Very easy to d'oh.
07:23
Now, if I bring a job,
07:26
um,
07:27
into the foreground or bring in the background, there might be different reasons for doing that. Could be that you want to change the priority. You want to do something else,
07:34
and it might be your only option if you have that single connection.
07:39
Another useful feature of the shell is the no hang up from Jin Ality.
07:44
So no help allows me to run a job in the background.
07:47
And then I can log off the system without that job exiting, which would, which is what normally would happen
07:56
in this example. Maybe I'm running a backup script and it's gonna take 56 hours. It's about time to go to lunch. I don't want to wait around, so I'm gonna run this script.
08:05
If I don't specify any output,
08:07
it goes to know hopped out out.
08:09
Although I could specify one here
08:13
to redirect output. Thio Some file of my choosing like a log file
08:18
to the second file descriptor is standard error. If you recall we talked about that a little bit earlier.
08:24
Maybe I want to send my errors to a separate file as well, so I can
08:30
go back later and just review that information that I'm most interested in. And then, of course, running it with the ampersand for the background.
08:37
So let's see how this works.
08:43
I'm going to start a new sleep process 3000 since that's a number that I can find easily later.
08:50
So I typed No help
08:52
sleep 3000
08:54
and just send it to the background
08:56
if I wanted to, I could redirect standard out
09:01
to my current directory
09:05
if I chose.
09:07
There's really no purpose for sleep. It's not gonna really give me much is gonna tell me that it's running,
09:11
and I could redirect the standard error with
09:13
two.
09:16
You could do it like this.
09:18
It's gonna do you always to pick, uh,
09:20
extensions to make sure you know what? What? What a file is not. Text is pretty
09:24
conventional
09:26
anyway, So sleep 3000
09:30
tells me it's now a pending my output to know helped out which I can look at later Have a hit enter. I get my show back.
09:37
So now I can actually exit from my shell.
09:41
You see that? It gave me a process i d number when I ran the job.
09:46
So I can just verify
09:52
that my sleep process is still there.
09:54
I could have done this in different ways to, um
10:00
but we'll look at the process, commands a little bit later.
10:03
You see that this proves my job is still there. Now if I go back into my show,
10:09
actually, this will be a new shell, so I shouldn't be able to see that job.
10:13
I can still see the process,
10:16
but if I run jobs, there's no jobs in this queue because this shell is separate from the one that I started that job.
10:28
The process is still running it. It's just that that job is no longer
10:33
attached to the shell, that it was launched from
10:37
hope that makes sense.
10:39
Anyway, let's let's talk about monitoring process easy. So me just use the P s command a little bit there
10:46
and there are several options for P s that are really useful. We'll talk about those in just a minute here.
10:52
In the meantime,
10:52
you need to be aware of the top utility.
10:56
This is a even though it's on Lee text based. It's very useful because it gives you a real time update
11:03
of various different details about your system.
11:05
What my load averages memory. You said CPU usage.
11:11
I can kill a process from here. I can also re nice a process
11:15
which allows me to change its
11:16
priority within the system.
11:20
So let's have a look.
11:24
So the P S command is pretty useful for viewing processes in lots of different contacts.
11:31
Let's start off by looking at it.
11:33
Help screen.
11:35
Now, this one, we have to specify either help simple list or output.
11:41
Um, somebody used a simple help.
11:45
Just give me some basic settings.
11:50
List. Gives me a little bit more
11:52
detail
11:56
frequently
11:58
when we use the P s command, we're just checking the processes that we have in the current shells. I can just type yes by itself,
12:05
and I can see that I'm running a bash shell and I ran a PS, commanded it, tracked its own process.
12:13
I'm gonna look at UH,
12:16
a larger scope of process easily for the whole system.
12:20
Usually I would run PS Dash E f.
12:26
So he gives me all processes
12:30
and the F
12:33
It gives me the long format.
12:35
So it's a long format listing.
12:37
I can see the user I d
12:39
process i d. The parent process i d
12:45
current system time when it started
12:46
time that it's been running and
12:50
the command itself
12:52
long format shows me a lot more details for what commands are running with options that were run with.
12:58
But, of course, is a big list toe look through and not very efficient.
13:03
So we've got other
13:05
options. We'll explore the PS command a little bit further in the next slide here.
13:11
In the meantime,
13:13
let's look at the top utility.
13:16
Now. Top is very useful because it gives us a real time
13:20
display of
13:22
different things. They're going out with their system. I can, for instance, go to the help screen
13:26
by typing question Mark.
13:31
I could turn on colors,
13:33
toggle the bold option. We'll see what that looks like.
13:37
I can look at my load average, which is my
13:39
one minute, five minutes and 15 minutes
13:43
system load
13:43
I can look at my Cebu information, my memory information.
13:48
I can find a process by its name
13:52
and I can do some other kinds of sorting. I can look at idle time,
13:56
huh?
13:58
I can
14:00
sort by the tasks that are currently running.
14:03
I could search by a user by using the Yuki
14:07
and I can kill and re nice processes.
14:11
There is a you for user killer. Re nice is always good Change the update Interval I think by default it's three seconds you see up here
14:20
So let's have a look at some of these options.
14:24
First we start with a Z
14:28
Z changes The
14:31
the color mapping that's a fight if I hit the control are sorry. Shift Z I get this screen
14:37
headings Aegis by itself turns on color.
14:41
This might be a little difficult for some people to see.
14:43
I usually don't use it, but I like the B option for bold.
14:46
I can set it for highlighting the entire
14:50
line that's currently getting some priority
14:52
or typing it again. Hitting be again. I can see some lines, are emboldened, some or not
14:58
See for CPU. If I
15:01
Let's see for CPU, I can uh,
15:03
changed the sorting. So
15:07
But now I'm looking at the lowest levels and headed again, and I can see the highest levels.
15:13
And it tells me information up here, I can see my load average
15:16
my current CPU, uh,
15:18
parameters showing me how hard my system is working.
15:26
I could look at
15:30
load average showing me,
15:33
uh,
15:33
how much memory I'm using. How much swamp I'm using.
15:37
I can hit em for memory and see a nice little graphical representation of how much remember I'm using versus my swamp.
15:46
Go back to the help screen for some more options.
15:50
The U option for finding a
15:52
process related to a user
15:56
also pretty handy.
15:58
So it tells me what user I'm interested in. I could just say show me admin.
16:03
These were all that process is running for admin
16:06
shift. L Let's me look for a string in my process list
16:12
so I could look for something like I bust. Is that because I happen to see it there
16:17
and it highlights it
16:18
very easily.
16:19
I can type in K to kill a process
16:22
by default. It gives me the one that's at the top of the list when I hit the key,
16:29
and I'm just gonna type, um,
16:32
had escaped to get out of that. I don't want to kill anything,
16:34
but I can also
16:36
re nyssa process with the Archy
16:40
and re nice means I'm changing the nice value, which we'll talk about here in a little bit.
16:45
Oops.
16:49
And one other thing that's useful to look at
16:56
is the task summary.
17:00
So I can be for this,
17:03
and it's trying to show me based on my priority levels and virtual memory,
17:08
Um,
17:10
storage that storage, but utilization for the particular process.
17:17
All right, so so top is kind of useful. I can do a little bit of administrative tasks from here, but mostly it's for viewing things and trying to find information and a little bit more user friendly way than the PS command from the command line.
17:30
Let's quit out of there
17:33
and
17:41
look at some examples for PS.
17:45
I have lots of different options. I can search by the user name search by
17:48
string
17:49
search by the group number of the process I D number
17:56
and these are the fields that process at the process. I
18:00
process listing command shows us your I. D p. i d parent
18:04
process i d
18:07
my system time t t y and other parameters.
18:11
Let's go do a few examples there.
18:17
I was starting to say before P S e f is pretty handy.
18:21
Maybe I want to do a quick and dirty search talking. Just say, Oh, show me everything that's related to bash
18:27
So just taking the output of PS, piping it to the grab command and looking for Bash.
18:34
This might not be very specific, though, so maybe I'm say, Well, show me
18:41
everything
18:44
running by
18:45
admin
18:47
that also has to do with Bash.
18:48
And there's my one bash l
18:52
If I don't use any other filter, I just see all the admin processes
18:57
I can search by the
19:00
Sorry, that habit. I can search by
19:04
the group of admin
19:07
as well.
19:08
So user admin is the owner and admit can also be a group.
19:14
Maybe I want to search by a particular process I d. So I can use the dash p option
19:22
and let's see one here 2 to 19
19:25
So it shows me what that particular
19:27
process I d is
19:32
but in the easier. Since I tend to prefer grab because
19:37
I can just run a full process cf listing and do searches for things that I'm interested up. And
19:45
there's also a couple of related commands a p i d of and P Group.
19:49
So P i d of
19:52
Can I see that I've gotta sleep process running here?
19:59
Actually, I've got more than one. I'll do a P I d of
20:03
Let's try.
20:06
No, no, nothing there. I'll try bashes. I know I have a bash l
20:11
So there's my three process I. D. S related to that string bash that I just searched for.
20:22
If I run a p grip for bash, I can do something very similar. I get a slightly different output,
20:29
but
20:30
in both cases, I'm able to search for process is based on their name.
20:34
So once again, you have multiple ways to
20:37
accomplish the same goal finding processes by their number, finding him by their parent process. I d fighting it by a port number of part of a command. You've got a lot of different opportunities for surgeons
20:49
when we are dealing with processes or managing. Then we have to be able to also send them signals.
20:56
When I was demonstrating the foreground of background commands. Earlier
21:00
you might remember I used control Z to stop a process.
21:06
I could also reference a process by its job number by using the percent sign here.
21:11
So if I knew a process I d number is our day job, i d number. I could kill it with this command
21:17
or I kill it with the process i d. Number
21:21
different signals
21:22
are available. I have signal hang up, which is a kind of a graceful way to
21:26
to end a process, said Kill is much more forceful, so some processes may not die easily,
21:33
so we might have to send the kill command.
21:37
There's a termination request
21:38
also a friendly way to shut down a process
21:41
and said Stop which will stop a process very similar to what control Z does.
21:48
We send signals using this notation here
22:00
so I can send some processes, some signals. Let's start up another sleep command
22:07
sleep 600 I'll sleep seven hundreds. I could tell them apart
22:11
jobs and I can see on the jobs de shell so I can see my process. I d numbers
22:18
Now I could send a kill signal based on the job number.
22:23
So if I specify killed job number one,
22:30
look at jobs. It shows me that that's terminated.
22:36
I actually don't need that more right anymore. Um,
22:38
so now I only have the one job right
22:41
now, I can kill this one using its process I d number
22:45
So job, too,
22:48
In a process i. D. Number of 39588
22:53
jobs. That one is now terminated.
22:56
I'll start up a new one.
23:03
There's my job that's running
23:04
in this case. I want to do kill Dash nine.
23:08
Sometimes again, jobs are
23:14
difficult to just to stop because of the way that they're cooked into the system. And you may need to use the more forceful kill method.
23:19
Killed nine is kind of like the big Hammer.
23:25
So now that job is dead,
23:26
it's been killed,
23:27
and I'll start up another sleep job.
23:34
In this case, I'm going to send a stop command to the to the job,
23:40
So kill dash cigs Stop.
23:45
Oops!
23:47
Helps if you specify the process, i d. Number 39672
23:59
I can see that job has stopped.
24:02
This is just like hitting control Z. So when I could also do
24:04
is put that job into the background,
24:08
referencing it by its job number. So check the BG command with job number one.
24:14
Can we type jobs again? It's running and it's in the background.
24:19
Sick terminate so I can type sig term.
24:23
This terminates the process,
24:26
and I want to also specify the P i. D. Number.
24:34
But I can also do that with the job number. So I knew that it was job number one,
24:40
so I could do that here instead of finding the p i d. And typing that in.
24:47
Okay, so we looked at a lot of different commands in this section.
24:52
He learned how to start. Stop process is putting them into the foreground, putting him into the background,
24:57
setting a system up or sending a process up so that it can run after we've logged out.
25:03
We also looked at the top command
25:06
and some of the ways that it can be used to view processes
25:08
and be able thio to change their settings.
25:15
All right, that gets us to the end of the section. Next we'll talk about modifying the process. Execution priorities.
25:21
Here we'll learn more about how to bud
25:22
use the nice commanding the re nice commands to
25:26
change. The priority of important process is running on our system.
25:30
All right, see, in the next section. Thank you.

Up Next

CompTIA Linux+

Our self-paced online CompTIA Linux+ course prepares students with the knowledge to become a certified Linux+ expert, spanning a curriculum that covers Linux maintenance tasks, user assistance and installation and configuration.

Instructed By

Instructor Profile Image
Dean Pompilio
CEO of SteppingStone Solutions
Instructor