Skip to content

Commit

Permalink
add find_process from admin
Browse files Browse the repository at this point in the history
  • Loading branch information
laszewsk committed Jan 8, 2024
1 parent 1161824 commit 806ab2a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/cloudmesh/common/Shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,40 @@ def oneline(script, seperator=" && "):
"""
return seperator.join(textwrap.dedent(script).strip().splitlines())

def find_process(name):
""" find a process by name
:param name: the name of the process
:return: A list of dicts in which the attributes pid, command,
and created are available and the name matches
the specified name argument.
TODO: at one point this should be moved to cloudmesh.common
Return a list of processes matching 'name'.
"""

processes = None
for p in psutil.process_iter():
found = None
try:
found = p.name()
except (psutil.AccessDenied, psutil.ZombieProcess):
pass
except psutil.NoSuchProcess:
continue
if name == found:
if processes is None:
processes = []
processes.append(
{
"pid": p.pid,
"command": " ".join(p.cmdline()),
"created": p.create_time()
})
return processes


@staticmethod
def is_choco_installed():
"""return true if chocolatey windows package manager is installed
Expand Down

0 comments on commit 806ab2a

Please sign in to comment.