xref: /freebsd/bin/pkill/pkill.1 (revision 0e1497aefd602cea581d2380d22e67dfdcac6b4e)
1.\"	$NetBSD: pkill.1,v 1.8 2003/02/14 15:59:18 grant Exp $
2.\"
3.\" $FreeBSD$
4.\"
5.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
6.\" All rights reserved.
7.\"
8.\" This code is derived from software contributed to The NetBSD Foundation
9.\" by Andrew Doran.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30.\" POSSIBILITY OF SUCH DAMAGE.
31.\"
32.Dd February 11, 2010
33.Dt PKILL 1
34.Os
35.Sh NAME
36.Nm pgrep , pkill
37.Nd find or signal processes by name
38.Sh SYNOPSIS
39.Nm pgrep
40.Op Fl LSafilnoqvx
41.Op Fl F Ar pidfile
42.Op Fl G Ar gid
43.Op Fl M Ar core
44.Op Fl N Ar system
45.Op Fl P Ar ppid
46.Op Fl U Ar uid
47.Op Fl d Ar delim
48.Op Fl g Ar pgrp
49.Op Fl j Ar jid
50.Op Fl s Ar sid
51.Op Fl t Ar tty
52.Op Fl u Ar euid
53.Ar pattern ...
54.Nm pkill
55.Op Fl Ar signal
56.Op Fl ILafilnovx
57.Op Fl F Ar pidfile
58.Op Fl G Ar gid
59.Op Fl M Ar core
60.Op Fl N Ar system
61.Op Fl P Ar ppid
62.Op Fl U Ar uid
63.Op Fl g Ar pgrp
64.Op Fl j Ar jid
65.Op Fl s Ar sid
66.Op Fl t Ar tty
67.Op Fl u Ar euid
68.Ar pattern ...
69.Sh DESCRIPTION
70The
71.Nm pgrep
72command searches the process table on the running system and prints the
73process IDs of all processes that match the criteria given on the command
74line.
75.Pp
76The
77.Nm pkill
78command searches the process table on the running system and signals all
79processes that match the criteria given on the command line.
80.Pp
81The following options are available:
82.Bl -tag -width ".Fl F Ar pidfile"
83.It Fl F Ar pidfile
84Restrict matches to a process whose PID is stored in the
85.Ar pidfile
86file.
87.It Fl G Ar gid
88Restrict matches to processes with a real group ID in the comma-separated
89list
90.Ar gid .
91.It Fl I
92Request confirmation before attempting to signal each process.
93.It Fl L
94The
95.Ar pidfile
96file given for the
97.Fl F
98option must be locked with the
99.Xr flock 2
100syscall or created with
101.Xr pidfile 3 .
102.It Fl M Ar core
103Extract values associated with the name list from the specified core
104instead of the currently running system.
105.It Fl N Ar system
106Extract the name list from the specified system instead of the default,
107which is the kernel image the system has booted from.
108.It Fl P Ar ppid
109Restrict matches to processes with a parent process ID in the
110comma-separated list
111.Ar ppid .
112.It Fl S
113Search also in system processes (kernel threads).
114.It Fl U Ar uid
115Restrict matches to processes with a real user ID in the comma-separated
116list
117.Ar uid .
118.It Fl d Ar delim
119Specify a delimiter to be printed between each process ID.
120The default is a newline.
121This option can only be used with the
122.Nm pgrep
123command.
124.It Fl a
125Include process ancestors in the match list.
126By default, the current
127.Nm pgrep
128or
129.Nm pkill
130process and all of its ancestors are excluded (unless
131.Fl v
132is used).
133.It Fl f
134Match against full argument lists.
135The default is to match against process names.
136.It Fl g Ar pgrp
137Restrict matches to processes with a process group ID in the comma-separated
138list
139.Ar pgrp .
140The value zero is taken to mean the process group ID of the running
141.Nm pgrep
142or
143.Nm pkill
144command.
145.It Fl i
146Ignore case distinctions in both the process table and the supplied pattern.
147.It Fl j Ar jid
148Restrict matches to processes inside jails with a jail ID in the comma-separated
149list
150.Ar jid .
151The value
152.Dq Li any
153matches processes in any jail.
154The value
155.Dq Li none
156matches processes not in jail.
157.It Fl l
158Long output.
159For
160.Nm pgrep ,
161print the process name in addition to the process ID for each matching
162process.
163If used in conjunction with
164.Fl f ,
165print the process ID and the full argument list for each matching process.
166For
167.Nm pkill ,
168display the kill command used for each process killed.
169.It Fl n
170Select only the newest (most recently started) of the matching processes.
171.It Fl o
172Select only the oldest (least recently started) of the matching processes.
173.It Fl q
174Do not write anything to standard output.
175.It Fl s Ar sid
176Restrict matches to processes with a session ID in the comma-separated
177list
178.Ar sid .
179The value zero is taken to mean the session ID of the running
180.Nm pgrep
181or
182.Nm pkill
183command.
184.It Fl t Ar tty
185Restrict matches to processes associated with a terminal in the
186comma-separated list
187.Ar tty .
188Terminal names may be of the form
189.Pa tty Ns Ar xx
190or the shortened form
191.Ar xx .
192A single dash
193.Pq Ql -
194matches processes not associated with a terminal.
195.It Fl u Ar euid
196Restrict matches to processes with an effective user ID in the
197comma-separated list
198.Ar euid .
199.It Fl v
200Reverse the sense of the matching; display processes that do not match the
201given criteria.
202.It Fl x
203Require an exact match of the process name, or argument list if
204.Fl f
205is given.
206The default is to match any substring.
207.It Fl Ns Ar signal
208A non-negative decimal number or symbolic signal name specifying the signal
209to be sent instead of the default
210.Dv TERM .
211This option is valid only when given as the first argument to
212.Nm pkill .
213.El
214.Pp
215If any
216.Ar pattern
217operands are specified, they are used as regular expressions to match
218the command name or full argument list of each process.
219If the
220.Fl f
221option is not specified, then the
222.Ar pattern
223will attempt to match the command name.
224However, presently
225.Fx
226will only keep track of the first 19 characters of the command
227name for each process.
228Attempts to match any characters after the first 19 of a command name
229will quietly fail.
230.Pp
231Note that a running
232.Nm pgrep
233or
234.Nm pkill
235process will never consider itself nor system processes (kernel threads) as
236a potential match.
237.Sh EXIT STATUS
238The
239.Nm pgrep
240and
241.Nm pkill
242utilities
243return one of the following values upon exit:
244.Bl -tag -width indent
245.It 0
246One or more processes were matched.
247.It 1
248No processes were matched.
249.It 2
250Invalid options were specified on the command line.
251.It 3
252An internal error occurred.
253.El
254.Sh COMPATIBILITY
255Historically the option
256.Dq Fl j Li 0
257means any jail, although in other utilities such as
258.Xr ps 1
259jail ID
260.Li 0
261has the opposite meaning, not in jail.
262Therefore
263.Dq Fl j Li 0
264is deprecated, and its use is discouraged in favor of
265.Dq Fl j Li any .
266.Sh SEE ALSO
267.Xr kill 1 ,
268.Xr killall 1 ,
269.Xr ps 1 ,
270.Xr flock 2 ,
271.Xr kill 2 ,
272.Xr sigaction 2 ,
273.Xr pidfile 3 ,
274.Xr re_format 7
275.\" Xr signal 7
276.Sh HISTORY
277The
278.Nm pkill
279and
280.Nm pgrep
281utilities
282first appeared in
283.Nx 1.6 .
284They are modelled after utilities of the same name that appeared in Sun
285Solaris 7.
286They made their first appearance in
287.Fx 5.3 .
288.Sh AUTHORS
289.An Andrew Doran
290.Aq ad@NetBSD.org
291