-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_manager -V2.0.py
More file actions
52 lines (40 loc) · 1.37 KB
/
task_manager -V2.0.py
File metadata and controls
52 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# =====================
# Task Manager (Enhanced)
# =====================
import psutil
import time
import os
def get_system_resources():
cpu_usage = psutil.cpu_percent(interval=1)
mem = psutil.virtual_memory()
mem_used = mem.used / (1024**3)
mem_tot = mem.total / (1024**3)
stats = {
"CPU Usage" : f"{cpu_usage}%",
"Memory Usage" : f"{mem_used:.2f} / {mem_tot:.2f} GB"
}
# Disk Usage
for partition in psutil.disk_partitions():
try:
usage = psutil.disk_usage(partition.mountpoint)
used_gb = usage.used / (1024**3)
total_gb = usage.total / (1024**3)
stats[f"Disk ({partition.mountpoint})"] = f"{used_gb:.2f} / {total_gb:.2f} GB"
except PermissionError:
continue
return stats
def display_loop(refresh=1):
""" Continuously update system stats like real Task Manager """
while True:
os.system("cls" if os.name == "nt" else "clear")
print("===== SYSTEM RESOURCE MONITOR =====\n")
stats = get_system_resources()
for key, value in stats.items():
print(f"{key:<20} : {value}")
print("\nPress Ctrl+C to exit.")
time.sleep(refresh)
if __name__ == "__main__":
try:
display_loop(1)
except KeyboardInterrupt:
print("\nExiting...")