Skip to content

Commit 23559ab

Browse files
added a library function which help to kill linuxprocess
added a library function which help to kill linuxprocess Signed-off-by: Praveen K Pandey <praveen@linux.vnet.ibm.com>
1 parent 5164ceb commit 23559ab

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

avocado/utils/linux.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
"""
2323
Linux OS utilities
2424
"""
25-
25+
import logging
2626
import os
2727
import psutil
2828

2929
from avocado.utils import genio
3030

31+
LOGGER = logging.getLogger(__name__)
32+
3133

3234
def get_proc_sys(key):
3335
"""
@@ -87,3 +89,18 @@ def get_processes_by_name(name):
8789
proc for proc in psutil.process_iter(["name"]) if proc.info["name"] == name
8890
]
8991
return matching_processes
92+
93+
94+
def kill_processes(processes):
95+
"""
96+
Attempt to kill all 'processes'
97+
98+
:param processes: linux process
99+
"""
100+
for proc in processes:
101+
try:
102+
proc.kill()
103+
except psutil.NoSuchProcess:
104+
LOGGER.error(f"No such process: {proc.pid}")
105+
except psutil.AccessDenied:
106+
LOGGER.error(f"Access denied to {proc.pid}")

0 commit comments

Comments
 (0)