Information Technology Reference
In-Depth Information
Table 5.4
Common pgrep and pkill Command-Line Arguments
(continued)
Argument
Description
-U
Real User ID
Matches processes with the specified real user ID
-v
Matches all processes except those that meet specified
criteria
-x
Matches only processes that exactly match the pattern
The
pattern
is a regular expression that is used to select processes based on
the program name. The following listing shows the difference between
obtaining the PID of the
admintool
command using the
ps
and
grep(1)
commands versus the
pgrep
command:
$ ps -eaf|grep admintool
root 2898 1096 0 Sep 04 pts/7 0:02 admintool
$ pgrep adm*
2898
$
When the
-f
command-line argument is specified along with the
pattern
,
the
pattern
is compared against the program arguments instead of the pro-
gram name. In addition, if the
-x
command-line argument is specified, the
regular expression interpretation of
pattern
is disabled, and
pattern
must
match the program name or program arguments exactly.
All the ID types of command-line arguments accept multiple IDs (separated
by commas). In the case of real and effective user IDs and real group IDs
(
-G
), either the numeric IDs or the account names can be specified.
The
pgrep
command supports two additional command-line arguments. The
-d
command-line argument is used to specify a delimiter for separating PIDs
when the specified
pgrep
criteria match more than one PID. By default, this
delimiter is the newline character. The following listing shows using the
pgrep
command to list the processes owned by the
ambro
user account and
the effect of specifying the space character as the delimiter:
$ pgrep -u ambro
781
782
910
913
$ pgrep -d' ' -u ambro
781 782 910 913
$
The delimiter command-line argument allows the output of the
pgrep
com-
mand to be used as the input to other commands or shell scripts.