()
Find the PID of the qemu usermode binary which we are
  talking to.
Find the PID of the qemu usermode binary which we are
  talking to.
Find the PID of the qemu usermode binary which we are talking to .
def pid():
  """Find the PID of the qemu usermode binary which we are
  talking to.
  """
  # Find all inodes in our process which are connections.
  targets = set(c.raddr for c in psutil.Process().connections())

  # No targets? :(
  if not targets:
    return 0

  for process in psutil.process_iter():
    if not process.name().startswith('qemu'):
      continue

    try:
      connections = process.connections()
    except Exception:
      continue

    for c in connections:
      if c.laddr in targets:
        return process.pid
def pid ( ) : # Find all inodes in our process which are connections. targets = set ( c . raddr for c in psutil . Process ( ) . connections ( ) ) # No targets? :( if not targets : return 0 for process in psutil . process_iter ( ) : if not process . name ( ) . startswith ( 'qemu' ) : continue try : connections = process . connections ( ) except Exception : continue for c in connections : if c . laddr in targets : return process . pid