1
00:00:01,350 --> 00:00:06,990
The kill command is used to kill processes, and this allows us to terminate programs that need killing.

2
00:00:06,990 --> 00:00:09,390
And this is some kind of pausing or termination.

3
00:00:09,390 --> 00:00:10,980
So here's an example here.

4
00:00:10,980 --> 00:00:16,890
And these are actually these are all the kill commands you can use with here, kill here.

5
00:00:17,100 --> 00:00:21,090
This is this is the list of commands we will use and we will discuss here.

6
00:00:21,090 --> 00:00:28,800
And let's actually clear and kill or actually, firstly, let's start X logo that our example with and

7
00:00:28,800 --> 00:00:29,520
background.

8
00:00:29,520 --> 00:00:34,410
So here this is our process ID and here it's actually always on top.

9
00:00:34,410 --> 00:00:37,350
So we first launch the x log in the background.

10
00:00:37,350 --> 00:00:42,570
Now let's kill this kill 71 608.

11
00:00:43,960 --> 00:00:46,180
Right here and be terminated.

12
00:00:47,430 --> 00:00:52,170
So the shell prints the job spec and the process ID of the background process.

13
00:00:53,000 --> 00:00:53,770
Right here.

14
00:00:53,780 --> 00:00:58,370
Next, we use the kill command and specify the process ID of the process we want to terminate.

15
00:00:58,400 --> 00:01:02,200
We could have also specified the process of job splits.

16
00:01:02,210 --> 00:01:05,180
For example, present one here.

17
00:01:06,780 --> 00:01:08,010
Always on top.

18
00:01:08,310 --> 00:01:08,940
Always on.

19
00:01:10,240 --> 00:01:10,510
Bob.

20
00:01:10,510 --> 00:01:17,830
And here we will write kill, kill Person one And as you can see, it will also terminate the X logo.

21
00:01:18,850 --> 00:01:21,960
So we will write at present one instead of the previous.

22
00:01:22,360 --> 00:01:26,440
So while this is all very straightforward, there is a more to it than that.

23
00:01:26,440 --> 00:01:31,930
So the kill command doesn't exactly kill processes, rather it sends them the signals.

24
00:01:31,960 --> 00:01:36,220
Signals are one of the several ways that the operating system communicates with programs.

25
00:01:36,220 --> 00:01:41,440
We already seen signals in action with the use of the control C and control Z.

26
00:01:41,740 --> 00:01:47,830
And when the terminal receives one of these keystrokes, it sends a signal to a program in the foreground.

27
00:01:48,130 --> 00:01:50,770
In the case of the control C right here.

28
00:01:51,930 --> 00:01:57,360
A signal called interrupt is sent and you will see you will learn all of this here.

29
00:01:57,360 --> 00:02:03,230
So with the control signal called interrupt is sent.

30
00:02:03,240 --> 00:02:04,950
So with control.

31
00:02:05,550 --> 00:02:09,360
With control Z here, control Z here.

32
00:02:09,570 --> 00:02:15,480
A signal called TFTP terminal stop is sent.

33
00:02:16,280 --> 00:02:21,410
So programs internal listen for the signals and may act upon them as they are received.

34
00:02:21,560 --> 00:02:28,010
The fact that program can listen and act upon signals allows a program to do things such as save work

35
00:02:28,010 --> 00:02:32,610
in progress when it sends a termination signal.

36
00:02:32,630 --> 00:02:37,040
So let's actually send the signals to process with the kill command here.

37
00:02:37,040 --> 00:02:38,260
So clear here.

38
00:02:38,270 --> 00:02:44,600
So the kill command is used to send signals in the signals to programs, Right?

39
00:02:44,870 --> 00:02:50,740
So it's most common syntax is going to in kill here we give it first the right kill.

40
00:02:50,750 --> 00:02:52,190
This is our command.

41
00:02:52,190 --> 00:02:54,830
And we will also specify some parameters here.

42
00:02:54,830 --> 00:02:57,590
So in this case, we're going to enter the signal type.

