WEBVTT

00:01.350 --> 00:06.990
The kill command is used to kill processes, and this allows us to terminate programs that need killing.

00:06.990 --> 00:09.390
And this is some kind of pausing or termination.

00:09.390 --> 00:10.980
So here's an example here.

00:10.980 --> 00:16.890
And these are actually these are all the kill commands you can use with here, kill here.

00:17.100 --> 00:21.090
This is this is the list of commands we will use and we will discuss here.

00:21.090 --> 00:28.800
And let's actually clear and kill or actually, firstly, let's start X logo that our example with and

00:28.800 --> 00:29.520
background.

00:29.520 --> 00:34.410
So here this is our process ID and here it's actually always on top.

00:34.410 --> 00:37.350
So we first launch the x log in the background.

00:37.350 --> 00:42.570
Now let's kill this kill 71 608.

00:43.960 --> 00:46.180
Right here and be terminated.

00:47.430 --> 00:52.170
So the shell prints the job spec and the process ID of the background process.

00:53.000 --> 00:53.770
Right here.

00:53.780 --> 00:58.370
Next, we use the kill command and specify the process ID of the process we want to terminate.

00:58.400 --> 01:02.200
We could have also specified the process of job splits.

01:02.210 --> 01:05.180
For example, present one here.

01:06.780 --> 01:08.010
Always on top.

01:08.310 --> 01:08.940
Always on.

01:10.240 --> 01:10.510
Bob.

01:10.510 --> 01:17.830
And here we will write kill, kill Person one And as you can see, it will also terminate the X logo.

01:18.850 --> 01:21.960
So we will write at present one instead of the previous.

01:22.360 --> 01:26.440
So while this is all very straightforward, there is a more to it than that.

01:26.440 --> 01:31.930
So the kill command doesn't exactly kill processes, rather it sends them the signals.

01:31.960 --> 01:36.220
Signals are one of the several ways that the operating system communicates with programs.

01:36.220 --> 01:41.440
We already seen signals in action with the use of the control C and control Z.

01:41.740 --> 01:47.830
And when the terminal receives one of these keystrokes, it sends a signal to a program in the foreground.

01:48.130 --> 01:50.770
In the case of the control C right here.

01:51.930 --> 01:57.360
A signal called interrupt is sent and you will see you will learn all of this here.

01:57.360 --> 02:03.230
So with the control signal called interrupt is sent.

02:03.240 --> 02:04.950
So with control.

02:05.550 --> 02:09.360
With control Z here, control Z here.

02:09.570 --> 02:15.480
A signal called TFTP terminal stop is sent.

02:16.280 --> 02:21.410
So programs internal listen for the signals and may act upon them as they are received.

02:21.560 --> 02:28.010
The fact that program can listen and act upon signals allows a program to do things such as save work

02:28.010 --> 02:32.610
in progress when it sends a termination signal.

02:32.630 --> 02:37.040
So let's actually send the signals to process with the kill command here.

02:37.040 --> 02:38.260
So clear here.

02:38.270 --> 02:44.600
So the kill command is used to send signals in the signals to programs, Right?

02:44.870 --> 02:50.740
So it's most common syntax is going to in kill here we give it first the right kill.

02:50.750 --> 02:52.190
This is our command.

02:52.190 --> 02:54.830
And we will also specify some parameters here.

02:54.830 --> 02:57.590
So in this case, we're going to enter the signal type.

02:57.590 --> 03:02.090
We want to send signal single no here.

03:02.090 --> 03:04.880
So it's actually right here.

03:04.880 --> 03:06.770
Signal signal type.

03:06.770 --> 03:08.750
We want to send signal.

03:09.570 --> 03:13.380
And we will also enter the process ID.

03:14.680 --> 03:15.190
Right.

03:15.190 --> 03:24.880
So if no signal is specified on the command line, the if nothing if no signal specified in the command

03:24.880 --> 03:28.480
line, the termination terminate.

03:29.680 --> 03:30.070
Her.

03:35.890 --> 03:40.000
The terminate signal is sent by default.

03:40.270 --> 03:40.660
Right.

03:40.690 --> 03:42.510
The kill command is most often used.

03:42.670 --> 03:44.420
Send the signals here.

03:44.440 --> 03:47.820
I write all of these signals right down here.

03:47.830 --> 03:51.280
Most used and popular kill commands, which is whoop.

03:51.430 --> 03:52.810
This is a high gap.

03:53.050 --> 03:53.920
Now.

