Skip to content
Advertisement

Tag: psutil

Getting MacOS process id from user using python

I want to get the pid by passing in the user name. For example, in the picture of a macOS activity monitor, the user name is ‘root’, and I want something that can return all running processes under user name ‘root’. Answer Use psutil.process_iter() to get all running processes, and then filter them by matching psutil.Process.username() with the desired username.

Advertisement