43
00:02:57,590 --> 00:03:02,090
We want to send signal single no here.

44
00:03:02,090 --> 00:03:04,880
So it's actually right here.

45
00:03:04,880 --> 00:03:06,770
Signal signal type.

46
00:03:06,770 --> 00:03:08,750
We want to send signal.

47
00:03:09,570 --> 00:03:13,380
And we will also enter the process ID.

48
00:03:14,680 --> 00:03:15,190
Right.

49
00:03:15,190 --> 00:03:24,880
So if no signal is specified on the command line, the if nothing if no signal specified in the command

50
00:03:24,880 --> 00:03:28,480
line, the termination terminate.

51
00:03:29,680 --> 00:03:30,070
Her.

52
00:03:35,890 --> 00:03:40,000
The terminate signal is sent by default.

53
00:03:40,270 --> 00:03:40,660
Right.

54
00:03:40,690 --> 00:03:42,510
The kill command is most often used.

55
00:03:42,670 --> 00:03:44,420
Send the signals here.

56
00:03:44,440 --> 00:03:47,820
I write all of these signals right down here.

57
00:03:47,830 --> 00:03:51,280
Most used and popular kill commands, which is whoop.

58
00:03:51,430 --> 00:03:52,810
This is a high gap.

59
00:03:53,050 --> 00:03:53,920
Now.

60
00:03:54,570 --> 00:03:55,500
This hoop here.

61
00:03:55,530 --> 00:04:01,050
This is a vestige of a good old days when terminals were attached to remote computers with phone lines

62
00:04:01,050 --> 00:04:01,950
and modems.

63
00:04:02,280 --> 00:04:10,380
So the signal is used to indicate the two programs that the controlling terminal has hung up.

64
00:04:10,470 --> 00:04:15,510
So the effect of this signal can be demonstrated by closing a terminal session and the foreground program

65
00:04:15,510 --> 00:04:18,990
running on the terminal will send the signal and it will terminate.

66
00:04:19,020 --> 00:04:25,350
The signal is also used by many Daemon programs to cause a reinitialization.

67
00:04:25,740 --> 00:04:28,100
And this means what?

68
00:04:28,100 --> 00:04:31,320
The daemon is set to send the signal.

69
00:04:31,320 --> 00:04:37,830
It will restart and reread its configuration file and the patch web server is an example of a daemon

70
00:04:38,220 --> 00:04:42,990
that uses the hop signal hangup signal in this way.

71
00:04:42,990 --> 00:04:45,200
And we also have the interrupt.

72
00:04:45,210 --> 00:04:49,230
So this performs the same function as the control C send from the terminal.

73
00:04:49,230 --> 00:04:52,710
It will usually terminate a program in an interrupt.

74
00:04:52,710 --> 00:05:00,750
And we also have quit actually, we will discuss quit Segway and whinge in the end of today's lecture.

75
00:05:00,750 --> 00:05:03,390
But firstly, we will discuss kill here right now.

76
00:05:03,390 --> 00:05:06,630
So the kill this this signal is special, right?

77
00:05:06,630 --> 00:05:12,240
So whereas programs may choose to handle signals sent to them in a different ways, including ignoring

78
00:05:12,240 --> 00:05:16,530
them altogether, so the kill signal is never actually ignoring them altogether.

79
00:05:17,130 --> 00:05:22,260
Uh, the kill is never actually sent to the target program, right?

80
00:05:22,260 --> 00:05:28,470
The rather than kernel here, kernel immediately terminates the program or process.

81
00:05:28,470 --> 00:05:35,820
So when a process is terminated in this manner, it is given no opportunity to clean up after itself

82
00:05:35,820 --> 00:05:36,870
or save its work.

83
00:05:36,870 --> 00:05:45,210
For this reason, the kill signal should be used only as a last resort when the other termination signals

84
00:05:45,210 --> 00:05:45,470
fails.

85
00:05:45,480 --> 00:05:53,820
As you can see, I have noted here that context directly with the kernel to kill this process rather

