xref: /freebsd/bin/pkill/pkill.1 (revision 3157ba21)
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 ILafinovx
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.
159Print the process name in addition to the process ID for each matching
160process.
161If used in conjunction with
162.Fl f ,
163print the process ID and the full argument list for each matching process.
164This option can only be used with the
165.Nm pgrep
166command.
167.It Fl n
168Select only the newest (most recently started) of the matching processes.
169.It Fl o
170Select only the oldest (least recently started) of the matching processes.
171.It Fl q
172Do not write anything to standard output.
173.It Fl s Ar sid
174Restrict matches to processes with a session ID in the comma-separated
175list
176.Ar sid .
177The value zero is taken to mean the session ID of the running
178.Nm pgrep
179or
180.Nm pkill
181command.
182.It Fl t Ar tty
183Restrict matches to processes associated with a terminal in the
184comma-separated list
185.Ar tty .
186Terminal names may be of the form
187.Pa tty Ns Ar xx
188or the shortened form
189.Ar xx .
190A single dash
191.Pq Ql -
192matches processes not associated with a terminal.
193.It Fl u Ar euid
194Restrict matches to processes with an effective user ID in the
195comma-separated list
196.Ar euid .
197.It Fl v
198Reverse the sense of the matching; display processes that do not match the
199given criteria.
200.It Fl x
201Require an exact match of the process name, or argument list if
202.Fl f
203is given.
204The default is to match any substring.
205.It Fl Ns Ar signal
206A non-negative decimal number or symbolic signal name specifying the signal
207to be sent instead of the default
208.Dv TERM .
209This option is valid only when given as the first argument to
210.Nm pkill .
211.El
212.Pp
213If any
214.Ar pattern
215operands are specified, they are used as regular expressions to match
216the command name or full argument list of each process.
217If the
218.Fl f
219option is not specified, then the
220.Ar pattern
221will attempt to match the command name.
222However, presently
223.Fx
224will only keep track of the first 19 characters of the command
225name for each process.
226Attempts to match any characters after the first 19 of a command name
227will quietly fail.
228.Pp
229Note that a running
230.Nm pgrep
231or
232.Nm pkill
233process will never consider itself nor system processes (kernel threads) as
234a potential match.
235.Sh EXIT STATUS
236The
237.Nm pgrep
238and
239.Nm pkill
240utilities
241return one of the following values upon exit:
242.Bl -tag -width indent
243.It 0
244One or more processes were matched.
245.It 1
246No processes were matched.
247.It 2
248Invalid options were specified on the command line.
249.It 3
250An internal error occurred.
251.El
252.Sh COMPATIBILITY
253Historically the option
254.Dq Fl j Li 0
255means any jail, although in other utilities such as
256.Xr ps 1
257jail ID
258.Li 0
259has the opposite meaning, not in jail.
260Therefore
261.Dq Fl j Li 0
262is deprecated, and its use is discouraged in favor of
263.Dq Fl j Li any .
264.Sh SEE ALSO
265.Xr kill 1 ,
266.Xr killall 1 ,
267.Xr ps 1 ,
268.Xr flock 2 ,
269.Xr kill 2 ,
270.Xr sigaction 2 ,
271.Xr pidfile 3 ,
272.Xr re_format 7
273.\" Xr signal 7
274.Sh HISTORY
275The
276.Nm pkill
277and
278.Nm pgrep
279utilities
280first appeared in
281.Nx 1.6 .
282They are modelled after utilities of the same name that appeared in Sun
283Solaris 7.
284They made their first appearance in
285.Fx 5.3 .
286.Sh AUTHORS
287.An Andrew Doran
288.Aq ad@NetBSD.org
289