class Sys::Proc::System::LinuxGnu::Prctl

Operations on a process

@see man7.org/linux/man-pages/man2/prctl.2.html

~~~~ include <sys/prctl.h>

int prctl(int option, unsigned long arg2, unsigned long arg3,

unsigned long arg4, unsigned long arg5);

~~~~

Constants

PR_GET_NAME

Return the name of the calling thread, in the buffer pointed to by (char *) arg2. The buffer should allow space for up to 16 bytes; the returned string will be null-terminated.

PR_SET_NAME

Set the name of the calling threadThe attribute is likewise accessible via /proc/self/task/[tid]/comm, where tid is the name of the calling thread.

Public Instance Methods

call(*args) click to toggle source

prctl() is called with a first argument describing what to do (with values defined in <linux/prctl.h>), and further arguments with a significance depending on the first one.

@return [Fixnum]

# File lib/sys/proc/system/linux_gnu/prctl.rb, line 61
def call(*args)
  args += ([0] * 5).slice(args.size..-1)

  function.call(*args)
end
getprogname() click to toggle source

Return the name of the calling thread

@return [String]

# File lib/sys/proc/system/linux_gnu/prctl.rb, line 49
def getprogname
  ptr = Fiddle::Pointer.malloc(32, Fiddle::RUBY_FREE.to_i)

  call(PR_GET_NAME, ptr.to_i)
  ptr.to_s
end
setprogname(name) click to toggle source

Set the name of the calling thread

@param [String] name @return [Boolean]

# File lib/sys/proc/system/linux_gnu/prctl.rb, line 40
def setprogname(name)
  name = name.to_s

  call(PR_SET_NAME, name).zero?
end

Protected Instance Methods

function() click to toggle source

@return [Fiddle::Function]

# File lib/sys/proc/system/linux_gnu/prctl.rb, line 70
def function
  config = {
    handle: helper.get(:lib_c).dlopen['prctl'],
    args: [Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP,
           Fiddle::TYPE_LONG, Fiddle::TYPE_LONG, Fiddle::TYPE_LONG],
    ret_type: Fiddle::TYPE_INT
  }

  Fiddle::Function.new(*config.values)
end