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))
psutil
可能就是你想要的。你知道吗https://pypi.python.org/pypi/psutil
在上面的例子中,有趣的是_进程.cmdline将是组成应用程序命令行的参数列表。你知道吗
HTH公司
相关问题 更多 >
编程相关推荐