def _CheckLeftProcess()

in tools/android/emulator/emulated_device.py [0:0]


  def _CheckLeftProcess(self):
    """Check left process on device, also killing known dead process body."""

    ps_out = self.ExecOnDevice(['ps'])
    lines = ps_out.split('\n')
    raw_key = lines[0].strip().split()
    # The output of ps is buggy on Android device.
    # The columns of header is inconsistent with
    # following lines. Just use the first 4 columns
    # and the last column.
    key = raw_key[:4] + raw_key[-1:]
    processes = []
    for l in lines[1:]:
      line = l.strip()
      if not line:
        continue
      raw_value = line.split()
      value = raw_value[:4] + raw_value[-1:]
      proc = dict(zip(key, value))
      # Ignore kernel process
      vsize = proc.get('VSIZE') or proc.get('VSZ')
      if vsize == '0':
        continue
      # Ignore init
      if proc['PID'] == '1':
        continue
      if os.path.basename(proc['NAME']) == 'pipe_traversal':
        pipe_traversal_pid = proc['PID']
        continue
      if proc['NAME'] == 'ps':
        continue
      processes.append(proc)

    suspicious = False
    for proc in processes:
      # Kill crashed "pm install" body. Its parent
      # process should be pipe_traversal.
      if (proc['PPID'] == pipe_traversal_pid and
          proc['NAME'] == 'app_process'):
        self.ExecOnDevice(['kill', '-9', proc['PID']])
        continue
      suspicious = True

    if suspicious:
      logging.warning('Some process is still running: %s\n', ps_out)