Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a library function which help to get linux process and kill those process #5932

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions avocado/utils/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""

import os
import psutil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that you are adding psutil as requirement for this utility which is new requirement for Avocado. Unfortunately, right now we don't have a way how to add utils specific requirements. Is it possible for you to do this without psutil ?

PS: Right now we are working on autils project which should merge avocado and avocado-vt utils together and there we should be able to add utils specific requirement. Unfortunately, this project is not prepared yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richtja I tried, but we need to grep or awk in ps command that seems not good way, please suggest if you have anything in mind

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PraveenPenguin it looks like you're after the process name. That should be available under /proc/$PID/comm. Let me know if there's other info you're after.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clebergnu it is a reverse way , I am looking process id having input as process name


from avocado.utils import genio

Expand Down Expand Up @@ -72,3 +73,17 @@ def enable_selinux_enforcing():
if is_selinux_enforcing():
return True
return False


def get_processes_by_name(name):
"""
Return a list of processes matching 'name'

:param name: name of the process

:return: list of processes
"""
matching_processes = [
proc for proc in psutil.process_iter(["name"]) if proc.info["name"] == name
]
return matching_processes