I would like to change the name of the ruby process that gets displayed in the linux/unix top command. I have tried the
$0=\'miname\'
approach
From @jessehz answer, following code work perfect on my linux X86_64. Ruby 1.9.3, 2.0, 2.1, 2.2, 2.3 is tested.
Perfect!
def set_process_name_linux(name)
handle = defined?(DL::Handle) ? DL::Handle : Fiddle::Handle
Fiddle::Function.new(
handle['prctl'.freeze], [
Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP,
Fiddle::TYPE_LONG, Fiddle::TYPE_LONG,
Fiddle::TYPE_LONG
], Fiddle::TYPE_INT
).call(15, name, 0, 0, 0)
$PROGRAM_NAME = name
end
set_process_name_linux('dummy')