| 1 |
.\" |
| 2 |
.\" Copyright (c) 2004-2025 Craig Small <[email protected]> |
| 3 |
.\" Copyright (c) 2013-2024 Jim Warner <[email protected]> |
| 4 |
.\" Copyright (c) 2011-2012 Sami Kerola <[email protected]> |
| 5 |
.\" Copyright (c) 2002-2004 Albert Cahalan |
| 6 |
.\" Copyright (c) 2000 Kjetil Torgrim Homme |
| 7 |
.\" |
| 8 |
.\" This program is free software; you can redistribute it and/or modify |
| 9 |
.\" it under the terms of the GNU General Public License as published by |
| 10 |
.\" the Free Software Foundation; either version 2 of the License, or |
| 11 |
.\" (at your option) any later version. |
| 12 |
.\" |
| 13 |
.TH PGREP 1 2025-12-29 procps-ng |
| 14 |
.SH NAME |
| 15 |
pgrep, pkill, pidwait \- look up, signal, or wait for processes based on name and other attributes |
| 16 |
.SH SYNOPSIS |
| 17 |
.B pgrep |
| 18 |
.RI [ option " .\|.\|.\&]" |
| 19 |
.I pattern |
| 20 |
.P |
| 21 |
.B pkill |
| 22 |
.RI [ option " .\|.\|.\&]" |
| 23 |
.I pattern |
| 24 |
.P |
| 25 |
.B pidwait |
| 26 |
.RI [ option " .\|.\|.\&]" |
| 27 |
.I pattern |
| 28 |
.SH DESCRIPTION |
| 29 |
.B pgrep |
| 30 |
looks through the currently running processes and lists the process IDs which |
| 31 |
match the selection criteria to stdout. All the criteria have to match. |
| 32 |
For example, |
| 33 |
.IP |
| 34 |
$ pgrep \-u root sshd |
| 35 |
.PP |
| 36 |
will only list the processes whose name include |
| 37 |
.B sshd |
| 38 |
AND owned by |
| 39 |
.BR root . |
| 40 |
On the other hand, |
| 41 |
.IP |
| 42 |
$ pgrep \-u root,daemon |
| 43 |
.PP |
| 44 |
will list the processes owned by |
| 45 |
.B root |
| 46 |
OR |
| 47 |
.BR daemon . |
| 48 |
.PP |
| 49 |
.B pkill |
| 50 |
will send the specified signal (by default |
| 51 |
.BR SIGTERM ) |
| 52 |
to each process instead of listing them on stdout. |
| 53 |
.PP |
| 54 |
.B pidwait |
| 55 |
will wait for each process instead of listing them on stdout. |
| 56 |
.SH OPTIONS |
| 57 |
.TP |
| 58 |
\fB\-\fR\fIsignal\fP |
| 59 |
.TQ |
| 60 |
\fB\-\-signal\fR \fIsignal\fR |
| 61 |
Defines the signal to send to each matched process. Either the numeric or |
| 62 |
the symbolic signal name can be used. In |
| 63 |
.B pgrep |
| 64 |
or |
| 65 |
.B pidwait |
| 66 |
mode only the long option can be used and has no effect unless used in conjunction with |
| 67 |
\fB\-\-require\-handler\fR to filter to processes with a userspace signal |
| 68 |
handler present for a particular signal. |
| 69 |
.TP |
| 70 |
\fB\-a\fR, \fB\-\-list\-full\fR |
| 71 |
List the full command line as well as the process ID. |
| 72 |
.RB ( pgrep |
| 73 |
only.) |
| 74 |
.TP |
| 75 |
\fB\-A\fR, \fB\-\-ignore-ancestors\fR\fR |
| 76 |
Ignore all ancestors of |
| 77 |
.BR pgrep , |
| 78 |
.BR pkill , |
| 79 |
or |
| 80 |
.BR pidwait . |
| 81 |
For example, this can be useful when elevating with |
| 82 |
.B sudo |
| 83 |
or similar tools. |
| 84 |
.TP |
| 85 |
\fB\-c\fR, \fB\-\-count\fR |
| 86 |
Suppress normal output; instead print a count of matching processes. When |
| 87 |
count does not match anything, e.g. returns zero, the command will return |
| 88 |
non-zero value. Note that for pkill and pidwait, the count is the number of |
| 89 |
matching processes, not the processes that were successfully signaled or waited |
| 90 |
for. |
| 91 |
.TP |
| 92 |
\fB\-d\fR, \fB\-\-delimiter\fR \fIdelimiter\fP |
| 93 |
Sets the string used to delimit each process ID in the output (by default a |
| 94 |
newline). |
| 95 |
.RB ( pgrep |
| 96 |
only.) |
| 97 |
.TP |
| 98 |
\fB\-e\fR, \fB\-\-echo\fR |
| 99 |
Display name and PID of the process being killed. |
| 100 |
.RB ( pkill |
| 101 |
only.) |
| 102 |
.TP |
| 103 |
\fB\-f\fR, \fB\-\-full\fR |
| 104 |
The |
| 105 |
.I pattern |
| 106 |
is normally only matched against the process name. When |
| 107 |
.B \-f |
| 108 |
is set, the full command line is used. |
| 109 |
.TP |
| 110 |
\fB\-F\fR, \fB\-\-pidfile\fR \fIfile\fR |
| 111 |
Read \fIPID\fRs from \fIfile\fR. This option is more useful for |
| 112 |
.B pkill |
| 113 |
or |
| 114 |
.B pidwait |
| 115 |
than |
| 116 |
.BR pgrep . |
| 117 |
The filename "\-" can be used to read from \fISTDIN\fR. |
| 118 |
Conflicts with the \fB\-\-pid\fR option. |
| 119 |
.TP |
| 120 |
\fB\-g\fR, \fB\-\-pgroup\fR \fIpgrp\fP,.\|.\|. |
| 121 |
Only match processes in the process group IDs listed. Process group 0 is |
| 122 |
translated into |
| 123 |
.BR pgrep 's, |
| 124 |
.BR pkill 's, |
| 125 |
or |
| 126 |
.BR pidwait 's |
| 127 |
own process group. |
| 128 |
.TP |
| 129 |
\fB\-G\fR, \fB\-\-group\fR \fIgid\fP,.\|.\|. |
| 130 |
Only match processes whose real group ID is listed. Either the numerical or |
| 131 |
symbolical value may be used. |
| 132 |
.TP |
| 133 |
\fB\-H\fR, \fB\-\-require\-handler\fR\fR |
| 134 |
Only match processes with a userspace signal handler present for the signal to |
| 135 |
be sent. |
| 136 |
.TP |
| 137 |
\fB\-i\fR, \fB\-\-ignore\-case\fR |
| 138 |
Match processes case-insensitively. |
| 139 |
.TP |
| 140 |
\fB\-l\fR, \fB\-\-list\-name\fR |
| 141 |
List the process name as well as the process ID. |
| 142 |
.RB ( pgrep |
| 143 |
only.) |
| 144 |
.TP |
| 145 |
\fB\-L\fR, \fB\-\-logpidfile\fR |
| 146 |
Fail if pidfile (see \fB\-F\fR) not locked. |
| 147 |
.TP |
| 148 |
\fB\-m\fR, \fB\-\-mrelease\fR |
| 149 |
After sending the signal, invoke the |
| 150 |
.BR process_mrelease () |
| 151 |
system call to immediately free the target process's memory. |
| 152 |
.TP |
| 153 |
\fB\-n\fR, \fB\-\-newest\fR |
| 154 |
Select only the newest (most recently started) of the matching processes. |
| 155 |
.TP |
| 156 |
\fB\-o\fR, \fB\-\-oldest\fR |
| 157 |
Select only the oldest (least recently started) of the matching processes. |
| 158 |
.TP |
| 159 |
\fB\-O\fR, \fB\-\-older\fR \fIsecs\fP |
| 160 |
Select processes older than secs. |
| 161 |
.TP |
| 162 |
\fB\-p\fR, \fB\-\-pid\fR \fIpid\fP,.\|.\|. |
| 163 |
Only match processes whose process ID is listed. Conflicts with the |
| 164 |
\fB\-\-pidfile\fR option. |
| 165 |
.TP |
| 166 |
\fB\-P\fR, \fB\-\-parent\fR \fIppid\fP,.\|.\|. |
| 167 |
Only match processes whose parent process ID is listed. |
| 168 |
.TP |
| 169 |
\fB\-q\fR, \fB\-\-queue \fIvalue\fP |
| 170 |
Send the integer \fIvalue\fR along with the signal. This option will either |
| 171 |
use |
| 172 |
.BR pidfd_send_signal (2) |
| 173 |
with a value applied or |
| 174 |
.BR sigqueue (3) |
| 175 |
rather than |
| 176 |
.BR kill (2). |
| 177 |
If the receiving process has |
| 178 |
installed a handler for this signal using the SA_SIGINFO flag to |
| 179 |
.BR sigaction (2), |
| 180 |
then it can obtain this data via the si_value field of the |
| 181 |
siginfo_t structure. |
| 182 |
.TP |
| 183 |
\fB\-Q\fR, \fB\-\-shell\-quote\fR\fR |
| 184 |
Output the command line in shell-quoted form. |
| 185 |
.RB ( pgrep |
| 186 |
only.) |
| 187 |
.TP |
| 188 |
\fB\-r\fR, \fB\-\-runstates\fR \fID,R,S,Z,\fP.\|.\|. |
| 189 |
Match only processes which match the process state. |
| 190 |
.TP |
| 191 |
\fB\-s\fR, \fB\-\-session\fR \fIsid\fP,.\|.\|. |
| 192 |
Only match processes whose process session ID is listed. Session ID 0 |
| 193 |
is translated into |
| 194 |
.BR pgrep 's, |
| 195 |
.BR pkill 's, |
| 196 |
or |
| 197 |
.BR pidwait 's |
| 198 |
own session ID. |
| 199 |
.TP |
| 200 |
\fB\-t\fR, \fB\-\-terminal\fR \fIterm\fP,.\|.\|. |
| 201 |
Only match processes whose controlling terminal is listed. The terminal name |
| 202 |
should be specified without the "/dev/" prefix. |
| 203 |
.TP |
| 204 |
\fB\-u\fR, \fB\-\-euid\fR \fIeuid\fP,.\|.\|. |
| 205 |
Only match processes whose effective user ID is listed. Either the numerical |
| 206 |
or symbolical value may be used. |
| 207 |
.TP |
| 208 |
\fB\-U\fR, \fB\-\-uid\fR \fIuid\fP,.\|.\|. |
| 209 |
Only match processes whose real user ID is listed. Either the numerical or |
| 210 |
symbolical value may be used. |
| 211 |
.TP |
| 212 |
\fB\-v\fR, \fB\-\-inverse\fR\fR |
| 213 |
Negates the matching. This option is usually used in |
| 214 |
.BR pgrep 's |
| 215 |
or |
| 216 |
.BR pidwait 's |
| 217 |
context. In |
| 218 |
.BR pkill 's |
| 219 |
context the short option is disabled to avoid accidental usage of the option. |
| 220 |
.TP |
| 221 |
\fB\-w\fR, \fB\-\-lightweight\fR\fR |
| 222 |
Shows all thread ids instead of pids in |
| 223 |
.BR pgrep 's |
| 224 |
or |
| 225 |
.BR pidwait 's |
| 226 |
context. In |
| 227 |
.BR pkill 's |
| 228 |
context this option is disabled. |
| 229 |
.TP |
| 230 |
\fB\-x\fR, \fB\-\-exact\fR\fR |
| 231 |
Only match processes whose names (or command lines if \fB\-f\fR is specified) |
| 232 |
.B exactly |
| 233 |
match the |
| 234 |
.IR pattern . |
| 235 |
.TP |
| 236 |
\fB\-\-cgroup \fIname\fP,.\|.\|. |
| 237 |
Match on provided control group (cgroup) v2 name. See |
| 238 |
.BR cgroups (7) |
| 239 |
.TP |
| 240 |
\fB\-\-env \fIname\fR[\fI=value\fR],.\|.\|. |
| 241 |
Match on process that have these environment variables. If the \fI=value\fR |
| 242 |
parameter is not defined then only the variable name is matched. |
| 243 |
.TP |
| 244 |
\fB\-\-ns \fIpid\fP |
| 245 |
Match processes that belong to the same namespaces. Required to run as |
| 246 |
root to match processes from other users. See \fB\-\-nslist\fR for how to |
| 247 |
limit which namespaces to match. |
| 248 |
.TP |
| 249 |
\fB\-\-nslist \fIname\fP,.\|.\|. |
| 250 |
Match only the provided namespaces. Available namespaces: |
| 251 |
ipc, mnt, net, pid, user, uts. |
| 252 |
.TP |
| 253 |
\fB\-\-quiet\fR |
| 254 |
Do not write anything to standard output (\fBpgrep\fR only). |
| 255 |
.TP |
| 256 |
\fB\-V\fR, \fB\-\-version\fR |
| 257 |
Display version information and exit. |
| 258 |
.TP |
| 259 |
\fB\-h\fR, \fB\-\-help\fR |
| 260 |
Display help and exit. |
| 261 |
.SH OPERANDS |
| 262 |
.TP |
| 263 |
.I pattern |
| 264 |
Specifies an Extended Regular Expression for matching against the process |
| 265 |
names or command lines. |
| 266 |
.SH EXAMPLES |
| 267 |
Example 1: Find the process ID of the |
| 268 |
.B named |
| 269 |
daemon: |
| 270 |
.IP |
| 271 |
$ pgrep \-u root named |
| 272 |
.PP |
| 273 |
Example 2: Make |
| 274 |
.B syslog |
| 275 |
reread its configuration file: |
| 276 |
.IP |
| 277 |
$ pkill \-HUP syslogd |
| 278 |
.PP |
| 279 |
Example 3: Give detailed information on all |
| 280 |
.B bash |
| 281 |
processes: |
| 282 |
.IP |
| 283 |
$ ps \-fp $(pgrep \-d, \-x bash) |
| 284 |
.PP |
| 285 |
Example 4: Make all |
| 286 |
.B chrome |
| 287 |
processes run nicer: |
| 288 |
.IP |
| 289 |
$ renice +4 $(pgrep chrome) |
| 290 |
.PP |
| 291 |
Example 5: Wait for a process with a known PID to finish: |
| 292 |
.IP |
| 293 |
$ echo ${PID} | pidwait -F - |
| 294 |
.SH "EXIT STATUS" |
| 295 |
.TP |
| 296 |
.B 0 |
| 297 |
One or more processes matched the criteria. For |
| 298 |
.B pkill |
| 299 |
and |
| 300 |
.BR pidwait , |
| 301 |
one or more |
| 302 |
processes must also have been successfully signalled or waited for. |
| 303 |
.TP |
| 304 |
.B 1 |
| 305 |
No processes matched or none of them could be signalled. |
| 306 |
.TP |
| 307 |
.B 2 |
| 308 |
Syntax error in the command line. |
| 309 |
.TP |
| 310 |
.B 3 |
| 311 |
Fatal error: out of memory etc. |
| 312 |
.SH NOTES |
| 313 |
The process name used for matching is limited to the 15 characters present in |
| 314 |
the output of /proc/\fIpid\fP/stat. Use the \fB\-f\fR option to match against the |
| 315 |
complete command line, /proc/\fIpid\fP/cmdline. Threads may not have the |
| 316 |
same process name as the parent process but will have the same command line. |
| 317 |
.PP |
| 318 |
The running |
| 319 |
.BR pgrep , |
| 320 |
.BR pkill , |
| 321 |
or |
| 322 |
.B pidwait |
| 323 |
process will never report itself as a |
| 324 |
match. |
| 325 |
.PP |
| 326 |
The |
| 327 |
.B \-O \-\-older |
| 328 |
option will silently fail if \fI/proc\fR is mounted with the \fIsubset=pid\fR option. |
| 329 |
.PP |
| 330 |
.B pkill |
| 331 |
will attempt to use |
| 332 |
.BR pidfd_send_signal (2) |
| 333 |
instead of |
| 334 |
.BR kill (2) |
| 335 |
or |
| 336 |
.BR sigqueue (3) |
| 337 |
to send a signal to the target process if it is able to get the process file descriptor. |
| 338 |
.SH BUGS |
| 339 |
The options |
| 340 |
.B \-n |
| 341 |
and |
| 342 |
.B \-o |
| 343 |
and |
| 344 |
.B \-v |
| 345 |
can not be combined. Let |
| 346 |
me know if you need to do this. |
| 347 |
.PP |
| 348 |
If processes start in the same clock tick (usually but not always a 100th |
| 349 |
of a second), the options |
| 350 |
.B \-n |
| 351 |
and |
| 352 |
.B \-o |
| 353 |
will not be able to distinguish which process started in the same clock |
| 354 |
tick and may give erroneous results. |
| 355 |
.PP |
| 356 |
Defunct processes are reported. |
| 357 |
.PP |
| 358 |
.B pidwait |
| 359 |
requires the |
| 360 |
.BR pidfd_open (2) |
| 361 |
system call which first appeared in Linux 5.3. |
| 362 |
.SH "SEE ALSO" |
| 363 |
.BR killall (1), |
| 364 |
.BR kill (1), |
| 365 |
.BR ps (1), |
| 366 |
.BR skill (1), |
| 367 |
.BR kill (2), |
| 368 |
.BR sigaction (2), |
| 369 |
.BR pidfd_open (2), |
| 370 |
.BR pidfd_send_signal (2), |
| 371 |
.BR sigqueue (3), |
| 372 |
.BR cgroups (7), |
| 373 |
.BR regex (7), |
| 374 |
.BR signal (7) |
| 375 |
.SH "REPORTING BUGS" |
| 376 |
Please send bug reports to |
| 377 |
.MT [email protected] |
| 378 |
.ME . |