summaryrefslogtreecommitdiff
path: root/usr/src/man/man1/pgrep.1
blob: 9e65244f8d03240a51c494d8751ca52d43f6896b (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
'\" te
.\"  Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH PGREP 1 "Jan 17, 2014"
.SH NAME
pgrep, pkill \- find or signal processes by name and other attributes
.SH SYNOPSIS
.LP
.nf
\fBpgrep\fR [\fB-flvx\fR] [\fB-n\fR | \fB-o\fR] [\fB-d\fR \fIdelim\fR] [\fB-P\fR \fIppidlist\fR]
     [\fB-g\fR \fIpgrplist\fR] [\fB-s\fR \fIsidlist\fR] [\fB-u\fR \fIeuidlist\fR] [\fB-U\fR \fIuidlist\fR]
     [\fB-G\fR \fIgidlist\fR] [\fB-J\fR \fIprojidlist\fR] [\fB-t\fR \fItermlist\fR]
     [\fB-T\fR \fItaskidlist\fR] [\fB-c\fR \fIctidlist\fR] [\fB-z\fR \fIzoneidlist\fR]
     [\fIpattern\fR]
.fi

.LP
.nf
\fBpkill\fR [\fB-\fIsignal\fR\fR] [\fB-fvx\fR] [\fB-n\fR | \fB-o\fR] [\fB-P\fR \fIppidlist\fR]
     [\fB-g\fR \fIpgrplist\fR] [\fB-s\fR \fIsidlist\fR] [\fB-u\fR \fIeuidlist\fR] [\fB-U\fR \fIuidlist\fR]
     [\fB-G\fR \fIgidlist\fR] [\fB-J\fR \fIprojidlist\fR] [\fB-t\fR \fItermlist\fR]
     [\fB-T\fR \fItaskidlist\fR] [\fB-c\fR \fIctidlist\fR] [\fB-z\fR \fIzoneidlist\fR]
     [\fIpattern\fR]
.fi

.SH DESCRIPTION
.sp
.LP
The \fBpgrep\fR utility examines the active processes on the system and reports
the process \fBID\fRs of the processes whose attributes match the criteria
specified on the command line. Each process \fBID\fR is printed as a decimal
value and is separated from the next \fBID\fR by a delimiter string, which
defaults to a newline. For each attribute option, the user can specify a set of
possible values separated by commas on the command line. For example,
.sp
.in +2
.nf
\fBpgrep -G other,daemon\fR
.fi
.in -2
.sp

.sp
.LP
matches processes whose real group \fBID\fR is \fBother\fR \fBOR\fR
\fBdaemon\fR. If multiple criteria options are specified, \fBpgrep\fR matches
processes whose attributes match the logical \fBAND\fR of the criteria options.
For example,
.sp
.in +2
.nf
\fBpgrep -G other,daemon -U root,daemon\fR
.fi
.in -2
.sp

.sp
.LP
matches processes whose attributes are:
.br
.in +2
(real group \fBID\fR is \fBother\fR \fBOR\fR \fBdaemon\fR) \fBAND\fR
.in -2
.br
.in +2
(real user \fBID\fR is \fBroot\fR \fBOR\fR \fBdaemon\fR)
.in -2
.sp
.LP
\fBpkill\fR functions identically to \fBpgrep\fR, except that each matching
process is signaled as if by \fBkill\fR(1) instead of having its process
\fBID\fR printed. A signal name or number may be specified as the first command
line option to \fBpkill\fR.
.SH OPTIONS
.sp
.LP
The following options are supported:
.sp
.ne 2
.na
\fB\fB-c\fR \fIctidlist\fR\fR
.ad
.RS 17n
Matches only processes whose process contract ID is in the given list.
.RE

.sp
.ne 2
.na
\fB\fB-d\fR \fIdelim\fR\fR
.ad
.RS 17n
Specifies the output delimiter string to be printed between each matching
process \fBID\fR. If no \fB-d\fR option is specified, the default is a newline
character. The \fB-d\fR option is only valid when specified as an option to
\fBpgrep\fR.
.RE

.sp
.ne 2
.na
\fB\fB-f\fR\fR
.ad
.RS 17n
The regular expression \fIpattern\fR should be matched against the full process
argument string (obtained from the \fBpr_psargs\fR field of the
\fB/proc/\fInnnnn\fR/psinfo\fR file). If no \fB-f\fR option is specified, the
expression is matched only against the name of the executable file (obtained
from the \fBpr_fname\fR field of the \fB/proc/\fInnnnn\fR/psinfo\fR file).
.RE

.sp
.ne 2
.na
\fB\fB-g\fR \fIpgrplist\fR\fR
.ad
.RS 17n
Matches only processes whose process group \fBID\fR is in the given list. If
group 0 is included in the list, this is interpreted as the process group
\fBID\fR of the \fBpgrep\fR or \fBpkill\fR process.
.RE

.sp
.ne 2
.na
\fB\fB-G\fR \fIgidlist\fR\fR
.ad
.RS 17n
Matches only processes whose real group \fBID\fR is in the given list. Each
group \fBID\fR may be specified as either a group name or a numerical group
\fBID\fR.
.RE

.sp
.ne 2
.na
\fB\fB-J\fR \fIprojidlist\fR\fR
.ad
.RS 17n
Matches only processes whose project \fBID\fR is in the given list. Each
project \fBID\fR may be specified as either a project name or a numerical
project \fBID\fR.
.RE

.sp
.ne 2
.na
\fB\fB-l\fR\fR
.ad
.RS 17n
Long output format. Prints the process name along with the process \fBID\fR of
each matching process. The process name is obtained from the \fBpr_psargs\fR or
\fBpr_fname\fR field, depending on whether the \fB-f\fR option was specified
(see above). The \fB-l\fR option is only valid when specified as an option to
\fBpgrep\fR.
.RE

.sp
.ne 2
.na
\fB\fB-n\fR\fR
.ad
.RS 17n
Matches only the newest (most recently created) process that meets all other
specified matching criteria. Cannot be used with option \fB-o\fR.
.RE

.sp
.ne 2
.na
\fB\fB-o\fR\fR
.ad
.RS 17n
Matches only the oldest (earliest created) process that meets all other
specified matching criteria. Cannot be used with option \fB-n\fR.
.RE

.sp
.ne 2
.na
\fB\fB-P\fR \fIppidlist\fR\fR
.ad
.RS 17n
Matches only processes whose parent process \fBID\fR is in the given list.
.RE

.sp
.ne 2
.na
\fB\fB-s\fR \fIsidlist\fR\fR
.ad
.RS 17n
Matches only processes whose process session \fBID\fR is in in the given list.
If \fBID\fR 0 is included in the list, this is interpreted as the session
\fBID\fR of the \fBpgrep\fR or \fBpkill\fR process.
.RE

.sp
.ne 2
.na
\fB\fB-t\fR \fItermlist\fR\fR
.ad
.RS 17n
Matches only processes which are associated with a terminal in the given list.
Each terminal is specified as the suffix following "/dev/" of the terminal's
device path name in \fB/dev\fR. For example, \fBterm/a\fR or \fBpts/0\fR.
.RE

.sp
.ne 2
.na
\fB\fB-T\fR \fItaskidlist\fR\fR
.ad
.RS 17n
Matches only processes whose task \fBID\fR is in the given list. If \fBID\fR 0
is included in the list, this is interpreted as the task \fBID\fR of the
\fBpgrep\fR or \fBpkill\fR process.
.RE

.sp
.ne 2
.na
\fB\fB-u\fR \fIeuidlist\fR\fR
.ad
.RS 17n
Matches only processes whose effective user \fBID\fR is in the given list. Each
user \fBID\fR may be specified as either a login name or a numerical user
\fBID\fR.
.RE

.sp
.ne 2
.na
\fB\fB-U\fR \fIuidlist\fR\fR
.ad
.RS 17n
Matches only processes whose real user \fBID\fR is in the given list. Each user
\fBID\fR may be specified as either a login name or a numerical user \fBID\fR.
.RE

.sp
.ne 2
.na
\fB\fB-v\fR\fR
.ad
.RS 17n
Reverses the sense of the matching. Matches all processes \fBexcept\fR those
which meet the specified matching criteria.
.RE

.sp
.ne 2
.na
\fB\fB-x\fR\fR
.ad
.RS 17n
Matches only processes whose executable file name (ignoring any path)
\fBexactly\fR matches the specified \fIpattern\fR. However, when used with -f,
the \fIpattern\fR should be matched against the full process argument
string. For example if there exists a process `/bin/ls /home' then:
.sp
.in +2
.nf
$ pgrep -x ls
1780
$ pgrep -x -f '/bin/ls /home'
1780
$ pgrep -x -f '/bin/ls.*'
1780
$ pgrep -x /bin/ls
$ pgrep -x -f 'ls /home'
$ pgrep -x -f /bin/ls
$

.fi
.in -2
.sp

.RE

.sp
.ne 2
.na
\fB\fB-z\fR \fIzoneidlist\fR\fR
.ad
.RS 17n
Matches only processes whose zone \fBID\fR is in the given list. Each zone
\fBID\fR may be specified as either a zone name or a numerical zone \fBID\fR.
This option is only useful when executed in the global zone. If the \fBpkill\fR
utility is used to send signals to processes in  other zones, the process must
have asserted the \fB{PRIV_PROC_ZONE}\fR privilege (see \fBprivileges\fR(5)).
.RE

.sp
.ne 2
.na
\fB\fB-\fR\fIsignal\fR\fR
.ad
.RS 17n
Specifies the signal to send to each matched process. If no signal is
specified, \fBSIGTERM\fR is sent by default. The value of \fIsignal\fR can be
one of the symbolic names defined in \fBsignal.h\fR(3HEAD) without the
\fBSIG\fR prefix, or the corresponding signal number as a decimal value. The
\fB-\fR\fIsignal\fR option is only valid when specified as the first option to
\fBpkill\fR.
.RE

.SH OPERANDS
.sp
.LP
The following operand is supported:
.sp
.ne 2
.na
\fB\fIpattern\fR\fR
.ad
.RS 11n
Specifies an Extended Regular Expression (\fBERE\fR) pattern to match against
either the executable file name or full process argument string. See
\fBregex\fR(5) for a complete description of the \fBERE\fR syntax.
.RE

.SH EXAMPLES
.LP
\fBExample 1 \fRObtaining a Process ID
.sp
.LP
Obtain the process \fBID\fR of \fBsendmail\fR:

.sp
.in +2
.nf
example% \fBpgrep -x -u root sendmail\fR
283
.fi
.in -2
.sp

.LP
\fBExample 2 \fRTerminating a Process
.sp
.LP
Terminate the most recently created \fBxterm\fR:

.sp
.in +2
.nf
example% \fBpkill -n xterm\fR
.fi
.in -2
.sp

.SH EXIT STATUS
.sp
.LP
The following exit values are returned:
.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 5n
One or more processes were matched.
.RE

.sp
.ne 2
.na
\fB\fB1\fR\fR
.ad
.RS 5n
No processes were matched.
.RE

.sp
.ne 2
.na
\fB\fB2\fR\fR
.ad
.RS 5n
Invalid command line options were specified.
.RE

.sp
.ne 2
.na
\fB\fB3\fR\fR
.ad
.RS 5n
A fatal error occurred.
.RE

.SH FILES
.sp
.ne 2
.na
\fB\fB/proc/\fInnnnn\fR/psinfo\fR\fR
.ad
.RS 22n
Process information files
.RE

.SH SEE ALSO
.sp
.LP
\fBkill\fR(1), \fBproc\fR(1), \fBps\fR(1), \fBtruss\fR(1), \fBkill\fR(2),
\fBsignal.h\fR(3HEAD), \fBproc\fR(4), \fBattributes\fR(5), \fBprivileges\fR(5),
\fBregex\fR(5), \fBzones\fR(5)
.SH NOTES
.sp
.LP
Both utilities match the \fBERE\fR \fIpattern\fR argument against either the
\fBpr_fname\fR or \fBpr_psargs\fR fields of the
\fB/proc/\fR\fInnnnn\fR\fB/psinfo\fR files. The lengths of these strings are
limited according to definitions in \fB<sys/procfs.h>\fR\&. Patterns which can
match strings longer than the current limits may fail to match the intended set
of processes.
.sp
.LP
If the \fIpattern\fR argument contains \fBERE\fR meta-characters which are also
shell meta-characters, it may be necessary to enclose the pattern with
appropriate shell quotes.
.sp
.LP
Defunct processes are never matched by either \fBpgrep\fR or \fBpkill\fR.
.sp
.LP
The current \fBpgrep\fR or \fBpkill\fR process will never consider itself a
potential match.