From dc0cc59684cfc4335ab7a2a351dfcd52602ef58a Mon Sep 17 00:00:00 2001 From: "Eshan Roy (Eshanized)" Date: Thu, 25 Apr 2024 09:52:05 +0530 Subject: [PATCH] [update] Functions -> check_if_another_process_running() --- blackbox/Functions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/blackbox/Functions.py b/blackbox/Functions.py index 5b0fc8b..a14513a 100644 --- a/blackbox/Functions.py +++ b/blackbox/Functions.py @@ -1796,3 +1796,13 @@ def remove_snigdhaos_repos(): "Found Exception in LOC1705: %s" % e ) return e +def check_if_process_running(process_name): + # DOCS : https://psutil.readthedocs.io/en/latest/#psutil.process_iter + for proc in psutil.process_iter(): + try: + pinfo = proc.as_dict(attrs=["pid", "name", "create_time"]) + if process_name == pinfo["pid"]: + return True + except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): + pass + return False