03:54.570 --> 03:55.500
This hoop here.

03:55.530 --> 04:01.050
This is a vestige of a good old days when terminals were attached to remote computers with phone lines

04:01.050 --> 04:01.950
and modems.

04:02.280 --> 04:10.380
So the signal is used to indicate the two programs that the controlling terminal has hung up.

04:10.470 --> 04:15.510
So the effect of this signal can be demonstrated by closing a terminal session and the foreground program

04:15.510 --> 04:18.990
running on the terminal will send the signal and it will terminate.

04:19.020 --> 04:25.350
The signal is also used by many Daemon programs to cause a reinitialization.

04:25.740 --> 04:28.100
And this means what?

04:28.100 --> 04:31.320
The daemon is set to send the signal.

04:31.320 --> 04:37.830
It will restart and reread its configuration file and the patch web server is an example of a daemon

04:38.220 --> 04:42.990
that uses the hop signal hangup signal in this way.

04:42.990 --> 04:45.200
And we also have the interrupt.

04:45.210 --> 04:49.230
So this performs the same function as the control C send from the terminal.

04:49.230 --> 04:52.710
It will usually terminate a program in an interrupt.

04:52.710 --> 05:00.750
And we also have quit actually, we will discuss quit Segway and whinge in the end of today's lecture.

05:00.750 --> 05:03.390
But firstly, we will discuss kill here right now.

05:03.390 --> 05:06.630
So the kill this this signal is special, right?

05:06.630 --> 05:12.240
So whereas programs may choose to handle signals sent to them in a different ways, including ignoring

05:12.240 --> 05:16.530
them altogether, so the kill signal is never actually ignoring them altogether.

05:17.130 --> 05:22.260
Uh, the kill is never actually sent to the target program, right?

05:22.260 --> 05:28.470
The rather than kernel here, kernel immediately terminates the program or process.

05:28.470 --> 05:35.820
So when a process is terminated in this manner, it is given no opportunity to clean up after itself

05:35.820 --> 05:36.870
or save its work.

05:36.870 --> 05:45.210
For this reason, the kill signal should be used only as a last resort when the other termination signals

05:45.210 --> 05:45.470
fails.

05:45.480 --> 05:53.820
As you can see, I have noted here that context directly with the kernel to kill this process rather

05:53.820 --> 05:56.620
than asking that please kill right.

05:56.620 --> 05:59.350
It will contact directly with the kernel.

05:59.530 --> 06:04.480
And we also have so we will discuss segue in end of this lecture.

06:04.480 --> 06:06.190
And we also have term.

06:06.490 --> 06:11.080
So this is the terminate and this is the default signal sent by the kill command.

06:11.080 --> 06:17.020
So if a program is still alive enough to receive signals, it will terminate.

06:17.020 --> 06:21.190
And we also have Continuum continue right here.

06:21.190 --> 06:26.590
So this continuum, this will restore a process after a stop or stop signal.

06:26.590 --> 06:33.190
And this is signal is sent by the uh, BG and FG command that we used in previous lectures.

06:33.190 --> 06:41.500
And we also have stop this, stop this signal causes a process to pause without terminating it.

06:41.500 --> 06:49.420
Like this is like the kill signal signal, but it is not sent to the target process and thus it cannot

06:49.420 --> 06:51.280
be ignored.

06:51.490 --> 06:54.370
And we also have terminal stop.

06:54.610 --> 06:58.540
This is the signal sent by the terminal when the control is pressed.

06:58.540 --> 07:05.140
Unlike the stop signal, the stop signal is received by the program, but the program may choose to

07:05.140 --> 07:05.680
ignore it.

07:05.680 --> 07:06.190
Right.

07:06.190 --> 07:11.410
So now you are asking the program, Please, uh, please terminate my process.

07:11.410 --> 07:13.580
But it the program can also choose.

07:13.600 --> 07:15.070
Ignore your.

07:15.850 --> 07:16.510
Option.

07:16.750 --> 07:19.120
And here we will.

07:19.120 --> 07:27.580
Now, let's actually we don't always here now let's actually start our X logo with background here and.

07:28.470 --> 07:28.730
Oops.

07:30.030 --> 07:31.140
Always on top.

07:35.120 --> 07:44.390
So here, as you can see, we will use kill minus one and we will enter our So minus actually it's parameter

07:44.390 --> 07:46.490
like we will enter with our.

07:47.670 --> 07:49.140
And these are these are the.

07:50.870 --> 07:54.110
So these are the signal IDs and these are the signal names.

07:54.110 --> 07:59.450
You can also call, call kill with the signal IDs and signal names.

07:59.660 --> 08:00.050
Same.

08:00.050 --> 08:06.170
But in this case, now I will call it with one signal ID, So which is hang up.

08:06.230 --> 08:06.920
Right.

08:06.920 --> 08:10.970
So now 75006.

08:11.730 --> 08:16.980
And here, as you can see here, hang up signal is called, as we have written here.

08:16.980 --> 08:23.280
So in this example, we start the logo program in the background and then send the Q signal with the

08:23.520 --> 08:24.710
hangup signal with a kill.

08:24.720 --> 08:31.200
So the program terminates and the shell indicates that the background process has received a hangup

08:31.200 --> 08:31.860
signal.

08:32.940 --> 08:33.300
Right.

08:33.300 --> 08:38.080
So we may need to press enter a couple of times before the message appears.

08:38.100 --> 08:43.960
Note that the signal may be specified either by a number or by name, as I said earlier.

08:43.980 --> 08:47.600
So including the name prefixed with the SIG here.

08:47.610 --> 08:51.810
So let's actually write our X logger again.

08:51.810 --> 08:55.170
Always on top and here.

08:56.050 --> 08:57.710
We can repeat this process, right?

08:57.730 --> 09:00.950
Kill it here, which is interrupt.

09:00.970 --> 09:02.860
Let's actually see what interrupt is.

09:02.890 --> 09:04.000
Interrupt.

09:04.000 --> 09:04.390
Interrupt.

09:04.390 --> 09:05.420
The same as the control here.

09:05.470 --> 09:05.920
Right.

09:05.920 --> 09:08.280
So interrupt 75.

09:08.290 --> 09:14.830
We will enter our process ID 757075708.

09:15.260 --> 09:18.090
You know, as you can see here, interrupt signal is sent.

09:19.020 --> 09:23.970
And let's start another example here and always on top here.

09:23.970 --> 09:26.310
Now we will send a sig integer.

09:26.520 --> 09:27.840
Sig sg interrupt.

09:29.530 --> 09:32.050
Here, which is you will learn here, right?

09:32.530 --> 09:33.970
So now we will.

09:34.990 --> 09:35.420
Heil.

09:36.250 --> 09:36.810
Sieg.

09:37.060 --> 09:39.700
Interrupt, and we will enter.

09:39.700 --> 09:42.970
Seven, five, nine, six, five.

09:43.180 --> 09:45.850
And here we also set an interrupt.

09:45.850 --> 09:46.960
And let's see.

09:46.990 --> 09:48.730
Sieg interrupt here right now.

09:48.730 --> 09:49.180
Right.

09:49.180 --> 09:52.990
So repeat this example and try other signals as well.

09:52.990 --> 10:00.280
And remember, we can also use the job space specs in place of process IDs and processes is like files,

10:00.280 --> 10:00.610
right?

10:01.060 --> 10:08.770
They have owners and you must be owner of the process or the superuser to send it signals with kill.

10:09.010 --> 10:16.060
In addition, the list of the list of the signals covered so far, which are most often used with kill.

10:16.060 --> 10:22.780
And there are other signals that I introduced in the start of this lecture that I told you that we will

10:22.780 --> 10:27.490
also discuss about quit CV and whinge.

10:28.880 --> 10:31.460
So the quit is basically quit here.

10:31.460 --> 10:33.800
And the segue V here, this is interesting.

10:33.800 --> 10:37.490
This is a segmentation violation and the signal is sent.

10:37.490 --> 10:41.270
If a program makes illegal use of a memory.

10:41.270 --> 10:49.550
That is if I if if program tried to write somewhere, it wasn't allowed to write and vincere will.

10:49.550 --> 10:51.380
Lastly, this is a Windows change.

10:51.380 --> 10:55.580
This is the signal sent by the system when a window changes size.

10:55.580 --> 11:03.620
So some programs such as top here, as you can see here and less will respond to the signal by redrawing

11:03.620 --> 11:09.350
themselves to fit the new window dimensions here, as you can see here.

11:12.800 --> 11:16.610
As you can see here, nothing is breaking when I.

11:17.420 --> 11:18.920
Change the window dimensions here.

11:18.920 --> 11:20.870
It will look just fine.

11:22.160 --> 11:28.490
And for the if you are curious about the more skilled commands, you can also display a complete list

11:28.490 --> 11:32.450
of the kill commands with this command right here.
