I have a rack/ruby application on a server. I run it as follows:

  nohup rackup -o 0.0.0.0 -p 1234 &

In the output of "top" command it appears as simply "ruby"

PID   USERNAME    THR PRI NICE   SIZE    RES STATE    TIME    WCPU COMMAND

98421  my_user123       3  20    0   140M 29576K select   0:29   0.01% ruby

How can I adjust its name in the "top"? What if I run 5 such web apps, how would I distinguish which is which if they're all "ruby"?

  • 1
    What if I run 5 such web apps, how would I distinguish which is which if they're all "ruby"? - Well... they'd all have a different PID. – joeqwerty Dec 7 '17 at 3:41
  • @joeqwerty, I said - "how would I know which is which" – Kakki Dec 7 '17 at 4:10

It's not the process name you need to adjust, but your tool.

Press c while top is running, or just start it with -c to see full command lines.

For example, without -c:

12329 error     20   0  618748 202472  19424 S   0.0 20.0   7:49.32 ruby

And with -c:

12329 error     20   0  618748 202472  19424 S   0.0 20.0   7:49.32 ruby /home/error/.rvm/gems/ruby-2.2.7@app/bin/thin start -a ::1 -p 8008
  • on linux - yes, that's good. on freebsd - "command not understood". how to do that? – Kakki Dec 7 '17 at 5:19
  • on linux - yes, that's good. on freebsd - "command not understood". how to do that? – Kakki Dec 7 '17 at 7:58
  • 1
    On a FreeBSD just press a in the top. Or better run ps auxwww | grep ruby – Kondybas Dec 7 '17 at 9:16

On systems where it is supported, you can change the name of a process in ruby by assigning to $0 or by using Process.setproctitle (ruby 2.1+).

  • by assigning to $0 -- how? – Kakki Dec 7 '17 at 7:58
  • @Kakki $0 = "something" – hobbs Dec 7 '17 at 8:00
  • that doesn't work $0 = "something" nohup rackup -o 0.0.0.0 -p 1234 &. show the full command – Kakki Dec 9 '17 at 7:07
  • @Kakki ... in the program, of course, not in the shell. – hobbs Dec 9 '17 at 7:30
  • thx, I'll try to – Kakki Dec 9 '17 at 8:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.