summaryrefslogtreecommitdiff
path: root/slackbook/html/process-control-kill.html
blob: 322926512eb28994a617846045e77ecab03a9eea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<title>kill</title>
<meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" />
<link rel="HOME" title="Slackware Linux Essentials" href="index.html" />
<link rel="UP" title="Process Control" href="process-control.html" />
<link rel="PREVIOUS" title="ps" href="process-control-ps.html" />
<link rel="NEXT" title="top" href="process-control-top.html" />
<link rel="STYLESHEET" type="text/css" href="docbook.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"
alink="#0000FF">
<div class="NAVHEADER">
<table summary="Header navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th colspan="3" align="center">Slackware Linux Essentials</th>
</tr>

<tr>
<td width="10%" align="left" valign="bottom"><a href="process-control-ps.html"
accesskey="P">Prev</a></td>
<td width="80%" align="center" valign="bottom">Chapter 11 Process Control</td>
<td width="10%" align="right" valign="bottom"><a href="process-control-top.html"
accesskey="N">Next</a></td>
</tr>
</table>

<hr align="LEFT" width="100%" />
</div>

<div class="SECT1">
<h1 class="SECT1"><a id="PROCESS-CONTROL-KILL" name="PROCESS-CONTROL-KILL">11.4 <tt
class="COMMAND">kill</tt></a></h1>

<p>On occasion, programs misbehave and you'll need to put them back in line. The program
for this kind of administration is called <tt class="COMMAND">kill</tt>(1), and it can be
used for manipulating processes in several ways. The most obvious use of <tt
class="COMMAND">kill</tt> is to kill off a process. You'll need to do this if a program
has run away and is using up lots of system resources, or if you're just sick of it
running.</p>

<p>In order to kill off a process, you'll need to know its PID or its name. To get the
PID, use the <tt class="COMMAND">ps</tt> command as was discussed in the last section.
For example, to kill off process 4747, you'd issue the following:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">kill 4747</kbd>
</pre>
</td>
</tr>
</table>

<p>Note that you'll have to be the owner of the process in order to kill it. This is a
security feature. If you were allowed to kill off processes started by other users, it
would be possible to do all sorts of malicious things. Of course, <tt
class="USERNAME">root</tt> can kill off any process on the system.</p>

<p>There's another variety of the <tt class="COMMAND">kill</tt> command called <tt
class="COMMAND">killall</tt>(1). This program does exactly what it says: it kills all the
running processes that have a certain name. If you wanted to kill off all the running <tt
class="COMMAND">vim</tt> processes, you could type the following command:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">killall vim</kbd>
</pre>
</td>
</tr>
</table>

<p>Any and all <tt class="COMMAND">vim</tt> processes you have running will die off.
Doing this as <tt class="USERNAME">root</tt> would kill off all the <tt
class="COMMAND">vim</tt> processes running for all users. This brings up an interesting
way to kick everyone (including yourself) off the system:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">#</samp> <kbd class="USERINPUT">killall bash</kbd>
</pre>
</td>
</tr>
</table>

<p>Sometimes a regular kill doesn't get the job done. Certain processes will not die with
a kill. You'll need to use a more potent form. If that pesky PID 4747 wasn't responding
to your kill request, you could do the following:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">kill -9 4747</kbd>
</pre>
</td>
</tr>
</table>

<p>That will almost certainly cause process 4747 to die. You can do the same thing with
<tt class="COMMAND">killall</tt>. What this is doing is sending a different signal to the
process. A regular <tt class="COMMAND">kill</tt> sends a <var
class="LITERAL">SIGTERM</var> (terminate) signal to the process, which tells it to finish
what it's doing, clean up, and exit. <tt class="COMMAND">kill -9</tt> sends a <var
class="LITERAL">SIGKILL</var> (kill) signal to the process, which essentially drops it.
The process is not allowed to clean-up, and sometimes bad things like data corruption
could occur by killing something with a <var class="LITERAL">SIGKILL</var>. There's a
whole list of signals at your disposal. You can get a listing of signals by typing the
following:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">kill -l</kbd>
  1) SIGHUP     2) SIGINT    3) SIGQUIT   4) SIGILL
  5) SIGTRAP    6) SIGABRT   7) SIGBUS    8) SIGFPE
  9) SIGKILL   10) SIGUSR1  11) SIGSEGV  12) SIGUSR2
 13) SIGPIPE   14) SIGALRM  15) SIGTERM  17) SIGCHLD
 18) SIGCONT   19) SIGSTOP  20) SIGTSTP  21) SIGTTIN
 22) SIGTTOU   23) SIGURG   24) SIGXCPU  25) SIGXFSZ
 26) SIGVTALRM 27) SIGPROF  28) SIGWINCH 29) SIGIO
 30) SIGPWR
</pre>
</td>
</tr>
</table>

<p>The number must be used for <tt class="COMMAND">kill</tt>, while the name minus the
leading &#8220;SIG&#8221; can be used with <tt class="COMMAND">killall</tt>. Here's
another example:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">killall -KILL vim</kbd>
</pre>
</td>
</tr>
</table>

<p>A final use of <tt class="COMMAND">kill</tt> is to restart a process. Sending a <var
class="LITERAL">SIGHUP</var> will cause most processes to re-read their configuration
files. This is especially helpful for telling system processes to re-read their config
files after editing.</p>
</div>

<div class="NAVFOOTER">
<hr align="LEFT" width="100%" />
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="33%" align="left" valign="top"><a href="process-control-ps.html"
accesskey="P">Prev</a></td>
<td width="34%" align="center" valign="top"><a href="index.html"
accesskey="H">Home</a></td>
<td width="33%" align="right" valign="top"><a href="process-control-top.html"
accesskey="N">Next</a></td>
</tr>

<tr>
<td width="33%" align="left" valign="top"><tt class="COMMAND">ps</tt></td>
<td width="34%" align="center" valign="top"><a href="process-control.html"
accesskey="U">Up</a></td>
<td width="33%" align="right" valign="top"><tt class="COMMAND">top</tt></td>
</tr>
</table>
</div>
</body>
</html>