本文整理汇总了Python中psutil.Process.cmdline方法的典型用法代码示例。如果您正苦于以下问题:Python Process.cmdline方法的具体用法?Python Process.cmdline怎么用?Python Process.cmdline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil.Process
的用法示例。
在下文中一共展示了Process.cmdline方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_procinfo_by_address
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import cmdline [as 别名]
def get_procinfo_by_address(ip_src, ip_dst, port_src=None, port_dst=None):
"""
Gets Infos about the Prozess associated with the given address information
Both port_src and port_dst must be not None or None at the same time.
return -- [pid, "/path/to/command", "user", "hash"] or []
"""
result = []
if port_src is not None:
pids = [c.pid for c in net_connections()
if len(c.raddr) != 0 and c.pid is not None and
(c.laddr[0], c.raddr[0], c.laddr[1], c.raddr[1]) == (ip_src, ip_dst, port_src, port_dst)]
else:
pids = [c.pid for c in net_connections()
if len(c.raddr) != 0 and c.pid is not None and (c.laddr[0], c.raddr[0]) == (ip_src, ip_dst)]
try:
if len(pids) > 1:
logger.warning("more than 1 matching process: %r", pids)
proc = Process(pids[0])
cmd = [pids[0], proc.cmdline(), proc.username()]
hash_input = "%d%s%s" % (cmd[0], cmd[1], cmd[2])
procinfo_hash = hashlib.sha256(hash_input.encode("UTF-8"))
cmd.append(procinfo_hash)
logger.debug("process info: %r", cmd)
return cmd
except IndexError:
pass
return []
示例2: get_soledad_server_pid
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import cmdline [as 别名]
def get_soledad_server_pid():
output = check_output(['pidof', 'python'])
for pid in output.split():
proc = Process(int(pid))
cmdline = proc.cmdline()
if args.issubset(set(cmdline)):
return int(pid)
示例3: query_process
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import cmdline [as 别名]
def query_process(process=None):
if not isinstance(process, Process):
process = Process(process)
cmd_line = u" ".join((u'"%s"' % x.replace('"', r'\"') if " " in x else x.replace('"', r'\"') \
for x in process.cmdline()))
return {"pid": process.pid, "cmd_line": cmd_line, "owner": process.uids()[0]}