devserver: fix a bug when counting processes

The original code has a bug when run by Python 2.7.6 that it always
return 1 even there's no this process, see

Python 2.7.6 (default, Oct 26 2016, 20:30:19)
  [GCC 4.8.4] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import subprocess
  >>> p = subprocess.Popen('pgrep -fc "xxxx"', stdout=subprocess.PIPE,
      stderr=subprocess.PIPE, shell=True)
  >>> p.communicate()
  ('1\n', '')
  >>> p.wait()
  >>> p = subprocess.Popen(['pgrep', '-fc',  "xxxx"],
      stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  >>> p.communicate()
  ('0\n', '')
  >>> p.wait()

I don't have this issue when run above code with Python 2.7.16. I guess
it should be related to how subprocess runs a process in a shell.

TEST=Ran local test

Change-Id: Ia2e06a58bea9c7a1581dab87441eb2d12cd59c1a
Commit-Ready: ChromeOS CL Exonerator Bot <>
Tested-by: Congbin Guo <>
Reviewed-by: Xixuan Wu <>
1 file changed