finding pid and killing process abilities were extended

This commit is contained in:
Volkan Şahin 2016-06-09 12:12:30 +03:00
parent 3b9c5fa097
commit 46047ac43b

View file

@ -91,6 +91,8 @@ class System:
def pids(): def pids():
return psutil.pids() return psutil.pids()
@staticmethod @staticmethod
def find_pid_by_name(p_name): def find_pid_by_name(p_name):
for id in psutil.pids(): for id in psutil.pids():
@ -99,10 +101,29 @@ class System:
return None return None
""" """
@staticmethod
def find_pids_by_name(p_name):
arr = []
for pid in psutil.get_pid_list():
if psutil.Process(pid).name==p_name:
arr.append(pid)
return arr
@staticmethod
def is_running(pid):
return psutil.pid_exists(pid)
@staticmethod @staticmethod
def kill_by_pid(pid): def kill_by_pid(pid):
return psutil.Process(pid).kill() return psutil.Process(pid).kill()
@staticmethod
def kill_by_pids(pids):
for pid in pids:
psutil.Process(pid).kill()
@staticmethod @staticmethod
def find_name_by_pid(pid): def find_name_by_pid(pid):
return psutil.Process(pid).name() return psutil.Process(pid).name()
@ -134,6 +155,7 @@ class System:
return psutil.Process(pid).create_time() return psutil.Process(pid).create_time()
""" """
@staticmethod @staticmethod
def cpu_times(pid): def cpu_times(pid):