summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-08-12 07:27:54 +0200
committerGitHub <noreply@github.com>2023-08-12 07:27:54 +0200
commit616bdb5299bf8252dfdab26f21a4b356cff6724e (patch)
treee9e68c32e45f39c3ac425aac49500432d1a3cf95
parent80465e2cb222307243f91afdc69c78e2953192fb (diff)
parent58a20e42087cbb7a1b3b4725fa40fd15a31bb4ed (diff)
downloadvyos-1x-616bdb5299bf8252dfdab26f21a4b356cff6724e.tar.gz
vyos-1x-616bdb5299bf8252dfdab26f21a4b356cff6724e.zip
Merge pull request #2127 from sever-sever/T2298-eq
T2298: vyos.util: extend process_named_running() signature with cmdline
-rw-r--r--python/vyos/util.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 32a5ae116..4df046a36 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -462,15 +462,17 @@ def process_running(pid_file):
pid = f.read().strip()
return pid_exists(int(pid))
-
-def process_named_running(name):
+def process_named_running(name, cmdline: str=None):
""" Checks if process with given name is running and returns its PID.
If Process is not running, return None
"""
from psutil import process_iter
- for p in process_iter():
- if name in p.name():
- return p.pid
+ for p in process_iter(['name', 'pid', 'cmdline']):
+ if cmdline:
+ if p.info['name'] == name and cmdline in p.info['cmdline']:
+ return p.info['pid']
+ elif p.info['name'] == name:
+ return p.info['pid']
return None