From 145550408bbe53f5bfb8b0211bacc5129d7b3117 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 19 Jul 2018 04:05:28 +0200 Subject: Add a function for quickly checking running processes by their PID files. --- python/vyos/util.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'python/vyos/util.py') diff --git a/python/vyos/util.py b/python/vyos/util.py index 8b3de7999..11a75c14b 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -14,6 +14,7 @@ # License along with this library. If not, see . import re +import psutil def colon_separated_to_dict(data_string, uniquekeys=False): @@ -63,3 +64,9 @@ def colon_separated_to_dict(data_string, uniquekeys=False): pass return data + +def process_running(pid_file): + """ Checks if a process with PID in pid_file is running """ + with open(pid_file, 'r') as f: + pid = f.read().strip() + return psutil.pid_exists(int(pid)) -- cgit v1.2.3