86
00:05:53,820 --> 00:05:56,620
than asking that please kill right.

87
00:05:56,620 --> 00:05:59,350
It will contact directly with the kernel.

88
00:05:59,530 --> 00:06:04,480
And we also have so we will discuss segue in end of this lecture.

89
00:06:04,480 --> 00:06:06,190
And we also have term.

90
00:06:06,490 --> 00:06:11,080
So this is the terminate and this is the default signal sent by the kill command.

91
00:06:11,080 --> 00:06:17,020
So if a program is still alive enough to receive signals, it will terminate.

92
00:06:17,020 --> 00:06:21,190
And we also have Continuum continue right here.

93
00:06:21,190 --> 00:06:26,590
So this continuum, this will restore a process after a stop or stop signal.

94
00:06:26,590 --> 00:06:33,190
And this is signal is sent by the uh, BG and FG command that we used in previous lectures.

95
00:06:33,190 --> 00:06:41,500
And we also have stop this, stop this signal causes a process to pause without terminating it.

96
00:06:41,500 --> 00:06:49,420
Like this is like the kill signal signal, but it is not sent to the target process and thus it cannot

97
00:06:49,420 --> 00:06:51,280
be ignored.

98
00:06:51,490 --> 00:06:54,370
And we also have terminal stop.

99
00:06:54,610 --> 00:06:58,540
This is the signal sent by the terminal when the control is pressed.

100
00:06:58,540 --> 00:07:05,140
Unlike the stop signal, the stop signal is received by the program, but the program may choose to

101
00:07:05,140 --> 00:07:05,680
ignore it.

102
00:07:05,680 --> 00:07:06,190
Right.

103
00:07:06,190 --> 00:07:11,410
So now you are asking the program, Please, uh, please terminate my process.

104
00:07:11,410 --> 00:07:13,580
But it the program can also choose.

105
00:07:13,600 --> 00:07:15,070
Ignore your.

106
00:07:15,850 --> 00:07:16,510
Option.

107
00:07:16,750 --> 00:07:19,120
And here we will.

108
00:07:19,120 --> 00:07:27,580
Now, let's actually we don't always here now let's actually start our X logo with background here and.

109
00:07:28,470 --> 00:07:28,730
Oops.

110
00:07:30,030 --> 00:07:31,140
Always on top.

111
00:07:35,120 --> 00: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

112
00:07:44,390 --> 00:07:46,490
like we will enter with our.

113
00:07:47,670 --> 00:07:49,140
And these are these are the.

114
00:07:50,870 --> 00:07:54,110
So these are the signal IDs and these are the signal names.

115
00:07:54,110 --> 00:07:59,450
You can also call, call kill with the signal IDs and signal names.

116
00:07:59,660 --> 00:08:00,050
Same.

117
00:08:00,050 --> 00:08:06,170
But in this case, now I will call it with one signal ID, So which is hang up.

118
00:08:06,230 --> 00:08:06,920
Right.

119
00:08:06,920 --> 00:08:10,970
So now 75006.

120
00:08:11,730 --> 00:08:16,980
And here, as you can see here, hang up signal is called, as we have written here.

121
00:08:16,980 --> 00:08:23,280
So in this example, we start the logo program in the background and then send the Q signal with the

122
00:08:23,520 --> 00:08:24,710
hangup signal with a kill.

123
00:08:24,720 --> 00:08:31,200
So the program terminates and the shell indicates that the background process has received a hangup

124
00:08:31,200 --> 00:08:31,860
signal.

125
00:08:32,940 --> 00:08:33,300
Right.

126
00:08:33,300 --> 00:08:38,080
So we may need to press enter a couple of times before the message appears.

127
00:08:38,100 --> 00:08:43,960
Note that the signal may be specified either by a number or by name, as I said earlier.

128
00:08:43,980 --> 00:08:47,600
So including the name prefixed with the SIG here.

129
00:08:47,610 --> 00:08:51,810
So let's actually write our X logger again.

