Change the ruby process name in top Change the ruby process name in top unix unix

Change the ruby process name in top


Dave Thomas had an interesting post on doing this in rails. There's nothing rails specific about the actual process name change code. He uses the $0='name' approach. When I followed his steps the name was changed in ps and top.

In the post he suggests using the c keyboard command if your version of top doesn't show the short version of the command by default.


Ruby 2.1 introduced a Process.setproctitle method for this purpose:

Process.setproctitle("My new title")


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], :voidendLibC.setproctitle("Ruby: executing %s", :string, $0)

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