Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Created December 30, 2015 13:28
Show Gist options
  • Select an option

  • Save sideshowcoder/8057955257e645b7058a to your computer and use it in GitHub Desktop.

Select an option

Save sideshowcoder/8057955257e645b7058a to your computer and use it in GitHub Desktop.
Setting the ruby process name
class ProcessCtrl
module LibC
PR_SET_NAME = 15
extend FFI::Library
ffi_lib "c"
attach_function :prctl, [:int, :pointer, :long, :long, :long], :int
end
class << self
def set_process_name(name)
# The process name is max 16 characters, so get the first 16, and if it is
# less pad with spaces to avoid formatting wierdness
process_name = "%-16.16s" % name
LibC.prctl(LibC::PR_SET_NAME, process_name, 0, 0, 0)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment