0

我正在尝试编写一个python代码,通过在linux中使用服务名称搜索服务来检索tomcat服务的绝对路径。有没有我可以使用的模块,代码片段将不胜感激。

提前致谢。

4

1 回答 1

0

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))

在上面的示例中,interesting_process.cmdline 将是组成应用程序命令行的参数列表。

高温高压

于 2013-11-06T01:34:03.103 回答