4

I am trying to give my Ruby program a different name. I am running this on OSx with Ruby version 2.1.2-p95. I am looking in the Activity Monitor which I believe uses top, but I am not 100% sure.

I have tried $0 = "My process name", $0 = "My process name\0", $PROGRAM_NAME = "My process name", $0 = "my_process_name". None of which seem to do the trick.

I have also tried:

require "fiddle"
def set_process_name(name)
    Fiddle::Function.new(
        DL::Handle["prctl"], [
            Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP,
            Fiddle::TYPE_LONG, Fiddle::TYPE_LONG,
            Fiddle::TYPE_LONG
        ], Fiddle::TYPE_INT
    ).call(15, name, 0, 0, 0)
end
set_process_name("My process name")

I would love to have a cross-platform way to do this, but I'm mainly after an OSx way right now.


Similar question without satisfactory answer: Change the ruby process name in top

Community
  • 1
  • 1
Automatico
  • 12,420
  • 9
  • 82
  • 110
  • Is specifically top/activity monitor output you want to change or the output from ps ? – Frederick Cheung Jul 30 '14 at 10:38
  • I would like it to change in Activity Monitor as this is where most mac users will be looking. – Automatico Jul 30 '14 at 11:20
  • Too bad, Process.setproctitle only seems to do ps – Frederick Cheung Jul 30 '14 at 11:26
  • Yeah, I found that myself. I have been struggling with this for a bit unfortunately. – Automatico Jul 30 '14 at 11:39
  • Have you managed to find a solution for this? I found some issues that may be relevant at Thoughtbot's [gitsh](https://github.com/thoughtbot/gitsh/issues/41) and the [Ruby issue tracker](https://bugs.ruby-lang.org/issues/10090) – Omar Bahareth May 26 '15 at 10:06
  • I never found a solution for this :( I honestly have just been ignoring it. On windows you can do `START "My name" ruby.exe whatever.rb`, but I have no idea how to achieve this on unix :( – Automatico May 26 '15 at 18:58

1 Answers1

2

I have not found a cross platform way to do it. The closest thing is using Process.setproctitle but on OSX it just works on the command line, not in the Activity Monitor app.

For OSX you will need bundling your script within an App and set the process name on the Info.plist file

Community
  • 1
  • 1
SystematicFrank
  • 16,555
  • 7
  • 56
  • 102