Change GPL-2.0+/LGPL-2.0+ to GPL-2.0-or-later/LGPL-2.0-or-later
[platform/upstream/procps-ng.git] / pgrep.1
1 .\"
2 .\" Copyright 2000 Kjetil Torgrim Homme
3 .\"           2017-2020 Craig Small
4 .\"
5 .\" This program is free software; you can redistribute it and/or modify
6 .\" it under the terms of the GNU General Public License as published by
7 .\" the Free Software Foundation; either version 2 of the License, or
8 .\" (at your option) any later version.
9 .\"
10 .TH PGREP "1" "2020-06-04" "procps-ng" "User Commands"
11 .SH NAME
12 pgrep, pkill, pwait \- look up, signal, or wait for processes based on name and other attributes
13 .SH SYNOPSIS
14 .B pgrep
15 [options] pattern
16 .br
17 .B pkill
18 [options] pattern
19 .br
20 .B pwait
21 [options] pattern
22 .SH DESCRIPTION
23 .B pgrep
24 looks through the currently running processes and lists the process IDs which
25 match the selection criteria to stdout.  All the criteria have to match.
26 For example,
27 .IP
28 $ pgrep \-u root sshd
29 .PP
30 will only list the processes called
31 .B sshd
32 AND owned by
33 .BR root .
34 On the other hand,
35 .IP
36 $ pgrep \-u root,daemon
37 .PP
38 will list the processes owned by
39 .B root
40 OR
41 .BR daemon .
42 .PP
43 .B pkill
44 will send the specified signal (by default
45 .BR SIGTERM )
46 to each process instead of listing them on stdout.
47 .PP
48 .B pwait
49 will wait for each process instead of listing them on stdout.
50 .SH OPTIONS
51 .TP
52 \fB\-\fR\fIsignal\fP
53 .TQ
54 \fB\-\-signal\fR \fIsignal\fR
55 Defines the signal to send to each matched process.  Either the numeric or
56 the symbolic signal name can be used.
57 .RB ( pkill
58 only.)
59 .TP
60 \fB\-c\fR, \fB\-\-count\fR
61 Suppress normal output; instead print a count of matching processes.  When
62 count does not match anything, e.g. returns zero, the command will return
63 non-zero value. Note that for pkill and pwait, the count is the number of
64 matching processes, not the processes that were successfully signaled or waited
65 for.
66 .TP
67 \fB\-d\fR, \fB\-\-delimiter\fR \fIdelimiter\fP
68 Sets the string used to delimit each process ID in the output (by default a
69 newline).
70 .RB ( pgrep
71 only.)
72 .TP
73 \fB\-e\fR, \fB\-\-echo\fR
74 Display name and PID of the process being killed.
75 .RB ( pkill
76 only.)
77 .TP
78 \fB\-f\fR, \fB\-\-full\fR
79 The
80 .I pattern
81 is normally only matched against the process name.  When
82 .B \-f
83 is set, the full command line is used.
84 .TP
85 \fB\-g\fR, \fB\-\-pgroup\fR \fIpgrp\fP,...
86 Only match processes in the process group IDs listed.  Process group 0 is
87 translated into
88 .BR pgrep 's,
89 .BR pkill 's,
90 or
91 .BR pwait 's
92 own process group.
93 .TP
94 \fB\-G\fR, \fB\-\-group\fR \fIgid\fP,...
95 Only match processes whose real group ID is listed.  Either the numerical or
96 symbolical value may be used.
97 .TP
98 \fB\-i\fR, \fB\-\-ignore\-case\fR
99 Match processes case-insensitively.
100 .TP
101 \fB\-l\fR, \fB\-\-list\-name\fR
102 List the process name as well as the process ID.
103 .RB ( pgrep
104 only.)
105 .TP
106 \fB\-a\fR, \fB\-\-list\-full\fR
107 List the full command line as well as the process ID.
108 .RB ( pgrep
109 only.)
110 .TP
111 \fB\-n\fR, \fB\-\-newest\fR
112 Select only the newest (most recently started) of the matching processes.
113 .TP
114 \fB\-o\fR, \fB\-\-oldest\fR
115 Select only the oldest (least recently started) of the matching processes.
116 .TP
117 \fB\-O\fR, \fB\-\-older\fR \fIsecs\fP
118 Select processes older than secs.
119 .TP
120 \fB\-P\fR, \fB\-\-parent\fR \fIppid\fP,...
121 Only match processes whose parent process ID is listed.
122 .TP
123 \fB\-s\fR, \fB\-\-session\fR \fIsid\fP,...
124 Only match processes whose process session ID is listed.  Session ID 0
125 is translated into
126 .BR pgrep 's,
127 .BR pkill 's,
128 or
129 .BR pwait 's
130 own session ID.
131 .TP
132 \fB\-t\fR, \fB\-\-terminal\fR \fIterm\fP,...
133 Only match processes whose controlling terminal is listed.  The terminal name
134 should be specified without the "/dev/" prefix.
135 .TP
136 \fB\-u\fR, \fB\-\-euid\fR \fIeuid\fP,...
137 Only match processes whose effective user ID is listed.  Either the numerical
138 or symbolical value may be used.
139 .TP
140 \fB\-U\fR, \fB\-\-uid\fR \fIuid\fP,...
141 Only match processes whose real user ID is listed.  Either the numerical or
142 symbolical value may be used.
143 .TP
144 \fB\-v\fR, \fB\-\-inverse\fR\fR
145 Negates the matching.  This option is usually used in
146 .BR pgrep 's
147 or
148 .BR pwait 's
149 context.  In
150 .BR pkill 's
151 context the short option is disabled to avoid accidental usage of the option.
152 .TP
153 \fB\-w\fR, \fB\-\-lightweight\fR\fR
154 Shows all thread ids instead of pids in
155 .BR pgrep 's
156 or
157 .BR pwait 's
158 context.  In
159 .BR pkill 's
160 context this option is disabled.
161 .TP
162 \fB\-x\fR, \fB\-\-exact\fR\fR
163 Only match processes whose names (or command lines if \fB\-f\fR is specified)
164 .B exactly
165 match the
166 .IR pattern .
167 .TP
168 \fB\-F\fR, \fB\-\-pidfile\fR \fIfile\fR
169 Read \fIPID\fRs from \fIfile\fR.  This option is more useful for
170 .BR pkill or pwait
171 than
172 .BR pgrep .
173 .TP
174 \fB\-L\fR, \fB\-\-logpidfile\fR
175 Fail if pidfile (see \fB\-F\fR) not locked.
176 .TP
177 \fB\-r\fR, \fB\-\-runstates\fR \fID,R,S,Z,\fP...
178 Match only processes which match the process state.
179 .TP
180 \fB\-\-ns \fIpid\fP
181 Match processes that belong to the same namespaces. Required to run as
182 root to match processes from other users. See \fB\-\-nslist\fR for how to
183 limit which namespaces to match.
184 .TP
185 \fB\-\-nslist \fIname\fP,...
186 Match only the provided namespaces. Available namespaces:
187 ipc, mnt, net, pid, user,uts.
188 .TP
189 \fB\-q\fR, \fB\-\-queue \fIvalue\fP
190 Use
191 .BR sigqueue(3)
192 rather than
193 .BR kill(2)
194 and the value argument is used to specify
195 an integer to be sent with the signal. If the receiving process has
196 installed a handler for this signal using the SA_SIGINFO flag to
197 .BR sigaction(2)
198 , then it can obtain this data via the si_value field of the
199 siginfo_t structure.
200 .TP
201 \fB\-V\fR, \fB\-\-version\fR
202 Display version information and exit.
203 .TP
204 \fB\-h\fR, \fB\-\-help\fR
205 Display help and exit.
206 .PD
207 .SH OPERANDS
208 .TP
209 .I pattern
210 Specifies an Extended Regular Expression for matching against the process
211 names or command lines.
212 .SH EXAMPLES
213 Example 1: Find the process ID of the
214 .B named
215 daemon:
216 .IP
217 $ pgrep \-u root named
218 .PP
219 Example 2: Make
220 .B syslog
221 reread its configuration file:
222 .IP
223 $ pkill \-HUP syslogd
224 .PP
225 Example 3: Give detailed information on all
226 .B xterm
227 processes:
228 .IP
229 $ ps \-fp $(pgrep \-d, \-x xterm)
230 .PP
231 Example 4: Make all
232 .B chrome
233 processes run nicer:
234 .IP
235 $ renice +4 $(pgrep chrome)
236 .SH "EXIT STATUS"
237 .PD 0
238 .TP
239 0
240 One or more processes matched the criteria. For pkill and pwait, one or more
241 processes must also have been successfully signalled or waited for.
242 .TP
243 1
244 No processes matched or none of them could be signalled.
245 .TP
246 2
247 Syntax error in the command line.
248 .TP
249 3
250 Fatal error: out of memory etc.
251 .PD
252 .SH NOTES
253 The process name used for matching is limited to the 15 characters present in
254 the output of /proc/\fIpid\fP/stat.  Use the \fB\-f\fR option to match against the
255 complete command line, /proc/\fIpid\fP/cmdline.
256 .PP
257 The running
258 .BR pgrep ,
259 .BR pkill ,
260 or
261 .B pwait
262 process will never report itself as a
263 match.
264 .SH BUGS
265 The options
266 .B \-n
267 and
268 .B \-o
269 and
270 .B \-v
271 can not be combined.  Let
272 me know if you need to do this.
273 .PP
274 Defunct processes are reported.
275
276 .SH "SEE ALSO"
277 .BR ps (1),
278 .BR regex (7),
279 .BR signal (7),
280 .BR sigqueue (3),
281 .BR killall (1),
282 .BR skill (1),
283 .BR kill (1),
284 .BR kill (2)
285 .SH AUTHOR
286 .UR kjetilho@ifi.uio.no
287 Kjetil Torgrim Homme
288 .UE
289 .SH "REPORTING BUGS"
290 Please send bug reports to
291 .UR procps@freelists.org
292 .UE