开发者

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

开发者 https://www.devze.com 2023-04-06 12:56 出处:网络
I\'d like to provide feedback for my pi开发者_开发知识库nger program via the command line and view it using ps ax.

I'd like to provide feedback for my pi开发者_开发知识库nger 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号