Process name and $0

B

Bertram Scharpf

Hi,

the following might be Linux specific.

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

$ ps aux | grep 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
 
B

Bertram Scharpf

Hi,

Am Freitag, 20. Apr 2007, 17:12:06 +0900 schrieb Bertram Scharpf:
Running Irb and having a look into the process table looks
like this:

$ ruby -pe 'sub "\0", "\n"' /proc/30546/cmdline
irb
$ cat /proc/30546/stat
30546 (irb) S ...

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.
[...]
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top