2 .\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH PGREP 1 "Jan 17, 2014"
8 pgrep, pkill \- find or signal processes by name and other attributes
12 \fBpgrep\fR [\fB-flvx\fR] [\fB-n\fR | \fB-o\fR] [\fB-d\fR \fIdelim\fR] [\fB-P\fR \fIppidlist\fR]
13 [\fB-g\fR \fIpgrplist\fR] [\fB-s\fR \fIsidlist\fR] [\fB-u\fR \fIeuidlist\fR] [\fB-U\fR \fIuidlist\fR]
14 [\fB-G\fR \fIgidlist\fR] [\fB-J\fR \fIprojidlist\fR] [\fB-t\fR \fItermlist\fR]
15 [\fB-T\fR \fItaskidlist\fR] [\fB-c\fR \fIctidlist\fR] [\fB-z\fR \fIzoneidlist\fR]
21 \fBpkill\fR [\fB-\fIsignal\fR\fR] [\fB-fvx\fR] [\fB-n\fR | \fB-o\fR] [\fB-P\fR \fIppidlist\fR]
22 [\fB-g\fR \fIpgrplist\fR] [\fB-s\fR \fIsidlist\fR] [\fB-u\fR \fIeuidlist\fR] [\fB-U\fR \fIuidlist\fR]
23 [\fB-G\fR \fIgidlist\fR] [\fB-J\fR \fIprojidlist\fR] [\fB-t\fR \fItermlist\fR]
24 [\fB-T\fR \fItaskidlist\fR] [\fB-c\fR \fIctidlist\fR] [\fB-z\fR \fIzoneidlist\fR]
31 The \fBpgrep\fR utility examines the active processes on the system and reports
32 the process \fBID\fRs of the processes whose attributes match the criteria
33 specified on the command line. Each process \fBID\fR is printed as a decimal
34 value and is separated from the next \fBID\fR by a delimiter string, which
35 defaults to a newline. For each attribute option, the user can specify a set of
36 possible values separated by commas on the command line. For example,
40 \fBpgrep -G other,daemon\fR
47 matches processes whose real group \fBID\fR is \fBother\fR \fBOR\fR
48 \fBdaemon\fR. If multiple criteria options are specified, \fBpgrep\fR matches
49 processes whose attributes match the logical \fBAND\fR of the criteria options.
54 \fBpgrep -G other,daemon -U root,daemon\fR
61 matches processes whose attributes are:
64 (real group \fBID\fR is \fBother\fR \fBOR\fR \fBdaemon\fR) \fBAND\fR
68 (real user \fBID\fR is \fBroot\fR \fBOR\fR \fBdaemon\fR)
72 \fBpkill\fR functions identically to \fBpgrep\fR, except that each matching
73 process is signaled as if by \fBkill\fR(1) instead of having its process
74 \fBID\fR printed. A signal name or number may be specified as the first command
75 line option to \fBpkill\fR.
79 The following options are supported:
83 \fB\fB-c\fR \fIctidlist\fR\fR
86 Matches only processes whose process contract ID is in the given list.
92 \fB\fB-d\fR \fIdelim\fR\fR
95 Specifies the output delimiter string to be printed between each matching
96 process \fBID\fR. If no \fB-d\fR option is specified, the default is a newline
97 character. The \fB-d\fR option is only valid when specified as an option to
107 The regular expression \fIpattern\fR should be matched against the full process
108 argument string (obtained from the \fBpr_psargs\fR field of the
109 \fB/proc/\fInnnnn\fR/psinfo\fR file). If no \fB-f\fR option is specified, the
110 expression is matched only against the name of the executable file (obtained
111 from the \fBpr_fname\fR field of the \fB/proc/\fInnnnn\fR/psinfo\fR file).
117 \fB\fB-g\fR \fIpgrplist\fR\fR
120 Matches only processes whose process group \fBID\fR is in the given list. If
121 group 0 is included in the list, this is interpreted as the process group
122 \fBID\fR of the \fBpgrep\fR or \fBpkill\fR process.
128 \fB\fB-G\fR \fIgidlist\fR\fR
131 Matches only processes whose real group \fBID\fR is in the given list. Each
132 group \fBID\fR may be specified as either a group name or a numerical group
139 \fB\fB-J\fR \fIprojidlist\fR\fR
142 Matches only processes whose project \fBID\fR is in the given list. Each
143 project \fBID\fR may be specified as either a project name or a numerical
153 Long output format. Prints the process name along with the process \fBID\fR of
154 each matching process. The process name is obtained from the \fBpr_psargs\fR or
155 \fBpr_fname\fR field, depending on whether the \fB-f\fR option was specified
156 (see above). The \fB-l\fR option is only valid when specified as an option to
166 Matches only the newest (most recently created) process that meets all other
167 specified matching criteria. Cannot be used with option \fB-o\fR.
176 Matches only the oldest (earliest created) process that meets all other
177 specified matching criteria. Cannot be used with option \fB-n\fR.
183 \fB\fB-P\fR \fIppidlist\fR\fR
186 Matches only processes whose parent process \fBID\fR is in the given list.
192 \fB\fB-s\fR \fIsidlist\fR\fR
195 Matches only processes whose process session \fBID\fR is in in the given list.
196 If \fBID\fR 0 is included in the list, this is interpreted as the session
197 \fBID\fR of the \fBpgrep\fR or \fBpkill\fR process.
203 \fB\fB-t\fR \fItermlist\fR\fR
206 Matches only processes which are associated with a terminal in the given list.
207 Each terminal is specified as the suffix following "/dev/" of the terminal's
208 device path name in \fB/dev\fR. For example, \fBterm/a\fR or \fBpts/0\fR.
214 \fB\fB-T\fR \fItaskidlist\fR\fR
217 Matches only processes whose task \fBID\fR is in the given list. If \fBID\fR 0
218 is included in the list, this is interpreted as the task \fBID\fR of the
219 \fBpgrep\fR or \fBpkill\fR process.
225 \fB\fB-u\fR \fIeuidlist\fR\fR
228 Matches only processes whose effective user \fBID\fR is in the given list. Each
229 user \fBID\fR may be specified as either a login name or a numerical user
236 \fB\fB-U\fR \fIuidlist\fR\fR
239 Matches only processes whose real user \fBID\fR is in the given list. Each user
240 \fBID\fR may be specified as either a login name or a numerical user \fBID\fR.
249 Reverses the sense of the matching. Matches all processes \fBexcept\fR those
250 which meet the specified matching criteria.
259 Matches only processes whose executable file name (ignoring any path)
260 \fBexactly\fR matches the specified \fIpattern\fR. However, when used with -f,
261 the \fIpattern\fR should be matched against the full process argument
262 string. For example if there exists a process `/bin/ls /home' then:
268 $ pgrep -x -f '/bin/ls /home'
270 $ pgrep -x -f '/bin/ls.*'
273 $ pgrep -x -f 'ls /home'
274 $ pgrep -x -f /bin/ls
286 \fB\fB-z\fR \fIzoneidlist\fR\fR
289 Matches only processes whose zone \fBID\fR is in the given list. Each zone
290 \fBID\fR may be specified as either a zone name or a numerical zone \fBID\fR.
291 This option is only useful when executed in the global zone. If the \fBpkill\fR
292 utility is used to send signals to processes in other zones, the process must
293 have asserted the \fB{PRIV_PROC_ZONE}\fR privilege (see \fBprivileges\fR(5)).
299 \fB\fB-\fR\fIsignal\fR\fR
302 Specifies the signal to send to each matched process. If no signal is
303 specified, \fBSIGTERM\fR is sent by default. The value of \fIsignal\fR can be
304 one of the symbolic names defined in \fBsignal.h\fR(3HEAD) without the
305 \fBSIG\fR prefix, or the corresponding signal number as a decimal value. The
306 \fB-\fR\fIsignal\fR option is only valid when specified as the first option to
313 The following operand is supported:
320 Specifies an Extended Regular Expression (\fBERE\fR) pattern to match against
321 either the executable file name or full process argument string. See
322 \fBregex\fR(5) for a complete description of the \fBERE\fR syntax.
327 \fBExample 1 \fRObtaining a Process ID
330 Obtain the process \fBID\fR of \fBsendmail\fR:
335 example% \fBpgrep -x -u root sendmail\fR
342 \fBExample 2 \fRTerminating a Process
345 Terminate the most recently created \fBxterm\fR:
350 example% \fBpkill -n xterm\fR
358 The following exit values are returned:
365 One or more processes were matched.
374 No processes were matched.
383 Invalid command line options were specified.
392 A fatal error occurred.
399 \fB\fB/proc/\fInnnnn\fR/psinfo\fR\fR
402 Process information files
408 \fBkill\fR(1), \fBproc\fR(1), \fBps\fR(1), \fBtruss\fR(1), \fBkill\fR(2),
409 \fBsignal.h\fR(3HEAD), \fBproc\fR(4), \fBattributes\fR(5), \fBprivileges\fR(5),
410 \fBregex\fR(5), \fBzones\fR(5)
414 Both utilities match the \fBERE\fR \fIpattern\fR argument against either the
415 \fBpr_fname\fR or \fBpr_psargs\fR fields of the
416 \fB/proc/\fR\fInnnnn\fR\fB/psinfo\fR files. The lengths of these strings are
417 limited according to definitions in \fB<sys/procfs.h>\fR\&. Patterns which can
418 match strings longer than the current limits may fail to match the intended set
422 If the \fIpattern\fR argument contains \fBERE\fR meta-characters which are also
423 shell meta-characters, it may be necessary to enclose the pattern with
424 appropriate shell quotes.
427 Defunct processes are never matched by either \fBpgrep\fR or \fBpkill\fR.
430 The current \fBpgrep\fR or \fBpkill\fR process will never consider itself a