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

NAME

6       pgrep, pkill, pidwait - look up, signal, or wait for processes based on
7       name and other attributes
8

SYNOPSIS

10       pgrep [options] pattern
11       pkill [options] pattern
12       pidwait [options] pattern
13

DESCRIPTION

15       pgrep looks through the  currently  running  processes  and  lists  the
16       process IDs which match the selection criteria to stdout.  All the cri‐
17       teria have to match.  For example,
18
19              $ pgrep -u root sshd
20
21       will only list the processes called sshd AND owned  by  root.   On  the
22       other hand,
23
24              $ pgrep -u root,daemon
25
26       will list the processes owned by root OR daemon.
27
28       pkill  will  send  the  specified  signal  (by default SIGTERM) to each
29       process instead of listing them on stdout.
30
31       pidwait will wait for each process instead of listing them on stdout.
32

OPTIONS

34       -signal
35       --signal signal
36              Defines the signal to send to each matched process.  Either  the
37              numeric  or  the  symbolic  signal name can be used. In pgrep or
38              pidwait mode this has no effect unless used in conjunction  with
39              --require-handler to filter to processes with a userspace signal
40              handler present for a particular signal.
41
42
43       -c, --count
44              Suppress normal output; instead print a count of  matching  pro‐
45              cesses.   When count does not match anything, e.g. returns zero,
46              the command will return non-zero value. Note that for pkill  and
47              pidwait,  the count is the number of matching processes, not the
48              processes that were successfully signaled or waited for.
49
50       -d, --delimiter delimiter
51              Sets the string used to delimit each process ID  in  the  output
52              (by default a newline).  (pgrep only.)
53
54       -e, --echo
55              Display name and PID of the process being killed.  (pkill only.)
56
57       -f, --full
58              The  pattern  is normally only matched against the process name.
59              When -f is set, the full command line is used.
60
61       -g, --pgroup pgrp,...
62              Only match processes in the process group IDs  listed.   Process
63              group  0  is  translated into pgrep's, pkill's, or pidwait's own
64              process group.
65
66       -G, --group gid,...
67              Only match processes whose real group ID is listed.  Either  the
68              numerical or symbolical value may be used.
69
70       -i, --ignore-case
71              Match processes case-insensitively.
72
73       -l, --list-name
74              List the process name as well as the process ID.  (pgrep only.)
75
76       -a, --list-full
77              List  the  full  command line as well as the process ID.  (pgrep
78              only.)
79
80       -n, --newest
81              Select only the newest (most recently started) of  the  matching
82              processes.
83
84       -o, --oldest
85              Select  only the oldest (least recently started) of the matching
86              processes.
87
88       -O, --older secs
89              Select processes older than secs.
90
91       -P, --parent ppid,...
92              Only match processes whose parent process ID is listed.
93
94       -s, --session sid,...
95              Only match processes whose process session ID is  listed.   Ses‐
96              sion  ID 0 is translated into pgrep's, pkill's, or pidwait's own
97              session ID.
98
99       -t, --terminal term,...
100              Only match processes whose controlling terminal is listed.   The
101              terminal name should be specified without the "/dev/" prefix.
102
103       -u, --euid euid,...
104              Only  match processes whose effective user ID is listed.  Either
105              the numerical or symbolical value may be used.
106
107       -U, --uid uid,...
108              Only match processes whose real user ID is listed.   Either  the
109              numerical or symbolical value may be used.
110
111       -v, --inverse
112              Negates the matching.  This option is usually used in pgrep's or
113              pidwait's context.  In pkill's context the short option is  dis‐
114              abled to avoid accidental usage of the option.
115
116       -w, --lightweight
117              Shows  all  thread  ids  instead of pids in pgrep's or pidwait's
118              context.  In pkill's context this option is disabled.
119
120       -x, --exact
121              Only match processes whose names (or  command  lines  if  -f  is
122              specified) exactly match the pattern.
123
124       -F, --pidfile file
125              Read  PIDs  from  file.  This option is more useful for pkill or
126              pidwait than pgrep.
127
128       -L, --logpidfile
129              Fail if pidfile (see -F) not locked.
130
131       -r, --runstates D,R,S,Z,...
132              Match only processes which match the process state.
133
134       -A, --ignore-ancestors
135              Ignore all ancestors of pgrep, pkill, or pidwait.  For  example,
136              this can be useful when elevating with sudo or similar tools.
137
138       -H, --require-handler
139              Only match processes with a userspace signal handler present for
140              the signal to be sent.
141
142       --cgroup name,...
143              Match on provided control group (cgroup) v2 name. See cgroups(8)
144
145       --ns pid
146              Match processes that belong to the same namespaces. Required  to
147              run  as  root  to match processes from other users. See --nslist
148              for how to limit which namespaces to match.
149
150       --nslist name,...
151              Match only the provided namespaces. Available  namespaces:  ipc,
152              mnt, net, pid, user, uts.
153
154       -q, --queue value
155              Use  sigqueue(3)  rather  than kill(2) and the value argument is
156              used to specify an integer to be sent with the  signal.  If  the
157              receiving  process has installed a handler for this signal using
158              the SA_SIGINFO flag to sigaction(2), then  it  can  obtain  this
159              data via the si_value field of the siginfo_t structure.
160
161       -V, --version
162              Display version information and exit.
163
164       -h, --help
165              Display help and exit.
166

OPERANDS

168       pattern
169              Specifies  an  Extended  Regular Expression for matching against
170              the process names or command lines.
171

EXAMPLES

173       Example 1: Find the process ID of the named daemon:
174
175              $ pgrep -u root named
176
177       Example 2: Make syslog reread its configuration file:
178
179              $ pkill -HUP syslogd
180
181       Example 3: Give detailed information on all xterm processes:
182
183              $ ps -fp $(pgrep -d, -x xterm)
184
185       Example 4: Make all chrome processes run nicer:
186
187              $ renice +4 $(pgrep chrome)
188

EXIT STATUS

190       0      One or more processes matched the criteria. For pkill  and  pid‐
191              wait,  one  or  more  processes must also have been successfully
192              signalled or waited for.
193       1      No processes matched or none of them could be signalled.
194       2      Syntax error in the command line.
195       3      Fatal error: out of memory etc.
196

NOTES

198       The process name used for matching is  limited  to  the  15  characters
199       present  in  the  output of /proc/pid/stat.  Use the -f option to match
200       against the complete command line, /proc/pid/cmdline. Threads  may  not
201       have the same process name as the parent process but will have the same
202       command line.
203
204       The running pgrep, pkill, or pidwait process will never  report  itself
205       as a match.
206
207       The  -O  --older option will silently fail if /proc is mounted with the
208       subset=pid option.
209

BUGS

211       The options -n and -o and -v can not be combined.  Let me know  if  you
212       need to do this.
213
214       Defunct processes are reported.
215
216       pidwait  requires the pidfd_open(2) system call which first appeared in
217       Linux 5.3.
218

SEE ALSO

220       ps(1), regex(7), signal(7), sigqueue(3), killall(1), skill(1), kill(1),
221       kill(2), cgroups(8).
222

AUTHOR

224       Kjetil Torgrim Homme ⟨kjetilho@ifi.uio.no⟩
225

REPORTING BUGS

227       Please send bug reports to ⟨procps@freelists.org⟩
228
229
230
231procps-ng                         2023-01-16                          PGREP(1)
Impressum