Change the ruby process name in top

后端 未结 7 813
渐次进展
渐次进展 2021-02-18 14:19

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

7条回答
  •  你的背包
    2021-02-18 14:33

    I don't think Ruby has the facility builtin (setproctitle(3)). You should probably try to look at ruby-ffi and create the interface to setproctitle(3).

    EDIT: I know you have your answer but I want to show you some code to use ffi:

    require "ffi"
    #
    module LibC
      extend FFI::Library
    
      attach_function :setproctitle, [:string, :varargs], :void
    end
    
    LibC.setproctitle("Ruby: executing %s", :string, $0)
    

    Does not work on OS X because setproctitle(3) does not exist, works on FreeBSD.

提交回复
热议问题