psutil
module?The psutil
(Python system and process utilities) module is a Python package that retrieves information on ongoing processes and system usage (CPU, memory, storage, network, and sensors). It is mostly used for system monitoring, profiling, restricting process resources, and process management.
This module can be installed via pip
as follows:
pip install psutil
boot_time
methodThe boot_time
method is used to return the system boot time, expressed in seconds since the epoch.
Boot time is the time taken by the system to be operational once the power is switched on.
Let’s look at the signature for this method:
psutil.boot_time()
This method takes no parameters.
Let’s look at a code example of this method:
import psutil, datetimeprint("The system boot time is: ")bt = psutil.boot_time()print(bt, end="")print(" seconds")print("Formatting time: ")print(datetime.datetime.fromtimestamp(bt).strftime("%Y-%m-%d %H:%M:%S"))
psutil
and datetime
modules.boot_time()
method, and store it in the variable called bt
.bt
variable.fromtimestamp
method from the datetime
module to format bt
into a human-readable data format.