Skip to content

Instantly share code, notes, and snippets.

@robobenklein
Last active June 7, 2022 05:11
Show Gist options
  • Save robobenklein/26306aaf733343a28ae8bb7bfd02cecc to your computer and use it in GitHub Desktop.
Save robobenklein/26306aaf733343a28ae8bb7bfd02cecc to your computer and use it in GitHub Desktop.
Watch your PIDs for changes to the niceness after they've started.
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