'\" 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 "6 May 2004" "SunOS 5.11" "User Commands" .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 .mk .na \fB\fB-c\fR \fIctidlist\fR\fR .ad .RS 17n .rt Matches only processes whose process contract ID is in the given list. .RE .sp .ne 2 .mk .na \fB\fB-d\fR \fIdelim\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-f\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-g\fR \fIpgrplist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-G\fR \fIgidlist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-J\fR \fIprojidlist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-l\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-n\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-o\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-P\fR \fIppidlist\fR\fR .ad .RS 17n .rt Matches only processes whose parent process \fBID\fR is in the given list. .RE .sp .ne 2 .mk .na \fB\fB-s\fR \fIsidlist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-t\fR \fItermlist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-T\fR \fItaskidlist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-u\fR \fIeuidlist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-U\fR \fIuidlist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-v\fR\fR .ad .RS 17n .rt Reverses the sense of the matching. Matches all processes \fBexcept\fR those which meet the specified matching criteria. .RE .sp .ne 2 .mk .na \fB\fB-x\fR\fR .ad .RS 17n .rt Considers only processes whose argument string or executable file name \fBexactly\fR matches the specified \fIpattern\fR to be matching processes. The pattern match is considered to be exact when all characters in the process argument string or executable file name match the pattern. .RE .sp .ne 2 .mk .na \fB\fB-z\fR \fIzoneidlist\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fB-\fR\fIsignal\fR\fR .ad .RS 17n .rt 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 .mk .na \fB\fIpattern\fR\fR .ad .RS 11n .rt 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 .mk .na \fB\fB0\fR\fR .ad .RS 5n .rt One or more processes were matched. .RE .sp .ne 2 .mk .na \fB\fB1\fR\fR .ad .RS 5n .rt No processes were matched. .RE .sp .ne 2 .mk .na \fB\fB2\fR\fR .ad .RS 5n .rt Invalid command line options were specified. .RE .sp .ne 2 .mk .na \fB\fB3\fR\fR .ad .RS 5n .rt A fatal error occurred. .RE .SH FILES .sp .ne 2 .mk .na \fB\fB/proc/\fInnnnn\fR/psinfo\fR\fR .ad .RS 22n .rt 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\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.