I am using PSUTIL library(mainly because it's cross-platform) to kill a process and its descendants. But it's shutting down the process forcefully. I am using the '.terminate' command. I want to send a normal shutdown signal and kill a process gracefully. How can I do that?
def kill_process(self, pid, including_parent=True):
'''
Kill_process method will kill the process and it's descendants recursively
'''
err_msg_temp = None
try:
parent = psutil.Process(pid)
for child in parent.children(recursive=False):
child_pid = child.pid
if child_pid not in deleted_processes:
self.kill_process(child_pid)
if including_parent:
deleted_processes[pid] = 1
parent.terminate()
except Exception as e:
err_msg_temp = str(e)
If there's a cross-platform command, I would like to know that as well.