Added interval refresh argument.
This commit is contained in:
1 parent
da58b4374c
commit
462e6f3ce7
1 file changed
+4
-2
+4
-2
@@ -53,7 +53,7 @@ def print_processes(limit):
|
|||||||
clear_screen()
|
clear_screen()
|
||||||
top_processes = get_top_processes(limit)
|
top_processes = get_top_processes(limit)
|
||||||
|
|
||||||
print("CPU % Process Name User")
|
print(" CPU% Process User")
|
||||||
print("----------------------------------------------")
|
print("----------------------------------------------")
|
||||||
|
|
||||||
for (cpu, name, user) in top_processes:
|
for (cpu, name, user) in top_processes:
|
||||||
@@ -75,13 +75,15 @@ def wait_for_keypress(timeout=1.0):
|
|||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Monitor system processes by CPU usage.")
|
parser = argparse.ArgumentParser(description="Monitor system processes by CPU usage.")
|
||||||
parser.add_argument("-n", "--number", type=int, default=10, help="Number of processes to monitor (default is 10).")
|
parser.add_argument("-n", "--number", type=int, default=10, help="Number of processes to monitor (default is 10).")
|
||||||
|
parser.add_argument("-i", "--interval", type=int, default=1, help="Refresh interval in seconds (default is 1).")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
limit = args.number
|
limit = args.number
|
||||||
|
interval = max(1, args.interval)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
print_processes(limit)
|
print_processes(limit)
|
||||||
key = wait_for_keypress(timeout=1.0)
|
key = wait_for_keypress(timeout=interval)
|
||||||
if key and key.lower() == 'q':
|
if key and key.lower() == 'q':
|
||||||
print("Exiting...")
|
print("Exiting...")
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in new issue
Block a user