Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

In what OS and Perl version set $0 works?

by gmpassos (Priest)
on Apr 14, 2004 at 06:34 UTC ( [id://344941]=perlquestion: print w/replies, xml ) Need Help??

gmpassos has asked for the wisdom of the Perl Monks concerning the following question:

I need to know in what OS and Perl versions the resource to set $0 works.

I know that it works on:

Linux - Perl-5.8.0 ; Perl-5.8.1 ; Perl-5.8.3
And here's a test script:
$|=1 ; print "$0\n" ; $0 = 'SET_0_WORKS' ; print "$0\n" ; for(0..1000) { sleep(1); print ".\n" ; }
To test, run it than see if 'SET_0_WORKS' appear is the process list. On Linux we type 'ps aux'.

Thanks in advance.

Also this informations can be added to the Perl docs, since we don't see any list of that there.

UPDATE:
The resource to set $0 is to change the information text of the process (let's say title) in the the process table. So, this is not just to see if $0 = foo works, but to see if the change in that variable appear in the process list. I say that because there are a lot of Windows replies saying that it works!

Graciliano M. P.
"Creativity is the expression of the liberty".

Replies are listed 'Best First'.
Re: In what OS and Perl version set $0 works?
by Corion (Patriarch) on Apr 14, 2004 at 07:14 UTC

    Does not work on Solaris 2.8, perl, version 5.005_03 built for sun4-solaris, neither started as perl -w tmp.pl nor as ./tmp.pl. This may be due to a kernel setting that (dis)allows setting of $0...

    I modified the snippet so I can find the PID more easy for grepping:

    #!/usr/bin/perl -w $|=1 ; print "$$: $0\n" ; $0 = 'SET_0_WORKS' ; print "$0\n" ; for(0..1000) { sleep(1); print ".\n" ; }

    Under Windows NT with Perl 5.6.1, it dosen't work, as demerphq already found out.

Re: In what OS and Perl version set $0 works?
by castaway (Parson) on Apr 14, 2004 at 07:08 UTC
    Works on perl 5.6.1, AIX 4.3.3 and AIX 5.2, does not work on HP-UX 11.0.

    C.

Re: In what OS and Perl version set $0 works?
by eserte (Deacon) on Apr 14, 2004 at 09:01 UTC
    See the comment in perlvar about $0 on BSD.

      Yup, here are my results:

        OpenBSD FreeBSD
      OS Version 3.4 5.2.1
      Perl Version 5.8.0 5.8.0
      `ps` shows perl: SET_0_WORKS (perl) SET_0_WORKS (perl)
      `top` shows perl perl

      (Have no NetBSD machine, sorry ;-)

      --
      b10m

      All code is usually tested, but rarely trusted.
Re: In what OS and Perl version set $0 works?
by pelagic (Priest) on Apr 14, 2004 at 08:37 UTC
    Does not work on cygwin version 2.78.2.9 with Perl 5.6.1 (Win NT 4.00.1381).
    Does not work on Win NT 4.00.1381 with Perl 5.005_02.

    pelagic
Re: In what OS and Perl version set $0 works?
by Eyck (Priest) on Apr 14, 2004 at 11:14 UTC
    What's the use, it doesen't work well even when it does work: (linux,5.6) Try:
    perl -le '$0="IT_WORKS";while(1) {}'&
    and look at whats on top of top. That's right, 'perl', and not 'IT_WORKS', although ps aux|grep IT_WORKS seems to indicate it works. So now maybe killall IT_WORKS works? Nope, it doesen't. (To make top recognize the change, press 'c', as 'show command line')

    Am I missing something?

      On Linux top is probably doing something akin to readlink( "/proc/##/exe" ) to get the process name, which wouldn't be changed by mucking with $0 (or by diddling argv[0] from C) since /proc is comming from the kernel's process table directly.

      ( Not that that makes it work, but it at least might explain the behavior. )

Re: In what OS and Perl version set $0 works?
by rob_au (Abbot) on Apr 14, 2004 at 09:45 UTC
    Works on Mac OS X 10.3(.3) with Perl versions 5.6.2 and 5.8.1 (shipping default).

     

    perl -le "print unpack'N', pack'B32', '00000000000000000000001011010000'"

Re: In what OS and Perl version set $0 works?
by CountZero (Bishop) on Apr 14, 2004 at 09:46 UTC
    Works on ActiveState Perl v5.8.3 built for MSWin32-x86-multi-thread running on Windows XP Pro.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Are you sure? Cause I'm pretty sure sure it doesn't. the process list always shows the executable name. You cannot change this on NT.
      I am on Win32 XPPro and AS 5.8.3 and it doesn't work for me.
      When running the program I get this output:

      x:\ActiveState Komodo 2.5\Mozilla\Perl-1.pl SET_0_WORKS

      So it seems to work on my machine. Well at least it produces the expected output (as was asked to check by the OP), but that doesn't mean it DWIM.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: In what OS and Perl version set $0 works?
by Anneq (Vicar) on Apr 14, 2004 at 13:15 UTC

    Works with ActiveState Perl v.5.8.0 on Win2K

    UPDATE:

    It did what I expected it to, but that was not what you were asking.

    Sorry,

    Anne

      I have Win2k here and it doesn't work?! How you see your process table?

      Graciliano M. P.
      "Creativity is the expression of the liberty".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://344941]
Approved by Corion
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found