1pgrep(1)                         User Commands                        pgrep(1)
2
3
4

NAME

6       pgrep, pkill - find or signal processes by name and other attributes
7

SYNOPSIS

9       pgrep [-flvx] [-n | -o] [-d delim] [-P ppidlist]
10            [-g pgrplist] [-s sidlist] [-u euidlist] [-U uidlist]
11            [-G gidlist] [-J projidlist] [-t termlist]
12            [-T taskidlist] [-c ctidlist] [-z zoneidlist]
13            [pattern]
14
15
16       pkill [-signal] [-fvx] [-n | -o] [-P ppidlist]
17            [-g pgrplist] [-s sidlist] [-u euidlist] [-U uidlist]
18            [-G gidlist] [-J projidlist] [-t termlist]
19            [-T taskidlist] [-c ctidlist] [-z zoneidlist]
20            [pattern]
21
22

DESCRIPTION

24       The  pgrep  utility  examines  the  active  processes on the system and
25       reports the process IDs of the processes  whose  attributes  match  the
26       criteria specified on the command line. Each process ID is printed as a
27       decimal value and is separated from the next ID by a delimiter  string,
28       which  defaults  to  a newline. For each attribute option, the user can
29       specify a set of possible values separated by  commas  on  the  command
30       line. For example,
31
32         pgrep -G other,daemon
33
34
35
36
37       matches  processes  whose real group ID is other OR daemon. If multiple
38       criteria  options  are  specified,  pgrep   matches   processes   whose
39       attributes match the logical AND of the criteria options. For example,
40
41         pgrep -G other,daemon -U root,daemon
42
43
44
45
46       matches processes whose attributes are:
47         (real group ID is other OR daemon) AND
48         (real user ID is root OR daemon)
49
50
51       pkill functions identically to pgrep, except that each matching process
52       is signaled as if by kill(1) instead of having its process ID  printed.
53       A  signal  name  or  number  may be specified as the first command line
54       option to pkill.
55

OPTIONS

57       The following options are supported:
58
59       -c ctidlist      Matches only processes whose process contract ID is in
60                        the given list.
61
62
63       -d delim         Specifies  the  output  delimiter string to be printed
64                        between each matching process ID. If no -d  option  is
65                        specified,  the default is a newline character. The -d
66                        option is only valid when specified as  an  option  to
67                        pgrep.
68
69
70       -f               The  regular  expression  pattern  should  be  matched
71                        against the full  process  argument  string  (obtained
72                        from  the  pr_psargs  field  of the /proc/nnnnn/psinfo
73                        file). If no -f option is specified, the expression is
74                        matched  only  against the name of the executable file
75                        (obtained   from   the   pr_fname   field    of    the
76                        /proc/nnnnn/psinfo file).
77
78
79       -g pgrplist      Matches  only  processes  whose process group ID is in
80                        the given list. If group 0 is included  in  the  list,
81                        this  is  interpreted  as  the process group ID of the
82                        pgrep or pkill process.
83
84
85       -G gidlist       Matches only processes whose real group ID is  in  the
86                        given list. Each group ID may be specified as either a
87                        group name or a numerical group ID.
88
89
90       -J projidlist    Matches only processes whose  project  ID  is  in  the
91                        given list. Each project ID may be specified as either
92                        a project name or a numerical project ID.
93
94
95       -l               Long output format. Prints the process name along with
96                        the  process  ID of each matching process. The process
97                        name is obtained from the pr_psargs or pr_fname field,
98                        depending  on whether the -f option was specified (see
99                        above). The -l option is only valid when specified  as
100                        an option to pgrep.
101
102
103       -n               Matches   only  the  newest  (most  recently  created)
104                        process that meets all other specified matching crite‐
105                        ria. Cannot be used with option -o.
106
107
108       -o               Matches  only  the  oldest  (earliest created) process
109                        that meets all other specified matching criteria. Can‐
110                        not be used with option -n.
111
112
113       -P ppidlist      Matches  only  processes whose parent process ID is in
114                        the given list.
115
116
117       -s sidlist       Matches only processes whose process session ID is  in
118                        in  the  given  list. If ID 0 is included in the list,
119                        this is interpreted as the session ID of the pgrep  or
120                        pkill process.
121
122
123       -t termlist      Matches  only  processes  which  are associated with a
124                        terminal in the given list. Each terminal is specified
125                        as  the  suffix  following  "/dev/"  of the terminal's
126                        device path name  in  /dev.  For  example,  term/a  or
127                        pts/0.
128
129
130       -T taskidlist    Matches  only  processes whose task ID is in the given
131                        list. If ID 0 is included in the list, this is  inter‐
132                        preted as the task ID of the pgrep or pkill process.
133
134
135       -u euidlist      Matches  only  processes whose effective user ID is in
136                        the given list. Each  user  ID  may  be  specified  as
137                        either a login name or a numerical user ID.
138
139
140       -U uidlist       Matches  only  processes  whose real user ID is in the
141                        given list. Each user ID may be specified as either  a
142                        login name or a numerical user ID.
143
144
145       -v               Reverses  the  sense of the matching. Matches all pro‐
146                        cesses except those which meet the specified  matching
147                        criteria.
148
149
150       -x               Considers only processes whose argument string or exe‐
151                        cutable file name exactly matches the  specified  pat‐
152                        tern  to  be  matching processes. The pattern match is
153                        considered to be exact  when  all  characters  in  the
154                        process  argument string or executable file name match
155                        the pattern.
156
157
158       -z zoneidlist    Matches only processes whose zone ID is in  the  given
159                        list.  Each  zone ID may be specified as either a zone
160                        name or a numerical zone ID. This option is only  use‐
161                        ful  when  executed  in  the global zone. If the pkill
162                        utility is used to send signals to processes in  other
163                        zones,    the   process   must   have   asserted   the
164                        {PRIV_PROC_ZONE} privilege (see privileges(5)).
165
166
167       -signal          Specifies the signal to send to each matched  process.
168                        If no signal is specified, SIGTERM is sent by default.
169                        The value of signal can be one of the  symbolic  names
170                        defined  in signal.h(3HEAD) without the SIG prefix, or
171                        the corresponding signal number as  a  decimal  value.
172                        The -signal option is only valid when specified as the
173                        first option to pkill.
174
175

