psutil
moduleIn Python, psutil
(Python system and process utilities) is a package that retrieves information on ongoing processes and #key# system usage (CPU, memory, storage, network, and sensors). We mainly use it for system monitoring, profiling, restricting process resources, and process management.
The module can be installed via pip
, as follows:
pip install psutil
users
methodThe users
method returns a list of named tuples with the following fields for users presently connected to the system:
name
: This is the name of the user.terminal
: This is the pseudo-terminal associated with the user.host
: This is the hostname associated with the user.started
: This is the time since the epoch as a floating-point number given in seconds.pid
: This is the login process PID.psutil.users()
The method takes no parameters.
import psutilprint("The current connected users in the system are: ")print(psutil.users())
psutil
module.