Created
January 22, 2018 00:22
-
-
Save William-Hill/78171b41bf0acaa014f4d3d62b454bae to your computer and use it in GitHub Desktop.
Find all processes belonging to a user in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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