Project

General

Profile

Actions

Bug #3563

closed

pgrep(1) -x description could be clearer

Added by Alasdair Lumsden about 10 years ago. Updated almost 9 years ago.

Status:
Resolved
Priority:
Low
Category:
manpage - manual pages
Start date:
2013-02-15
Due date:
% Done:

100%

Estimated time:
Difficulty:
Bite-size
Tags:
Gerrit CR:
External Bug:

Description

From the pgrep man page:

     -x
                      Considers only processes whose  argument  string
                      or  executable  file  name  exactly  matches the
                      specified pattern to be matching processes.  The
                      pattern match is considered to be exact when all
                      characters in the  process  argument  string  or
                      executable file name match the pattern.

Observed behaviour:

# pgrep /opt/ec/bin/snapshot_hourly.sh
# pgrep -x /opt/ec/bin/snapshot_hourly.sh
# ps -ef | grep /opt/ec/bin/snapshot_hourly.sh
    root 71199 56198   0 10:24:06 pts/3       0:00 /bin/bash /opt/ec/bin/snapshot_hourly.sh
    root 71587 66659   0 10:24:33 pts/6       0:00 grep /opt/ec/bin/snapshot_hourly.sh
Actions #1

Updated by Alasdair Lumsden about 10 years ago

pargs output:

root ~ (so1-12.ixlon1): pargs 36481
36481:  /bin/bash /opt/ec/bin/snapshot_hourly.sh
argv[0]: /bin/bash
argv[1]: /opt/ec/bin/snapshot_hourly.sh
root ~ (so1-12.ixlon1): pgrep -x /opt/ec/bin/snapshot_hourly.sh
root ~ (so1-12.ixlon1): 
Actions #2

Updated by Yuri Pankov about 10 years ago

Remember that you need -f to match full command line, not just executable name, but it still looks like the documentation is inaccurate here, or rather a bit puzzling (same on FreeBSD), while linux version seems to documents it correctly:

-x     Only match processes whose name (or command line if -f is specified) exactly match the pattern.

So the following would have worked for you:

pgrep -fx '/bin/bash /opt/ec/bin/snapshot_hourly.sh'

Actions #3

Updated by Rich Lowe almost 10 years ago

It's saying "executable file name" to try to suggest it matches on the basename, not the full path. That's admittedly not particularly clear. So not only, as Yuri said, is it not matching because of the interpretter, but also because of the full path (both would cause you to need -f)

Actions #4

Updated by Sachidananda Urs about 9 years ago

I propose to change the documentation to reflect the program behavior

sac@hipster:/tmp$ pgrep x emacs-gtk
2544
sac@hipster:/tmp$ pgrep -x /usr/bin/emacs-gtk
sac@hipster:/tmp$ ps 2544
PID TT S TIME COMMAND
2544 ? S 0:41 /usr/bin/emacs-gtk
sac@hipster:/tmp$ pgrep -x 'emacs
.*'
2544
sac@hipster:~$ pgrep -x '.macs.*'
2544
sac@hipster:~$

==========
I suggest changing:

x
Considers only processes whose argument
string or executable file name exactly
matches the specified pattern to be match

ing processes. The pattern match is con-
sidered to be exact when all characters in
the process argument string or executable
file name match the pattern.

To

-x
Considers only processes whose executable
file name exactly matches the specified
pattern to the matching processes. The
pattern match is considered to be exact when
all characters in the executable file name
match the pattern.

If I get a couple of ok on this I'll submit a patch for man page.

Actions #5

Updated by Sachidananda Urs about 9 years ago

I propose to change the documentation to reflect the program behavior

sac@hipster:/tmp$ pgrep -x emacs-gtk
2544
sac@hipster:/tmp$ pgrep -x /usr/bin/emacs-gtk
sac@hipster:/tmp$ ps 2544
PID TT S TIME COMMAND
2544 ? S 0:41 /usr/bin/emacs-gtk
sac@hipster:/tmp$ pgrep -x 'emacs.*'
2544
sac@hipster:~$ pgrep -x '.macs.*'
2544
sac@hipster:~$

I suggest changing:

 -x
                      Considers  only  processes  whose  argument
                      string  or  executable  file  name  exactly
                      matches the specified pattern to be  match-
                      ing  processes.  The  pattern match is con-
                      sidered to be exact when all characters  in
                      the  process  argument string or executable
                      file name match the pattern.

To

-x
                      Considers only processes whose executable
                      file name exactly matches the specified 
                      pattern to the matching processes. The
                      pattern match is considered to be exact when
                      all characters in the executable file name 
                      match the pattern.

If I get a couple of ok on this I'll submit a patch for man page.
Actions #6

Updated by Yuri Pankov about 9 years ago

  • Category changed from cmd - userland programs to manpage - manual pages
  • Tags deleted (needs-triage)

I still find the linux' description better, as it's far easier to understand than "Considers only processes whose executable file name exactly matches the specified pattern to the matching processes."

Actions #7

Updated by Sachidananda Urs about 9 years ago

Yuri Pankov wrote:

I still find the linux' description better, as it's far easier to understand than "Considers only processes whose executable file name exactly matches the specified pattern to the matching processes."

Yeah I agree too. It is quite short and very much clear. Maybe we should discuss this in the mailing list and come to a conclusion. Can you bring this topic on discuss?

Actions #8

Updated by Sachidananda Urs about 9 years ago

For quick reference, linux man page says:

       -x, --exact
              Only match processes whose name (or command line if -f is specified) exactly match the pattern.
Actions #9

Updated by Sachidananda Urs about 9 years ago

  • Status changed from New to Feedback
  • Assignee set to Sachidananda Urs
  • % Done changed from 0 to 50
Actions #10

Updated by Sachidananda Urs about 9 years ago

  • Status changed from Feedback to Pending RTI
Actions #11

Updated by Dan McDonald about 9 years ago

  • Subject changed from pgrep not working as documented or documentation inaccurate to pgrep(1) -x description could be clearer
  • Status changed from Pending RTI to Resolved

commit c1ca8c1d77967585bfbe78133a7257e36ebfec85
Author: Sachidananda Urs <>
Date: Wed Jan 15 22:27:07 2014 +0530

3563 pgrep(1) -x description could be clearer
Reviewed by: Marcel Telka &lt;&gt;
Reviewed by: Robert Mustacchi &lt;&gt;
Approved by: Dan McDonald &lt;&gt;

:100644 100644 f4ae7ff... 9e65244... M usr/src/man/man1/pgrep.1

Actions #12

Updated by Sachidananda Urs almost 9 years ago

  • % Done changed from 50 to 100
Actions

Also available in: Atom PDF