diff options
author | Daniil Baturin <daniil@baturin.org> | 2018-07-19 04:05:28 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2018-07-19 04:05:28 +0200 |
commit | 145550408bbe53f5bfb8b0211bacc5129d7b3117 (patch) | |
tree | a099f400057fb298e55db0cd24789f5b3abedee1 | |
parent | f19cfb3a82554d5389bce994492969ed737dd3d8 (diff) | |
download | vyos-1x-145550408bbe53f5bfb8b0211bacc5129d7b3117.tar.gz vyos-1x-145550408bbe53f5bfb8b0211bacc5129d7b3117.zip |
Add a function for quickly checking running processes by their PID files.
-rw-r--r-- | debian/control | 1 | ||||
-rw-r--r-- | python/vyos/util.py | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/debian/control b/debian/control index 51f396604..ff7460bee 100644 --- a/debian/control +++ b/debian/control @@ -19,6 +19,7 @@ Depends: python3, python3-netifaces, python3-jinja2, python3-pystache, + python3-psutil, ipaddrcheck, tcpdump, bmon, 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 <http://www.gnu.org/licenses/>. 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)) |