Module: Adhearsion::LinuxProcName

Defined in:
lib/adhearsion/linux_proc_name.rb

Overview

gist.github.com/1350729

Eric Lindvall <[email protected]>

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

Constant Summary collapse

PR_SET_NAME =

Set process name

15

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.errorObject

Returns the value of attribute error


21
22
23
# File 'lib/adhearsion/linux_proc_name.rb', line 21

def error
  @error
end

Class Method Details

.set_proc_name(name) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/adhearsion/linux_proc_name.rb', line 23

def set_proc_name(name)
  $0 = name # process name in ps command
  if error
    logger.debug 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