溫馨提示×

psutil python如何獲取系統信息

小樊
92
2024-12-06 20:35:17
欄目: 編程語言

要使用Python的psutil庫獲取系統信息,首先需要安裝psutil庫

pip install psutil

接下來,你可以使用以下代碼示例來獲取各種系統信息:

import psutil

# 獲取系統名稱
system_name = psutil.os.name()
print(f"系統名稱: {system_name}")

# 獲取系統版本
system_version = psutil.os.version()
print(f"系統版本: {system_version}")

# 獲取系統架構
system_architecture = psutil.os.arch()
print(f"系統架構: {system_architecture}")

# 獲取CPU信息
cpu_info = psutil.cpu_info()
print(f"CPU信息: {cpu_info}")

# 獲取CPU使用率
cpu_usage = psutil.cpu_percent()
print(f"CPU使用率: {cpu_usage}%")

# 獲取內存信息
memory_info = psutil.virtual_memory()
print(f"內存信息: {memory_info}")

# 獲取磁盤信息
disk_info = psutil.disk_usage('/')
print(f"磁盤信息: {disk_info}")

# 獲取網絡接口信息
network_interface_info = psutil.net_if_addrs()
print(f"網絡接口信息: {network_interface_info}")

# 獲取當前進程列表
process_list = psutil.process_iter(['pid', 'name', 'cpu_percent'])
print("當前進程列表:")
for process in process_list:
    print(process)

這個代碼示例將輸出一些基本的系統信息,如系統名稱、版本、架構、CPU和內存使用情況、磁盤空間和網絡接口信息。你可以根據需要調整代碼以獲取更多詳細信息。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女