130
00:08:51,810 --> 00:08:55,170
Always on top and here.

131
00:08:56,050 --> 00:08:57,710
We can repeat this process, right?

132
00:08:57,730 --> 00:09:00,950
Kill it here, which is interrupt.

133
00:09:00,970 --> 00:09:02,860
Let's actually see what interrupt is.

134
00:09:02,890 --> 00:09:04,000
Interrupt.

135
00:09:04,000 --> 00:09:04,390
Interrupt.

136
00:09:04,390 --> 00:09:05,420
The same as the control here.

137
00:09:05,470 --> 00:09:05,920
Right.

138
00:09:05,920 --> 00:09:08,280
So interrupt 75.

139
00:09:08,290 --> 00:09:14,830
We will enter our process ID 757075708.

140
00:09:15,260 --> 00:09:18,090
You know, as you can see here, interrupt signal is sent.

141
00:09:19,020 --> 00:09:23,970
And let's start another example here and always on top here.

142
00:09:23,970 --> 00:09:26,310
Now we will send a sig integer.

143
00:09:26,520 --> 00:09:27,840
Sig sg interrupt.

144
00:09:29,530 --> 00:09:32,050
Here, which is you will learn here, right?

145
00:09:32,530 --> 00:09:33,970
So now we will.

146
00:09:34,990 --> 00:09:35,420
Heil.

147
00:09:36,250 --> 00:09:36,810
Sieg.

148
00:09:37,060 --> 00:09:39,700
Interrupt, and we will enter.

149
00:09:39,700 --> 00:09:42,970
Seven, five, nine, six, five.

150
00:09:43,180 --> 00:09:45,850
And here we also set an interrupt.

151
00:09:45,850 --> 00:09:46,960
And let's see.

152
00:09:46,990 --> 00:09:48,730
Sieg interrupt here right now.

153
00:09:48,730 --> 00:09:49,180
Right.

154
00:09:49,180 --> 00:09:52,990
So repeat this example and try other signals as well.

155
00:09:52,990 --> 00:10:00,280
And remember, we can also use the job space specs in place of process IDs and processes is like files,

156
00:10:00,280 --> 00:10:00,610
right?

157
00:10:01,060 --> 00:10:08,770
They have owners and you must be owner of the process or the superuser to send it signals with kill.

158
00:10:09,010 --> 00:10:16,060
In addition, the list of the list of the signals covered so far, which are most often used with kill.

159
00:10:16,060 --> 00:10:22,780
And there are other signals that I introduced in the start of this lecture that I told you that we will

160
00:10:22,780 --> 00:10:27,490
also discuss about quit CV and whinge.

161
00:10:28,880 --> 00:10:31,460
So the quit is basically quit here.

162
00:10:31,460 --> 00:10:33,800
And the segue V here, this is interesting.

163
00:10:33,800 --> 00:10:37,490
This is a segmentation violation and the signal is sent.

164
00:10:37,490 --> 00:10:41,270
If a program makes illegal use of a memory.

165
00:10:41,270 --> 00:10:49,550
That is if I if if program tried to write somewhere, it wasn't allowed to write and vincere will.

166
00:10:49,550 --> 00:10:51,380
Lastly, this is a Windows change.

167
00:10:51,380 --> 00:10:55,580
This is the signal sent by the system when a window changes size.

168
00:10:55,580 --> 00:11:03,620
So some programs such as top here, as you can see here and less will respond to the signal by redrawing

169
00:11:03,620 --> 00:11:09,350
themselves to fit the new window dimensions here, as you can see here.

170
00:11:12,800 --> 00:11:16,610
As you can see here, nothing is breaking when I.

171
00:11:17,420 --> 00:11:18,920
Change the window dimensions here.

172
00:11:18,920 --> 00:11:20,870
It will look just fine.

173
00:11:22,160 --> 00:11:28,490
And for the if you are curious about the more skilled commands, you can also display a complete list

174
00:11:28,490 --> 00:11:32,450
of the kill commands with this command right here.
