def pkill(pattern, user=None, signal=15, full=False):
 killed = []
 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):
   try:
    proc.send_signal(signal)
    killed.append(_get_proc_pid(proc))
   except psutil.NoSuchProcess:
    pass
 if (not killed):
  return None
 else:
  return {'killed': killed}

def pkill ( pattern , user = None , signal = 15 , full = False ) : killed = [ ] 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 ) : try : proc . send_signal ( signal ) killed . append ( _get_proc_pid ( proc ) ) except psutil . NoSuchProcess : pass if ( not killed ) : return None else : return { 'killed' : killed }
kill processes matching a pattern .