pgrep, pkill - find or signal processes by name and other
attributes
pgrep [-flnovx] [-d delim]
[-P ppidlist] [-g pgrplist]
[-s sidlist] [-u euidlist]
[-U uidlist] [-G gidlist]
[-t termlist] [pattern]
pkill [-signal] [-fnovx]
[-P ppidlist] [-g pgrplist]
[-s sidlist] [-u euidlist]
[-U uidlist] [-G gidlist]
[-t termlist] [pattern]
Pgrep searches the currently active processes for
occurences of the specified pattern and prints the process IDs of the
matching ones. Pattern is treated as an extended regular expression
as described in egrep(1). A number of options can be used in addition
to the pattern (or without specifying pattern) to further
restrict the set of matching processes. Multiple criteria can be specified
for each of these options, separated by commas or blanks, or by giving the
option more than once. In this case, all processes that match any of the
given criteria are considered matches. If more than one kind of criterion is
specified, a process must match each kind of criterion.
Pkill is similar to pgrep, but a signal (SIGTERM by
default) is sent to matching processes instead of printing its process ID.
The signal can be changed with the -signal argument; this
argument must appear before all options to be recognized. Signal can
be either numeric or symbolic with the SIG prefix omitted (as in QUIT for
SIGQUIT).
Zombie processes and the current pgrep or pkill
process are never included.
Both commands accept the following options:
- -d delim
- Use the specified delimiter string to separate process IDs in
output. By default, a newline character is used. This option is accepted
by pgrep only.
- -f
- Use the command line arguments of each process instead of the name of its
executable file for matching, and, if -l is also specified, for
printing.
- -g pgrplist
- Restrict matches to processes whose process group ID appears in
pgrplist. If an ID is `0', the process group ID of the current
process is used.
- -G gidlist
- Restrict matches to processes whose real group ID appears in
gidlist.
- -l
- Print the command name in addition to the process ID. This option is
accepted by pgrep only.
- -n
- Select only the newest (most recently created) process of all processes
that matched the other criteria. Cannot be combined with -o.
- -o
- Select only the oldest (least recently created) process of all processes
that matched the other criteria. Cannot be combined with -n.
- -P ppidlist
- Restrict matches to processes whose parent ID appears in
ppidlist.
- -s sidlist
- Restrict matches to processes that are members of a session given in
sidlist. If an ID is `0', the session ID of the current process is
used.
- -t termlist
- Restrict matches to processes that run on any controlling terminal given
in termlist. Terminal specifications have the format described in
ps(1).
- -u uidlist
- Restrict matches to processes whose effective user ID appears in
uidlist.
- -U uidlist
- Restrict matches to processes whose real user ID appears in
uidlist.
- -v
- Reverse the match, that is, select all processes that fail to fulfill the
given criteria.
- -x
- Require the entire process name to be matched, as if pattern was
surrounded by `^( )$'.
Determine the process ID of the inetd process:
Print all processes that have a first argument starting with /bin/ along
with their arguments:
Send a SIGHUP signal to all processes that are owned by either the root
or the daemon user and are children of the init process (process
ID 1):
pkill -HUP -u root,daemon -P 1
- LANG,
LC_ALL
- See locale(7).
- LC_COLLATE
- Affects the collation order for range expressions, equivalence classes,
and collation symbols in extended regular expressions.
- LC_CTYPE
- Determines the mapping of bytes to characters and the availability and
composition of character classes in extended regular expressions.
egrep(1), ps(1), locale(7)
Pgrep and Pkill exit with
- 0
- if matching processes were found, and the -v option was not
specified;
- 1
- if no matching processes were found, or the -v option was specified
without any matches;
- 2
- if an invalid command line argument was found;
- 3
- on fatal errors.
Command names are limited to 18 characters, process arguments to
80 characters; excess characters are stripped.