The kill command is used to kill processes, and this allows us to terminate programs that need killing.
And this is some kind of pausing or termination.
So here's an example here.
And these are actually these are all the kill commands you can use with here, kill here.
This is this is the list of commands we will use and we will discuss here.
And let's actually clear and kill or actually, firstly, let's start X logo that our example with and
background.
So here this is our process ID and here it's actually always on top.
So we first launch the x log in the background.
Now let's kill this kill 71 608.
Right here and be terminated.
So the shell prints the job spec and the process ID of the background process.
Right here.
Next, we use the kill command and specify the process ID of the process we want to terminate.
We could have also specified the process of job splits.
For example, present one here.
Always on top.
Always on.
Bob.
And here we will write kill, kill Person one And as you can see, it will also terminate the X logo.
So we will write at present one instead of the previous.
So while this is all very straightforward, there is a more to it than that.
So the kill command doesn't exactly kill processes, rather it sends them the signals.
Signals are one of the several ways that the operating system communicates with programs.
We already seen signals in action with the use of the control C and control Z.
And when the terminal receives one of these keystrokes, it sends a signal to a program in the foreground.
In the case of the control C right here.
A signal called interrupt is sent and you will see you will learn all of this here.
So with the control signal called interrupt is sent.
So with control.
With control Z here, control Z here.
A signal called TFTP terminal stop is sent.
So programs internal listen for the signals and may act upon them as they are received.
The fact that program can listen and act upon signals allows a program to do things such as save work
in progress when it sends a termination signal.
So let's actually send the signals to process with the kill command here.
So clear here.
So the kill command is used to send signals in the signals to programs, Right?
So it's most common syntax is going to in kill here we give it first the right kill.
This is our command.
And we will also specify some parameters here.
So in this case, we're going to enter the signal type.
We want to send signal single no here.
So it's actually right here.
Signal signal type.
We want to send signal.
And we will also enter the process ID.
Right.
So if no signal is specified on the command line, the if nothing if no signal specified in the command
line, the termination terminate.
Her.
The terminate signal is sent by default.
Right.
The kill command is most often used.
Send the signals here.
I write all of these signals right down here.
Most used and popular kill commands, which is whoop.
This is a high gap.
Now.
This hoop here.
This is a vestige of a good old days when terminals were attached to remote computers with phone lines
and modems.
So the signal is used to indicate the two programs that the controlling terminal has hung up.
So the effect of this signal can be demonstrated by closing a terminal session and the foreground program
running on the terminal will send the signal and it will terminate.
The signal is also used by many Daemon programs to cause a reinitialization.
And this means what?
The daemon is set to send the signal.
It will restart and reread its configuration file and the patch web server is an example of a daemon
that uses the hop signal hangup signal in this way.
And we also have the interrupt.
So this performs the same function as the control C send from the terminal.
It will usually terminate a program in an interrupt.
And we also have quit actually, we will discuss quit Segway and whinge in the end of today's lecture.
But firstly, we will discuss kill here right now.
So the kill this this signal is special, right?
So whereas programs may choose to handle signals sent to them in a different ways, including ignoring
them altogether, so the kill signal is never actually ignoring them altogether.
Uh, the kill is never actually sent to the target program, right?
The rather than kernel here, kernel immediately terminates the program or process.
So when a process is terminated in this manner, it is given no opportunity to clean up after itself
or save its work.
For this reason, the kill signal should be used only as a last resort when the other termination signals
fails.
As you can see, I have noted here that context directly with the kernel to kill this process rather
than asking that please kill right.
It will contact directly with the kernel.
And we also have so we will discuss segue in end of this lecture.
And we also have term.
So this is the terminate and this is the default signal sent by the kill command.
So if a program is still alive enough to receive signals, it will terminate.
And we also have Continuum continue right here.
So this continuum, this will restore a process after a stop or stop signal.
And this is signal is sent by the uh, BG and FG command that we used in previous lectures.
And we also have stop this, stop this signal causes a process to pause without terminating it.
Like this is like the kill signal signal, but it is not sent to the target process and thus it cannot
be ignored.
And we also have terminal stop.
This is the signal sent by the terminal when the control is pressed.
Unlike the stop signal, the stop signal is received by the program, but the program may choose to
ignore it.
Right.
So now you are asking the program, Please, uh, please terminate my process.
But it the program can also choose.
Ignore your.
Option.
And here we will.
Now, let's actually we don't always here now let's actually start our X logo with background here and.
Oops.
Always on top.
So here, as you can see, we will use kill minus one and we will enter our So minus actually it's parameter
like we will enter with our.
And these are these are the.
So these are the signal IDs and these are the signal names.
You can also call, call kill with the signal IDs and signal names.
Same.
But in this case, now I will call it with one signal ID, So which is hang up.
Right.
So now 75006.
And here, as you can see here, hang up signal is called, as we have written here.
So in this example, we start the logo program in the background and then send the Q signal with the
hangup signal with a kill.
So the program terminates and the shell indicates that the background process has received a hangup
signal.
Right.
So we may need to press enter a couple of times before the message appears.
Note that the signal may be specified either by a number or by name, as I said earlier.
So including the name prefixed with the SIG here.
So let's actually write our X logger again.
Always on top and here.
We can repeat this process, right?
Kill it here, which is interrupt.
Let's actually see what interrupt is.
Interrupt.
The same as the control here.
Right.
So interrupt 75.
We will enter our process ID 757075708.
You know, as you can see here, interrupt signal is sent.
And let's start another example here and always on top here.
Now we will send a sig integer.
Sig sg interrupt.
Here, which is you will learn here, right?
So now we will.
Heil.
Sieg.
Interrupt, and we will enter.
Seven, five, nine, six, five.
And here we also set an interrupt.
And let's see.
Sieg interrupt here right now.
Right.
So repeat this example and try other signals as well.
And remember, we can also use the job space specs in place of process IDs and processes is like files,
right?
They have owners and you must be owner of the process or the superuser to send it signals with kill.
In addition, the list of the list of the signals covered so far, which are most often used with kill.
And there are other signals that I introduced in the start of this lecture that I told you that we will
also discuss about quit CV and whinge.
So the quit is basically quit here.
And the segue V here, this is interesting.
This is a segmentation violation and the signal is sent.
If a program makes illegal use of a memory.
That is if I if if program tried to write somewhere, it wasn't allowed to write and vincere will.
Lastly, this is a Windows change.
This is the signal sent by the system when a window changes size.
So some programs such as top here, as you can see here and less will respond to the signal by redrawing
themselves to fit the new window dimensions here, as you can see here.
As you can see here, nothing is breaking when I.
Change the window dimensions here.
It will look just fine.
And for the if you are curious about the more skilled commands, you can also display a complete list
of the kill commands with this command right here.