Comment 4 for bug 1174911

Revision history for this message
Dominique Poulain (dominique-poulain) wrote : Re: pgrep cuts process names

Confirmed on latest Xenial:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Xenial Xerus (development branch)
Release: 16.04
Codename: xenial

Related to LP #295876 'top and ps truncate command after 15 chars' at <https://bugs.launchpad.net/ubuntu/+source/procps/+bug/295876>.

As per comment #3 to LP #295876 (<https://bugs.launchpad.net/ubuntu/+source/procps/+bug/295876/comments/3>), The root cause seems to be that pgrep gets the process's name from /proc/<pid>/status instead of /proc/<pid>/cmdline; in the former case, the name is truncated to 15 characters:

$ python3 -c 'print(len("chromium-browser"))'
16
$ pgrep chromium-browser
echo $?
1 # exit status code 1 == no processes matched (as per man page for pgrep(1))
$ pgrep chromium-browse
22351
22364
[snip]

$ cat /proc/22351/cmdline && echo
chromium-browser --enable-pinch
$ cat /proc/22351/status | grep Name
Name: chromium-browse