Skip to content

Instantly share code, notes, and snippets.

@nomicode
Forked from anonymous/cpulimit.py
Created June 26, 2022 16:47
Show Gist options
  • Save nomicode/8b36fc067397913cd97cc487f7d1bff8 to your computer and use it in GitHub Desktop.
Save nomicode/8b36fc067397913cd97cc487f7d1bff8 to your computer and use it in GitHub Desktop.
reduce the cpu time of a process by pausing and resuming it repeatedly
#!/usr/bin/env python
import time, os, sys, signal
sleeptime = waketime = 0.01
def send(signal, pids):
for pid in pids:
os.kill(pid, signal)
pids = map(int, sys.argv[1:])
while 1:
send(signal.SIGSTOP, pids)
time.sleep(sleeptime)
send(signal.SIGCONT, pids)
time.sleep(waketime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment