def pid_by_name(name):
 def match(p):
  if (p.status() == 'zombie'):
   return False
  if (p.name() == name):
   return True
  try:
   if (p.exe() == name):
    return True
  except Exception:
   pass
  return False
 processes = (p for p in psutil.process_iter() if match(p))
 processes = sorted(processes, key=(lambda p: p.create_time()))
 return list(reversed([p.pid for p in processes]))

def pid_by_name ( name ) : def match ( p ) : if ( p . status ( ) == 'zombie' ) : return False if ( p . name ( ) == name ) : return True try : if ( p . exe ( ) == name ) : return True except Exception : pass return False processes = ( p for p in psutil . process_iter ( ) if match ( p ) ) processes = sorted ( processes , key = ( lambda p : p . create_time ( ) ) ) return list ( reversed ( [ p . pid for p in processes ] ) )
pid_by_name -> int list arguments: name : name of program .