OPERANDS

177       The following operand is supported:
178
179       pattern    Specifies an Extended Regular Expression  (ERE)  pattern  to
180                  match  against  either  the  executable  file  name  or full
181                  process  argument  string.  See  regex(5)  for  a   complete
182                  description of the ERE syntax.
183
184

EXAMPLES

186       Example 1 Obtaining a Process ID
187
188
189       Obtain the process ID of sendmail:
190
191
192         example% pgrep -x -u root sendmail
193         283
194
195
196
197       Example 2 Terminating a Process
198
199
200       Terminate the most recently created xterm:
201
202
203         example% pkill -n xterm
204
205
206

EXIT STATUS

208       The following exit values are returned:
209
210       0    One or more processes were matched.
211
212
213       1    No processes were matched.
214
215
216       2    Invalid command line options were specified.
217
218
219       3    A fatal error occurred.
220
221

FILES

223       /proc/nnnnn/psinfo    Process information files
224
225

ATTRIBUTES

227       See attributes(5) for descriptions of the following attributes:
228
229
230
231
232       ┌─────────────────────────────┬─────────────────────────────┐
233       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
234       ├─────────────────────────────┼─────────────────────────────┤
235       │Availability                 │SUNWcsu                      │
236       └─────────────────────────────┴─────────────────────────────┘
237

SEE ALSO

239       kill(1),  proc(1),  ps(1), truss(1), kill(2), signal.h(3HEAD), proc(4),
240       attributes(5), privileges(5), regex(5), zones(5)
241

NOTES

243       Both utilities match  the  ERE  pattern  argument  against  either  the
244       pr_fname  or  pr_psargs  fields  of  the  /proc/nnnnn/psinfo files. The
245       lengths of these  strings  are  limited  according  to  definitions  in
246       <sys/procfs.h>.  Patterns  which can match strings longer than the cur‐
247       rent limits may fail to match the intended set of processes.
248
249
250       If the pattern argument contains ERE  meta-characters  which  are  also
251       shell  meta-characters, it may be necessary to enclose the pattern with
252       appropriate shell quotes.
253
254
255       Defunct processes are never matched by either pgrep or pkill.
256
257
258       The current pgrep or pkill process will never consider itself a  poten‐
259       tial match.
260
261
262
263SunOS 5.11                        6 May 2004                          pgrep(1)
Impressum