Added process management actions

This commit is contained in:
Fabio Manganiello 2020-01-08 00:07:15 +01:00
parent c53dfab246
commit aa6bf5379a

View file

@ -626,6 +626,11 @@ class SystemPlugin(Plugin):
return ProcessResponseList(p_list) return ProcessResponseList(p_list)
@staticmethod
def _get_process(pid: int):
import psutil
return psutil.Process(pid)
@action @action
def pid_exists(self, pid: int) -> bool: def pid_exists(self, pid: int) -> bool:
""" """
@ -635,5 +640,47 @@ class SystemPlugin(Plugin):
import psutil import psutil
return psutil.pid_exists(pid) return psutil.pid_exists(pid)
@action
def suspend(self, pid: int):
"""
Suspend a process.
:param pid: Process PID.
"""
self._get_process(pid).suspend()
@action
def resume(self, pid: int):
"""
Resume a process.
:param pid: Process PID.
"""
self._get_process(pid).resume()
@action
def terminate(self, pid: int):
"""
Terminate a process.
:param pid: Process PID.
"""
self._get_process(pid).terminate()
@action
def kill(self, pid: int):
"""
Kill a process.
:param pid: Process PID.
"""
self._get_process(pid).kill()
@action
def wait(self, pid: int, timeout: int = None):
"""
Wait for a process to terminate.
:param pid: Process PID.
:param timeout: Timeout in seconds (default: ``None``).
"""
self._get_process(pid).wait(timeout)
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et: