def pgrep(pattern, user=None, full=False):
 procs = []
 for proc in psutil.process_iter():
  name_match = ((pattern in ' '.join(_get_proc_cmdline(proc))) if full else (pattern in _get_proc_name(proc)))
  user_match = (True if (user is None) else (user == _get_proc_username(proc)))
  if (name_match and user_match):
   procs.append(_get_proc_pid(proc))
 return (procs or None)

def pgrep ( pattern , user = None , full = False ) : procs = [ ] for proc in psutil . process_iter ( ) : name_match = ( ( pattern in ' ' . join ( _get_proc_cmdline ( proc ) ) ) if full else ( pattern in _get_proc_name ( proc ) ) ) user_match = ( True if ( user is None ) else ( user == _get_proc_username ( proc ) ) ) if ( name_match and user_match ) : procs . append ( _get_proc_pid ( proc ) ) return ( procs or None )
return the pids for processes matching a pattern .