检索tomcat服务的绝对路径的Python代码

2024-04-29 15:06:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图编写一个python代码,通过在linux中搜索具有服务名称的服务来检索tomcat服务的绝对路径。 有什么模块我可以用吗, 代码狙击手将高度赞赏。你知道吗

提前谢谢。你知道吗


Tags: 模块代码名称高度linux狙击手tomcat
1条回答
网友
1楼 · 发布于 2024-04-29 15:06:48

psutil可能就是你想要的。你知道吗

https://pypi.python.org/pypi/psutil

import psutil

process_name = u'jboss'  # Place your case-insensitive process name here...
interesting_processes = []

# Loop over all processes, and see if process_name is in any segment of their command lines
for process in psutil.get_process_list():
    try:  # You cannot access some processes unless you're root, so we try here
        for cmd_segment in process.cmdline:
            if process_name.lower() in cmd_segment.lower():
                interesting_processes.append(process)
    except psutil.error.AccessDenied:
        continue  # processing other processes.

# Show off our results
for interesting_process in interesting_processes:
    print 'Process ID: {} has command: {}\n'.format(interesting_process.pid, u' '.join(interesting_process.cmdline))

在上面的例子中,有趣的是_进程.cmdline将是组成应用程序命令行的参数列表。你知道吗

HTH公司

相关问题 更多 >