Skip to content

Instantly share code, notes, and snippets.

@caius
Last active September 24, 2015 08:58
Show Gist options
  • Save caius/723293 to your computer and use it in GitHub Desktop.
Save caius/723293 to your computer and use it in GitHub Desktop.
~/bin/rinse_cpus
#!/usr/bin/env ruby
# Only works on OS X
# Spins up enough `yes > /dev/null` instances inside a
# `screen` to use 100% of all your cpu cores
#
# This just starts screen eating your cores, currently
# when you're done you need to kill the screen manually.
require "tempfile"
# Figure out CPU Count
CPUCount = `sysctl machdep.cpu.core_count`.split(": ").last.to_i
# Use a config to start screen
ScreenConfig = <<-EOF
startup_message off
vbell off
#{Array.new(CPUCount) { %{screen -L /bin/sh -c "yes > /dev/null"} }.join("\n")}
EOF
# Write config into a temp file
tfile = Tempfile.new("rinse_cpus.")
tfile.puts ScreenConfig
tfile.close
# Kick off the thing!
system("screen -md -S cpu_rinse -c #{tfile.path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment