Skip to content

Commit

Permalink
added a library function which help to kill linuxprocess
Browse files Browse the repository at this point in the history
added a library function which help to kill linuxprocess

Signed-off-by: Praveen K Pandey <[email protected]>
  • Loading branch information
PraveenPenguin committed May 14, 2024
1 parent 5164ceb commit 229187f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion avocado/utils/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
"""
Linux OS utilities
"""

import logging
import os

import psutil

from avocado.utils import genio

LOGGER = logging.getLogger(__name__)


def get_proc_sys(key):
"""
Expand Down Expand Up @@ -87,3 +90,18 @@ def get_processes_by_name(name):
proc for proc in psutil.process_iter(["name"]) if proc.info["name"] == name
]
return matching_processes


def kill_processes(processes):
"""
Attempt to kill all 'processes'
:param processes: linux process
"""
for proc in processes:
try:
proc.kill()
except psutil.NoSuchProcess:
LOGGER.error(f"No such process: {proc.pid}")
except psutil.AccessDenied:
LOGGER.error(f"Access denied to {proc.pid}")

0 comments on commit 229187f

Please sign in to comment.