Process name and $0

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()' inruby.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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs