Sha256: 8b10aad7293d924fa874844a44d9ca24ee8fdfde444639516b58581a40f22011

Contents?: true

Size: 996 Bytes

Versions: 3

Compression:

Stored size: 996 Bytes

Contents

module Adhearsion

  # https://gist.github.com/1350729
  #
  # Eric Lindvall <eric@5stops.com>
  # 
  # Update the process name for the process you're running in.
  #
  # $0    => updates proc name for ps command
  # prctl => updates proc name for lsof, top, killall commands (...)
  #
  # prctl does not work on OS X
  #
  module LinuxProcName
    # Set process name
    PR_SET_NAME = 15

    class << self
      attr_accessor :error

      def set_proc_name(name)
        $0 = name # process name in ps command
        if error
          logger.warn error
          return false
        end
        return false unless LibC.respond_to?(:prctl)

        # The name can be up to 16 bytes long, and should be null-terminated if
        # it contains fewer bytes.
        name = name.slice(0, 16)
        ptr = FFI::MemoryPointer.from_string(name)
        LibC.prctl(PR_SET_NAME, ptr.address, 0, 0) # process name in top, lsof, etc
      ensure
        ptr.free if ptr
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-2.0.0.beta1 lib/adhearsion/linux_proc_name.rb
adhearsion-2.0.0.alpha3 lib/adhearsion/linux_proc_name.rb
adhearsion-2.0.0.alpha2 lib/adhearsion/linux_proc_name.rb