295 lines
18 KiB
Plaintext
295 lines
18 KiB
Plaintext
|
|
Episode: 1132
|
||
|
|
Title: HPR1132: LiTS 019: Kill the worms!
|
||
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1132/hpr1132.mp3
|
||
|
|
Transcribed: 2025-10-17 19:32:15
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
Welcome to Linux in the Shell episode 19, The Kill Command.
|
||
|
|
My name is Dan Washgrove.
|
||
|
|
I'll be your host today, and I'd like to thank Hacker Public Radio as always for hosting
|
||
|
|
the show website and audio files.
|
||
|
|
So head on over to Linux in the Shell, and also head on over to Hacker Public Radio
|
||
|
|
to hear the latest and greatest from a wonderful group of people.
|
||
|
|
And don't just listen, contribute to.
|
||
|
|
They're always looking for new content.
|
||
|
|
So Hacker Public Radio, it's a great concept.
|
||
|
|
Today we're going to talk about the Kill Command, and again I said head on over to our website
|
||
|
|
Linux in the Shell.org for the full write up on the Kill Command in the corresponding
|
||
|
|
video to this show.
|
||
|
|
So let's jump right in.
|
||
|
|
But before we talk about the Kill Command, I'm going to give you a bonus command, Worms.
|
||
|
|
Worms, I found this a couple weeks ago, actually right before the last one, and Worms
|
||
|
|
is a fun little application that will in a terminal or console session, create ASCII Worms,
|
||
|
|
and they'll move around the screen and just eat things, but by default they just move
|
||
|
|
around the screen.
|
||
|
|
It's part of the BSD games package, and it's a great little utility to mess around
|
||
|
|
with, game to mess around with while you're learning the Kill Command.
|
||
|
|
So let's just talk briefly about Worms.
|
||
|
|
Worms, simple, W-R-O-R-M-S, is how you execute it after you have the BSD games installed.
|
||
|
|
And when you do that, chances are you are going to see a mess all over your screen, flying
|
||
|
|
all over the place, and it's going to look really odd, almost like grainy film stock,
|
||
|
|
which is black for the background of your terminal.
|
||
|
|
That's because on newer systems, and I guess anything in the year 2000, probably, you
|
||
|
|
need to put a delay in there.
|
||
|
|
All right, so a delay, anything from 20 to 200 is what they recommend.
|
||
|
|
I think, and that's what the DASH-D.
|
||
|
|
So I recommend starting Worms with the DASH-D, command like Worms, DASH-D, 100, we'll
|
||
|
|
put all 100 millisecond delay, and you'll actually be able to see the Worms moving across
|
||
|
|
the screen.
|
||
|
|
By default, you'll see five Worms squiggling around.
|
||
|
|
You can change that, no wait, sorry, not five, three Worms.
|
||
|
|
You can change that with the DASH-N switch, and then specify a number from one to whatever.
|
||
|
|
So you know, Worms, DASH, and five will put the five Worms on the screen.
|
||
|
|
Then you'll see them squiggling about.
|
||
|
|
And they're just little ASCII characters of 16 ASCII characters long, that's how long the
|
||
|
|
Worms going to be 16 segments of the same ASCII character.
|
||
|
|
You can change the segment, too, by the DASH-L for length.
|
||
|
|
By default, the 16, so you can change it to 10 to 30, however you want to go, and you'll
|
||
|
|
see your Worms squiggling around with that many segments.
|
||
|
|
If you want your Worms to leave a trail behind them, that's DASH-T, and that leaves a little
|
||
|
|
period wherever they have gone.
|
||
|
|
And if you want to create a field for the Worms to eat, that's DASH-F, and what it does
|
||
|
|
is it just takes the word Worms, and keeps repeating it all over the screen, and then the
|
||
|
|
Worms will eat the letters, and if you do it at DASH-T, they'll leave a trail behind.
|
||
|
|
So you got...
|
||
|
|
It's just a cool little time-waster, Worms to watch, it's almost hypnotic, so check
|
||
|
|
it out.
|
||
|
|
But now let's jump into the Kill command.
|
||
|
|
And the Kill command is an important command, because it's what you use in the terminal
|
||
|
|
to kill any process that you would like to kill, that you obviously have permission
|
||
|
|
to do first.
|
||
|
|
So if you're a general user, you can't kill a root process, but if your own processes
|
||
|
|
you can kill, and it's handy if you have an errand process that, like say your browser
|
||
|
|
has crash, so to speak, or it's hung up, and the rest of the systems we're going to find
|
||
|
|
about your browser is on response, so you can use the Kill command, the Kill your browser
|
||
|
|
from the terminal.
|
||
|
|
Now, you need to know the process idea of the command you want to kill.
|
||
|
|
And now top was a command we talked about in the past, and if you look at top, you can
|
||
|
|
see the process or the PID.
|
||
|
|
Another great command to use is PS, which I'll show you all the processes that are running.
|
||
|
|
There's a couple of switches I just want to touch on, and I cover PS entirely yet, that's
|
||
|
|
for a future episode.
|
||
|
|
But the dash E, if you just run PS in your terminal, you'll only see the processes running
|
||
|
|
in that terminal.
|
||
|
|
Chances are it's going to be the bash shell and the process command that gets flagged
|
||
|
|
there.
|
||
|
|
But if you do dash E, that stands for showing the processes for everyone, and you'll see
|
||
|
|
the full list there.
|
||
|
|
And it shows you the process ID, the terminal that's running on, the cumulative CPU time
|
||
|
|
that's been used on that process, and the command that was to execute the process.
|
||
|
|
So if you did like PS dash E, F gives you the full process, let's give some more extended
|
||
|
|
information on there than just dash E.
|
||
|
|
And so if you're running Chromium and Chromium is on response, if you want to kill it, you
|
||
|
|
could type PS dash E, F, pipe, grip, Chromium, and it'll pull back all the Chromium processes
|
||
|
|
there.
|
||
|
|
You'll probably see more than one process running, okay?
|
||
|
|
So something like Chromium spawns some child processes, especially if you have multiple
|
||
|
|
tabs open.
|
||
|
|
So if you go and you kill any one of those processes besides the parent process, it'll
|
||
|
|
start closing tabs and doing some phone use stuff, but it won't necessarily close the
|
||
|
|
application entirely.
|
||
|
|
You need to find the parent process.
|
||
|
|
So you could do that with the PS dash E space F, I think it is, PS dash E space F, which
|
||
|
|
will kind of give you a tree view, and then you'll be able to see Chromium in there.
|
||
|
|
And if you pass that to grab, it would kind of, it would show you all that, and it still
|
||
|
|
retain the tree hierarchy format.
|
||
|
|
But PS E F put a space in between the E and the F, and you'll get a tree format.
|
||
|
|
All right, let's talk about the kill command.
|
||
|
|
That the harder the kill command just takes one thing, the process ID.
|
||
|
|
So you got the process ID, the PID, you pass it to the kill command, and it's going to
|
||
|
|
terminate that process if it has permission to.
|
||
|
|
Now what that has actually done is it sent a signal to the process.
|
||
|
|
The signal default signal is SIG term, or the termination signal.
|
||
|
|
And what that does is it's the default signal sent by the kill command, and it can be
|
||
|
|
caught or ignored by the process, and it allows the process to release its resources, state,
|
||
|
|
and saving when appropriate.
|
||
|
|
So it's just sends the termination signal to the process.
|
||
|
|
Now more than likely that should be enough to kill the process, but if it doesn't, you
|
||
|
|
may have to use a different signal.
|
||
|
|
And the way that you pass a signal to the kill command is with, there's a couple of ways,
|
||
|
|
the dash S is the switch for the signal.
|
||
|
|
And you can specify the signal either by the name, or by the signal number.
|
||
|
|
And by what we mean by signal name and number, I'm going to cover a few of those right now,
|
||
|
|
but there's a whole bunch of them, but I'm going to cover a couple of the common ones
|
||
|
|
that you're going to use with the kill command.
|
||
|
|
If you go to the website, there's a couple of links in there that'll list all the signal
|
||
|
|
commands, there's a link to the Wikipedia page for Linux signals and explains every one
|
||
|
|
of them in detail, but we're only going to cover just a handful.
|
||
|
|
And the first one we're going to cover is SIG term, which has a signal number of 15.
|
||
|
|
That's the one that's default.
|
||
|
|
Now you can specify SIG term with the dash S space SIG term, and that's all capital letters
|
||
|
|
is the way you should put it in there.
|
||
|
|
In a process ID or kill dash space S, I'm sorry, kill dash S space 15.
|
||
|
|
You could specify instead of typing out SIG term, you could specify number 15 and kill it.
|
||
|
|
Now also there's two other things that you do, there's two other ways that you can kill
|
||
|
|
the command.
|
||
|
|
You could forego the dash S, and you could just do dash in the signal number, like kill
|
||
|
|
space dash 15 is same thing as kill or same thing as kill dash SIG term, or you could do
|
||
|
|
kill space dash and then omit the prefix SIG signal, SIG, and just put the signal term.
|
||
|
|
So it would be kill dash term, capital T, E, R, M, and the process ID.
|
||
|
|
So there's four ways to do it.
|
||
|
|
The dash S with SIG term, the dash S with the signal number 15, the dash with the signal
|
||
|
|
name, which is term, in this case, or the dash signal number, which is 15.
|
||
|
|
So we kind of have four ways to do that, and let's talk about a couple of the signals
|
||
|
|
that you would actually want to pass.
|
||
|
|
We've 15 is SIG term, so let's start all the way back to the beginning with number
|
||
|
|
one.
|
||
|
|
SIG Hangup, SIG Hangup, SIG, HUP, which has a signal number one.
|
||
|
|
It tells the process that the controlling terminal has closed and the process should terminate.
|
||
|
|
And if it's a, if it's a Damon, like a patchy or an IRC Damon, this will usually call
|
||
|
|
the Damon to reread the configuration and restart.
|
||
|
|
So one or SIG HUP is to hang up, and you'd specify kill dash one, kill dash HUP, or kill
|
||
|
|
dash S, SIG HUP, kill dash S one, and the process ID.
|
||
|
|
Now we have SIG Int, which is two, and what is that is a signal is a terminal interrupt.
|
||
|
|
And it sends a terminal interrupt process to the process, which is equivalent to pressing
|
||
|
|
control C. So it's like you were within the terminal and you press control C on a running
|
||
|
|
process.
|
||
|
|
That is SIG INT, or the number two.
|
||
|
|
Then we have SIG QUIT, which is the third signal, which has an ID of three, and that's
|
||
|
|
terminal QUIT.
|
||
|
|
This determination signals sent to the process when the user requests the process to perform
|
||
|
|
a core dump.
|
||
|
|
Now this doesn't necessarily going to give you a core dump, but that's kind of what happens.
|
||
|
|
It's called SIG QUIT, SIG QIT, or the number three.
|
||
|
|
We have SIG KILL, which is number nine.
|
||
|
|
This is KILL.
|
||
|
|
This signal tells the process to terminate immediately.
|
||
|
|
It cannot be caught.
|
||
|
|
It cannot be ignored, and no cleanup is performed when the signal is received.
|
||
|
|
It just kills the process.
|
||
|
|
If you have a process that you can't kill with SIG TURM, or just by default SIG, SIG
|
||
|
|
KILL is probably what you want.
|
||
|
|
KILL DASH NINE is, you'll probably see that a lot, and the process ID.
|
||
|
|
So SIG KILL, number nine.
|
||
|
|
There's SIG TURM, which we talked about, was 15.
|
||
|
|
There is, I'm going to skip number 18 a second, and you'll come back to that, and you'll
|
||
|
|
see why.
|
||
|
|
SIG STOP, number 19.
|
||
|
|
Stop executing.
|
||
|
|
This will stop a process, and it's equivalent to pressing CTRL Z, and it cannot be caught
|
||
|
|
or ignored in the process, but can then be resumed again with the SIG continuous signal.
|
||
|
|
Here, 19 and 20, kind of like the same thing, SIG STP is 20, which is terminal stop signal.
|
||
|
|
It's like SIG SIG STOP, but the process is sent to SIG STP signal to temporarily stop,
|
||
|
|
and then the process can be resumed or continued.
|
||
|
|
And I think the difference between the two is one, can't be caught, SIG STOP, can't be
|
||
|
|
caught, but the other one could be, could be caught, or it could be ignored.
|
||
|
|
So 19 and 20 are stop processes like pressing CTRL Z.
|
||
|
|
Let's step back now to 18, which is SIG CONTINUE, 18, and that's continue if the process
|
||
|
|
is stopped.
|
||
|
|
This will resume a stop process.
|
||
|
|
Let's say we're running a signal 1,000, or a process ID 1,050, and you type KILL-19
|
||
|
|
1,050, that stops it.
|
||
|
|
That's sent to stop signal, so the process is stopped, but it's still, it's still
|
||
|
|
stopped.
|
||
|
|
You could continue it by typing KILL-18, and the process ID 1,050, again, and it will
|
||
|
|
resume the process.
|
||
|
|
So not every signal is a KILL signal, we've got to continue.
|
||
|
|
And we didn't exhaust the signals, like I said, we talked about signal 1, SIG HUB, signal
|
||
|
|
2, which is signal interrupt, signal 3, which is signal quit, signal 9, which is KILL,
|
||
|
|
no 15, which is SIG term, the default termination, signal continue, which is 18, signal stop, which
|
||
|
|
is 19, and terminal stop signal, which is SIG STP ID of 20.
|
||
|
|
So you can see we've jumped around, there's a whole lot more signals that you can listen.
|
||
|
|
If you want to see the full list of signals, you could type KILL-L, and that will list
|
||
|
|
all the signals that are available to the KILL command.
|
||
|
|
You can do KILL-L space 9 if you want to know a specific number signal is right there,
|
||
|
|
and it will list, come back and say it's SIG KILL.
|
||
|
|
If you know the name, if you want to know the number of a specific signal name, you can
|
||
|
|
do KILL-L SIG term, and that's going to return the output of number 15.
|
||
|
|
So it has some informational aspects right there.
|
||
|
|
You can pass, how you pass process IDs is important, okay?
|
||
|
|
So where the process ID is greater than zero, KILL treats that as sending the signal to
|
||
|
|
the process with that PID, and you can list a number of processes by a space in between.
|
||
|
|
So if you need to kill five processes, you can do KILL-L 9, 1,050, 1,088, 2,050, and
|
||
|
|
so on, just a space in between them, and it will send the KILL signal to each one of
|
||
|
|
those processes.
|
||
|
|
Now, if you pass zero as the process ID, this will send the signal to every process and
|
||
|
|
the process group that you executed the KILL command from.
|
||
|
|
So if you're in a terminal and you type KILL-9,0, it's going to kill everything in that
|
||
|
|
process ID group.
|
||
|
|
Chances are it's going to effectively terminate your terminal session in any other process
|
||
|
|
that's running, that's in a similar process ID group, well, maybe all your applications
|
||
|
|
running.
|
||
|
|
It probably won't kill your accession if you're in an accession, but just be aware of that.
|
||
|
|
If you pass a dash zero instead of a KILL-L 1050, that doesn't actually kill the command.
|
||
|
|
It just reports, it sends the signal, but it reports back whether it would be a success
|
||
|
|
for a failure.
|
||
|
|
Now, you will not see the success or failure.
|
||
|
|
If it's a failure, you'll probably see an error message, but you'd have to echo that
|
||
|
|
out with KILL-0, 2050, semi-colon, echo, dollar sign, question mark will return that
|
||
|
|
actual number so you can see whether it would do it.
|
||
|
|
If you use a dash one as the signal, by using that by itself, it will signal every process
|
||
|
|
that you have permission to kill.
|
||
|
|
Well, actually, it will signal every process, but it will only kill what you have permission
|
||
|
|
to kill.
|
||
|
|
You do that, you're going to blow your whole system out of the water.
|
||
|
|
Chances are you are going to end up with a completely non-responsive system that you
|
||
|
|
can't move around onto a different screen, and I've done it just as a test a few times,
|
||
|
|
but it will kill every process that you could kill, all right, everything.
|
||
|
|
Now, that pretty much covers some of the basics.
|
||
|
|
If you have a process and you want to find the pit of that process, what you can do is
|
||
|
|
use the dash P switch and the name of the process, like I said before, if you needed to kill
|
||
|
|
Chromium, you could do PS-EF, pipe it to Grep Chromium, or you could do the dash P Chromium
|
||
|
|
and it will list the Chromium processes right there.
|
||
|
|
Well, there's a caveat.
|
||
|
|
You have to specify the full path to the kill command.
|
||
|
|
If you do just kill space dash P, space Chromium, you're going to get an error message back.
|
||
|
|
You have to do slash bin slash kill.
|
||
|
|
Chances are kill is probably going to be in bin.
|
||
|
|
It could be a user bin in newer systems because they're moving everything under USR bin.
|
||
|
|
So slash bin slash kill, space dash P Chromium, and it will return to process IDs of the
|
||
|
|
processes running Chromium.
|
||
|
|
Now, you may not see all the child processes, you may not see any extended processes, but
|
||
|
|
if you need to kill Chromium and you pass those two process IDs in that return, you will
|
||
|
|
kill Chromium.
|
||
|
|
Okay, so just be aware of that.
|
||
|
|
You need to specify the full path.
|
||
|
|
Okay?
|
||
|
|
Now, you might say, well, let's, why do I need to know the process ID?
|
||
|
|
Can I just kill a command by name?
|
||
|
|
Yes, you can.
|
||
|
|
And you don't have to use kill all, which we will cover in another episode.
|
||
|
|
But you can use the dash A switch to kill and pass the process name.
|
||
|
|
And again, like the P, it has to be the full path to the kill command.
|
||
|
|
Otherwise, it's just going to throw you an error, okay?
|
||
|
|
So it's slash bin slash kill, space dash A, space Chromium will kill all the processes
|
||
|
|
named Chromium on your system.
|
||
|
|
Now of course with dash A, you can use a signal.
|
||
|
|
You could do dash nine.
|
||
|
|
You could just leave it without a signal in that does 15 or sig term.
|
||
|
|
You could pass the signals to them.
|
||
|
|
So that, that is essentially the kill command in a nutshell, very, very, very, very useful,
|
||
|
|
very handy.
|
||
|
|
You should know what the kill command is.
|
||
|
|
I believe I've covered everything in the basics there, just to reiterate quickly, kill
|
||
|
|
by itself, send signal 15.
|
||
|
|
Dash S allows you to send a specific signal by specifying the name, sig term, sig kill,
|
||
|
|
sig hub, or you could specify the numeric equivalent of the signal, 15, 9, 1, 2, 3 and
|
||
|
|
so on.
|
||
|
|
Or you could just use dash and the signal name without the sig prefix, like dash term,
|
||
|
|
dash hub, or you could do the dash number of the signal, like dash nine, dash 15.
|
||
|
|
Kill dash L will list all the current signals available.
|
||
|
|
And if you use either nine or the sig, if you use dash space nine after there or a number,
|
||
|
|
it will return the signal name.
|
||
|
|
If you put the signal name after the dash L, it will return the signal number.
|
||
|
|
So that signal in a, kill in a nutshell, today we talked about kill and worms.
|
||
|
|
I hope you enjoyed this episode for the full skinny head on over to the website, Linux
|
||
|
|
and the shell.org, look it up, watch the video and remember, contribute to hacker public
|
||
|
|
radio.
|
||
|
|
My name is Dan Washco.
|
||
|
|
You have been listening to Linux and the shell episode 19, kill with the bonus command
|
||
|
|
worms.
|
||
|
|
Have a great day.
|
||
|
|
You have been listening to Hacker Public Radio or Hacker Public Radio does our, we are
|
||
|
|
a community podcast network that releases shows every weekday Monday through Friday.
|
||
|
|
Today's show, like all our shows, was contributed by a HPR listener like yourself.
|
||
|
|
If you ever consider recording a podcast, then visit our website to find out how easy
|
||
|
|
it really is.
|
||
|
|
Hacker Public Radio was founded by the digital dog pound and the infonomicum computer
|
||
|
|
club.
|
||
|
|
HPR is funded by the binary revolution at binref.com, all binref projects are crowd sponsored
|
||
|
|
by LUNA pages.
|
||
|
|
From shared hosting to custom private clouds, go to LUNA pages.com for all your hosting
|
||
|
|
needs.
|
||
|
|
Unless otherwise stasis, today's show is released under a creative commons, attribution, share
|