[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: $0 is truncated

Yukihiro Matsumoto

5/16/2009 7:28:00 PM

Hi,

In message "Re: $0 is truncated"
on Sun, 17 May 2009 02:22:45 +0900, Brian Candler <b.candler@pobox.com> writes:

|This is under Linux (Ubuntu Hardy).
|
|Yes, I'm aware that maybe setproctitle has limits, but it's also useful
|to set $0 to a longer Ruby string (even if that's not fully reflecting
|in the proctitle), because another piece of Ruby code in the same
|process may be testing the value of $0.
|
|In ruby 1.8.6, I can use $0.replace("any long string") which works just
|fine for setting $0 - presumably not setting the proctitle of course.
|But this stopped working in 1.8.7/1.9 because $0 is frozen.

OK, choose either from the following.

[ ] it's OK (for you) that $0 is not corresponding to process name
read by ps etc. at all, i.e. if you set $0 longer than the
limit, $0 will be updated but the proc title will not.

[ ] it's OK (for you) that $0 is not always corresponding to process
name read by ps etc.; in this case if you set $0 longer than the
limit, $0 will be updated but the proc title will be truncated to
the limit.

[ ] it's important for you to just update the $0, so that $0 string
should not be frozen to allow replacing. When you replace $0
string, you'd take the responsibility.

matz.


5 Answers

Brian Candler

5/16/2009 8:37:00 PM

0

Yukihiro Matsumoto wrote:
> [ ] it's OK (for you) that $0 is not always corresponding to process
> name read by ps etc.; in this case if you set $0 longer than the
> limit, $0 will be updated but the proc title will be truncated to
> the limit.

Yes, that would be my preferred option.

I don't mind whether $0 is frozen. Actually, I wrote $0 = ...
originally, and only changed it to $0.replace(...) as a workaround.

Regards,

Brian.
--
Posted via http://www.ruby-....

Eric Hodel

5/16/2009 11:24:00 PM

0

On May 16, 2009, at 13:36, Brian Candler <b.candler@pobox.com> wrote:

> Yukihiro Matsumoto wrote:
>> [ ] it's OK (for you) that $0 is not always corresponding to process
>> name read by ps etc.; in this case if you set $0 longer than the
>> limit, $0 will be updated but the proc title will be truncated
>> to
>> the limit.
>
> Yes, that would be my preferred option.
>
> I don't mind whether $0 is frozen. Actually, I wrote $0 = ...
> originally, and only changed it to $0.replace(...) as a workaround.

In this case, why is it important that you check $0? Why not use any
other global variable?

Yossef Mendelssohn

5/17/2009 1:15:00 AM

0


On May 16, 6:24=A0pm, Eric Hodel <drbr...@segment7.net> wrote:
> In this case, why is it important that you check $0? Why not use any =A0
> other global variable?

I'm guessing it has to do with the bit in the original post where he
said "Test::Unit gets the test suite name from $0".

--
-yossef

Nobuyoshi Nakada

5/17/2009 2:28:00 AM

0

Hi,

At Sun, 17 May 2009 05:36:39 +0900,
Brian Candler wrote in [ruby-talk:336729]:
> I don't mind whether $0 is frozen. Actually, I wrote $0 = ...
> originally, and only changed it to $0.replace(...) as a workaround.

You can find a hint in ext/extmk.rb.

$progname = $0
alias $PROGRAM_NAME $0
alias $0 $progname

trace_var(:$0) {|val| $PROGRAM_NAME = val} # update for ps

--
Nobu Nakada

Brian Candler

5/17/2009 10:48:00 AM

0

Nobuyoshi Nakada wrote:
> Hi,
>
> At Sun, 17 May 2009 05:36:39 +0900,
> Brian Candler wrote in [ruby-talk:336729]:
>> I don't mind whether $0 is frozen. Actually, I wrote $0 = ...
>> originally, and only changed it to $0.replace(...) as a workaround.
>
> You can find a hint in ext/extmk.rb.
>
> $progname = $0
> alias $PROGRAM_NAME $0
> alias $0 $progname
>
> trace_var(:$0) {|val| $PROGRAM_NAME = val} # update for ps

Wow, that's a trick I wouldn't have thought of in a hundred years :-)
Thank you.
--
Posted via http://www.ruby-....