How to set command line value via Ruby to see status via PS?
Asked Answered
S

1

7

I'd like to provide feedback for my pinger program via the command line and view it using ps ax.

I found a SO q. But

....
ARGV[0] = "Hello!" # does nothing

I'm starting the script via ruby ./pinger

Screens answered 19/9, 2011 at 21:52 Comment(3)
I doubt you could do that w/o modifying Ruby itself.Ctenidium
@Dave: You can assign to $0, that's the Ruby equivalent of C's argv[0], Ruby's ARGV just holds the arguments.Montemontefiascone
@Dave: This $0 stuff is probably inherited from Perl.Montemontefiascone
M
9

Assign to $0 instead. For example, if I start irb and

$ ps | egrep 'irb|pancakes'
 3119 ttys000    0:01.02 irb 
 3131 ttys001    0:00.00 egrep irb|pancakes

and then over in irb:

>> $0 = 'pancakes'

and back to the other terminal:

$ ps | egrep 'irb|pancakes'
 3119 ttys000    0:01.07 pancakes 
 3135 ttys001    0:00.00 egrep irb|pancakes

You can check with this tiny script as well:

#!/usr/bin/env ruby
$0 = 'pancakes'
sleep 10

Run that, jump to another terminal, do a ps | grep pancakes, and you should see a pancakes process.

Montemontefiascone answered 19/9, 2011 at 22:24 Comment(1)
@rm-rf: I got tired of foo so I switched to pancakes. Besides, I like pancakes :)Montemontefiascone

© 2022 - 2024 — McMap. All rights reserved.