The snippet below (from an existing script) is used to check the xvfb processes and whether they are listening on a specific port:

  my_list=`pgrep -u $CurrentUserID -fl Xvfb | grep :${XVFBPORT}`
  process_list=`pgrep -fl Xvfb | grep :${XVFBPORT}`

The Xvfb process is started in the following format:

  Xvfb :619  -fp /usr/share/fonts/X11/misc # i.e. in this case XVFBPORT is 619

Apparently this does not work as intended on Ubuntu since the output of pgrep -fl Xvfb would give something like:

  4812 Xvfb

, without the ":619" at the end. Clearly, with some additional piping to ps this can be easily fixed.

Is there some other distro or configuration where pgrep would give the output as expected by the script?

  • What it's this other distro where pgrep works as intended? It could be different versions of pgrep that are installed by default. – Braiam Jul 17 '14 at 13:30
  • @Braiam the script appears to have been tested against RHEL/SuSE but I did not have a chance to verify – prusswan Jul 18 '14 at 0:03

A recent version of pgrep from procps-ng has the -a option.

   -a, --list-full
          List  the  full  command line as well as the process ID.

So the pgrep -afl Xvfb | grep 619 should print:

  4812 Xvfb :619  -fp /usr/share/fonts/X11/mis

On my Debian Jessie (testing) this option is present, and the installed package is procps-ng 3.3.9, but I can't find a version when this option was introduced, perhaps the option is present in procps-ng and doesn't exist in procps.

| improve this answer | |
  • I can confirm that the -a is there on pgrep from procps-ng 3.3.4. – terdon Jul 17 '14 at 13:37
  • 1
    The -a, --list-full option appears to be present on Ubuntu 14.04 (procps-ng 3.3.9) but absent on 13.10 (procps-ng 3.3.3) - however on 13.10 the default behavior for -l appears to be to print the whole command, including arguments. So it looks like the new option may have broken backward compatibility? – steeldriver Jul 17 '14 at 13:40
  • This might be the reason, I ran the script on Ubuntu 14.04 where it was indeed not working. – prusswan Jul 18 '14 at 0:04
  • I can confirm that pgrep -a will give the intended output on Ubuntu 14.04, however this option is not shown in pgrep --help. Otherwise I would certainly have tried it. – prusswan Jul 18 '14 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.