# Process name and $0

**URL:** <https://www.ruby-forum.com/t/process-name-and-0/92524>\
**Category:** Ruby\
**Created:** [April 20, 2007, 10:12am UTC](https://www.ruby-forum.com/t/process-name-and-0/92524 "2007-04-20T10:12:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [April 20, 2007, 10:12am UTC](https://www.ruby-forum.com/t/process-name-and-0/92524/1 "2007-04-20T10:12:59Z")

</div>

Hi,

the following might be Linux specific.

Running Irb and having a look into the process table looks  
like this:

$ ps aux | grep [i]rb  
user 30546 1.3 1.0 7880 5328 pts/3 S+ 09:49 0:00 irb  
$ ps -A | grep irb  
30546 pts/3 00:00:00 irb  
$ pgrep irb  
30546  
$ ruby -pe ‘sub “\0”, “\n”’ /proc/30546/cmdline  
irb  
$ cat /proc/30546/stat  
30546 (irb) S …

$ cat /etc/gentoo-release  
Gentoo Base System release 1.12.9

Now, I’m running a daemon written in Ruby that I want to  
appear under its own name rather than “ruby” in ps, pstree,  
top and so forth.

Having a look at Irb’s source code and at  
`rb_define_hooked_variable()' in`ruby.c’ shows me that  
setting $0 does at least partially what I want. It works for  
the ‘ps -A’ call and for the ‘cmdline’ output. ‘pgrep’ still  
doesn’t respond and ‘stat’ still contains “ruby”.

I cannot find it: How does Irb manage to change the process  
name in its higher sense?

Thanks for any hints in advance.

Bertram

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [April 20, 2007, 11:42am UTC](https://www.ruby-forum.com/t/process-name-and-0/92524/2 "2007-04-20T11:42:11Z")

</div>

Hi,

Am Freitag, 20. Apr 2007, 17:12:06 +0900 schrieb Bertram S.:

> top and so forth.  
> […]  
> I cannot find it: How does Irb manage to change the process  
> name in its higher sense?

Just when I had dispatched the posting I found it:  
The shebang line must be the latter of:

#!/usr/bin/env ruby  
#!/usr/bin/ruby

Bertram
