xref: /openbsd-src/usr.bin/pkill/pkill.1 (revision 70ef51b6352a49f1837c40f65d15a08e541620ff)
1.\"	$OpenBSD: pkill.1,v 1.25 2020/11/14 14:06:42 otto Exp $
2.\"	$NetBSD: pkill.1,v 1.8 2003/02/14 15:59:18 grant Exp $
3.\"
4.\" Copyright (c) 2002 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Andrew Doran.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29.\" POSSIBILITY OF SUCH DAMAGE.
30.\"
31.Dd $Mdocdate: November 14 2020 $
32.Dt PKILL 1
33.Os
34.Sh NAME
35.Nm pgrep , pkill
36.Nd find or signal processes by name
37.Sh SYNOPSIS
38.Nm pgrep
39.Op Fl flnoqvx
40.Op Fl d Ar delim
41.Op Fl G Ar gid
42.Op Fl g Ar pgrp
43.Op Fl P Ar ppid
44.Op Fl s Ar sid
45.Op Fl T Ar rtable
46.Op Fl t Ar tty
47.Op Fl U Ar uid
48.Op Fl u Ar euid
49.Op Ar pattern ...
50.Nm pkill
51.Op Fl Ar signal
52.Op Fl fIlnoqvx
53.Op Fl G Ar gid
54.Op Fl g Ar pgrp
55.Op Fl P Ar ppid
56.Op Fl s Ar sid
57.Op Fl T Ar rtable
58.Op Fl t Ar tty
59.Op Fl U Ar uid
60.Op Fl u Ar euid
61.Op Ar pattern ...
62.Sh DESCRIPTION
63The
64.Nm pgrep
65command searches the process table on the running system and prints the
66process IDs of all processes that match the criteria given on the command
67line.
68.Pp
69The
70.Nm pkill
71command searches the process table on the running system and signals all
72processes that match the criteria given on the command line.
73.Pp
74The following options are available:
75.Bl -tag -width Ds
76.It Fl d Ar delim
77Specify a delimiter to be printed between each process ID.
78The default is a newline.
79This option can only be used with the
80.Nm pgrep
81command.
82.It Fl f
83Match against full argument lists.
84The default is to match against process names.
85.It Fl G Ar gid
86Restrict matches to processes with a real group ID in the comma-separated
87list
88.Ar gid .
89.It Fl g Ar pgrp
90Restrict matches to processes with a process group ID in the comma-separated
91list
92.Ar pgrp .
93The value zero is taken to mean the process group ID of the running
94.Nm pgrep
95or
96.Nm pkill
97command.
98.It Fl I
99Ask for confirmation before killing a process.
100.It Fl l
101Long output.
102Print the process name in addition to the process ID for each matching
103process.
104If used in conjunction with
105.Fl f ,
106print the process ID and the full argument list for each matching process
107.Pf ( Nm pgrep
108only).
109.It Fl n
110Match only the most recently created (newest) process, if any.
111Cannot be used in conjunction with
112.Fl o .
113.It Fl o
114Match only the least recently created (oldest) process, if any.
115Cannot be used in conjunction with
116.Fl n .
117.It Fl P Ar ppid
118Restrict matches to processes with a parent process ID in the
119comma-separated list
120.Ar ppid .
121.It Fl q
122Quiet mode.
123Perform the action, but don't display anything on standard output.
124Note that
125.Fl q
126takes precedence over other display options such as
127.Fl l .
128.It Fl s Ar sid
129Restrict matches to processes with a session ID in the comma-separated
130list
131.Ar sid .
132The value zero is taken to mean the session ID of the running
133.Nm pgrep
134or
135.Nm pkill
136command.
137.It Fl T Ar rtable
138Restrict matches to processes associated with the specified routing tables
139in the comma-separated list
140.Ar rtable .
141.It Fl t Ar tty
142Restrict matches to processes associated with a terminal in the
143comma-separated list
144.Ar tty .
145Terminal names may be of the form
146.Sq ttyxx
147or the shortened form
148.Sq xx .
149A single dash
150.Pq Sq -
151matches processes not associated with a terminal.
152.It Fl U Ar uid
153Restrict matches to processes with a real user ID in the comma-separated
154list
155.Ar uid .
156.It Fl u Ar euid
157Restrict matches to processes with an effective user ID in the
158comma-separated list
159.Ar euid .
160.It Fl v
161Reverse the sense of the matching;
162display or signal processes that do not match the given criteria.
163.It Fl x
164Require an exact match of the process name, or argument list if
165.Fl f
166is given.
167The default is to match any substring.
168.It Fl Ar signal
169A non-negative decimal number or symbolic signal name specifying the signal
170to be sent instead of the default TERM.
171This option is valid only when given as the first argument to
172.Nm pkill .
173.El
174.Pp
175If any
176.Ar pattern
177operands are specified,
178they are used as extended regular expressions to match the command name.
179Only the first 16 characters of the command name are matched;
180attempts to match any characters after the first 16 will silently fail.
181If
182.Fl f
183is specified, the full argument list,
184including the full command name,
185of each process is matched.
186.Pp
187Note that a running
188.Nm pgrep
189or
190.Nm pkill
191process will never consider itself or system processes (kernel threads) as
192a potential match.
193.Sh EXIT STATUS
194The
195.Nm pgrep
196and
197.Nm pkill
198utilities exit with one of the following values:
199.Pp
200.Bl -tag -width Ds -offset indent -compact
201.It 0
202One or more processes were matched.
203.It 1
204No processes were matched.
205.It 2
206Invalid options were specified on the command line.
207.It 3
208An internal error occurred.
209.El
210.Sh SEE ALSO
211.Xr grep 1 ,
212.Xr kill 1 ,
213.Xr ps 1 ,
214.Xr kill 2 ,
215.Xr sigaction 2 ,
216.Xr re_format 7
217.Sh HISTORY
218.Nm pkill
219and
220.Nm pgrep
221first appeared in
222.Ox 3.5 .
223They are modelled after utilities of the same name that appeared in Sun
224Solaris 7.
225.Sh AUTHORS
226.An Andrew Doran
227.Aq Mt ad@NetBSD.org .
228