Last active
June 7, 2022 05:11
-
-
Save robobenklein/26306aaf733343a28ae8bb7bfd02cecc to your computer and use it in GitHub Desktop.
Watch your PIDs for changes to the niceness after they've started.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import psutil | |
nices = {} | |
while True: | |
time.sleep(0.2) | |
for proc in psutil.process_iter(['pid', 'cmdline', 'nice']): | |
try: | |
cur_nice = proc.nice() | |
if proc.pid not in nices: | |
nices[proc.pid] = cur_nice | |
else: | |
if nices[proc.pid] != cur_nice: | |
print(f"Process changed priority at {time.time():.2f}: {nices[proc.pid]} to {proc.nice()}, {proc.pid}: {proc.cmdline()}") | |
nices[proc.pid] = cur_nice | |
except psutil.NoSuchProcess: | |
del nices[proc.pid] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment