So now that you know what is going on for monitoring system
activity, let's talk about managing processes
on your system.
First thing to understand is the signal.
The signal allows the operating system
to interrupt the process from software
and ask it to do something.
So signal is really like the operating system telling
your process, hey, listen.
Interrupts are comparable to signals.
The difference is that an interrupt
is generated from hardware.
You can generate an interrupt from keyboard,
and the kernel would generate a signal.
A limited number of signals can be
used to manage what your processes are doing.
And you can find information about them
using MAN 7 signals.
That's a complete documentation, but it's a little bit too much
because not all signals that are documented in the MAN page
are working in all cases.
Now, if you want to send a signal to a command,
you use the kill command.
Sounds kind of funny because kill is like terminate,
but terminate is something that you would only
do in specific cases.
So use a kill command to send a signal to a PID.
Alternatively, you can use K from top
for similar functionality.
There are different kill-like commands,
like pkill and killall.
They just do the same.
I do like killall because kill requires a PID,
and killall works on a name as well.
And sometimes it's convenient to kill multiple processes
that have the same name.
So if you have 20 DD processes that you want to terminate,
just kill all DD, and it will terminate all of them.
Let me show you how to use these signals.
So in order to use my signals, I'm
going to create some activity.
Using DD, if is dev0, of is dev0.
DD is really one of my favorite utilities.
You can use it for cloning.
And here, I'm cloning the dev0 device to the dev0 device.
It's copying nothing to nowhere, basically,
but it is going to make my system very busy with it.
And I'm starting it no less than six times.
You can see that for every single time I'm starting it,
we have different PIDs.
So the 29606 and so on, these are the PIDs.
Top is giving a convenient overview of what
these DD processes are doing.
Now, what is interesting is that we now
have six processes that all want attention.
So we can see that the load average is rapidly
climbing to a number above 2.
Why is the 2 so important?
Well, as I was mentioning, this is a two-core system.
So anything more than 2 is indicating
that this system is overloaded.
You can also see that in the CPUs line, most important,
we have 0% in the idle loop.
So this system is continuously busy.
And we can change that from the top interface
by using K to kill a signal.
So by default, it will try to kill the most active process.
If you don't like that, type the PID of the process
that you want to kill.
And then it will ask, how do you want to kill it?
Two options.
Signal 15 is a nice and polite way to tell it to go.
Signal 9 is a not so nice and polite way to tell it to go.
In this case, it doesn't really make a difference
what you are using.
But let me show you signal 9 and why it is not so very nice.
As you can see in a bold typeface,
top is in this list as well.
The PID is 29613.
And I'm going to kill 29613 with signal 9.
And you see what is happening.
In the middle of my output, my prompt is regenerated.
And the output is not cleaned up at all.
And that is what is bad about this sick kill signal.
Processes don't have the opportunity
to clear up what they are doing.
And that might lead to damage on your system.
And let me use PSAOX, because I also
want to show you from the command line.
PSAOX, grab DD, is showing all of these DD processes.
And I want to show you how we can use kill on 29606 and 29608,
for instance, to kill multiple processes by PID.
You probably are going to like kill all in this case,
because kill only works with PIDs.
Kill all works with names.
So I'm using kill all DD.
And there you can see that it is killing
all of these DD processes.
And as you can see, all are terminated right now.
So the system will get back to a relaxed state pretty soon.