Skip to content

Instantly share code, notes, and snippets.

@JakeStanger
Created March 20, 2017 20:52
Show Gist options
  • Save JakeStanger/e0f4ed8eb4e00b16c341d8fedb2880c2 to your computer and use it in GitHub Desktop.
Save JakeStanger/e0f4ed8eb4e00b16c341d8fedb2880c2 to your computer and use it in GitHub Desktop.
Stresses appropriate CPU cores to display a given number in binary using CPU cores
import time
import os
CORE_LIST = (0, 1, 2, 3, 4, 5, 6, 7)
number = 100
while number <= 0 or number > 255:
number = eval(input("Enter number between 1 and 255: "))
binary = list('{0:0b}'.format(number))
while len(binary) < 8: binary.insert(0, 0)
print(binary)
coresToEnable = ""
cpus = 0
for i in range(len(binary)-1, -1, -1):
if int(binary[i]) == 1:
coresToEnable += (str(CORE_LIST[i]) + ",")
cpus += 1
coresToEnable = coresToEnable[:-1]
print(coresToEnable)
command = "taskset -c " + coresToEnable + " stress --cpu " + str(cpus) + " --timeout 10"
print(command)
os.system(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment