Skip to content

Instantly share code, notes, and snippets.

@William-Hill
Created January 22, 2018 00:22
Show Gist options
  • Save William-Hill/78171b41bf0acaa014f4d3d62b454bae to your computer and use it in GitHub Desktop.
Save William-Hill/78171b41bf0acaa014f4d3d62b454bae to your computer and use it in GitHub Desktop.
Find all processes belonging to a user in python
'''Requires psutil package that's available from pip'''
import psutil
def find_processes_by_user(user_name):
user_processes = [proc for proc in psutil.process_iter(attrs=['pid', 'name', 'username']) if proc.info["username"] == user_name]
return user_processes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment