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

hello, i'm trying this "proof of concept" script, to make sure i can modify the output of a ps for a given perl script, as stated on perlvar manpage.
$ cat ps_info.pl #!/usr/bin/perl @a = ( "one", "two", "three", "four", "five" ); for (1..50) { print $0 . "," .$a[$c%5]."\n"; $0 = $a[$c%5]; $c++; sleep 2; } exit;
this script outputs:
$ ./ps_info.pl ./ps_info.pl,one one,two two,three three,four four,five five,one one,two two,three three,four four,five five,one one,two two,three
showing that the "$0" is being assigned different values, although, the "ps xww" does not show any difference, it sits there like this the whole time the script runs:
5578 pts/5 S 0:00 /usr/bin/perl ./ps_info.pl
could you monks show me the light ?... what's wrong ? ( this is a Slackware Linux, kernel 2.4.21, perl 5.8.0 )

Replies are listed 'Best First'.
Re: (perlvar) changing program name
by ysth (Canon) on Sep 12, 2004 at 03:39 UTC
    perl581delta:
    Linux

    o Setting $0 works again (with certain limitations that Perl cannot do much about: see "$0" in perlvar)

Re: (perlvar) changing program name
by ccn (Vicar) on Sep 11, 2004 at 20:17 UTC
Re: (perlvar) changing program name
by sintadil (Pilgrim) on Sep 11, 2004 at 21:24 UTC

    hello, i'm trying this "proof of concept" script, to make sure i can modify the output of a ps for a given perl script, as stated on perlvar manpage.

    If you're aiming for any sort of portability across operating systems -- or even different versions of the same operating system -- you should keep in mind that not all systems support modifying this value. Any halfway secure operating system won't let you.

    But what if I want to hide what I'm running from other people? Not being able to change $^X is insecure!

    Reconsider the ethical standpoint of what you're doing, or install a decent operating system (or OS interface) which allows you to hide your processes from other users (except, optionally, the super-user(s) or a select group of administrators).

      The man page for perlvar says:

      On some operating systems assigning to "$0" modifies the argument area that the ps program sees.
      The emphasis being on some

      Printing $0 in your program means nothing. That's the value that your program sees. If, as a side effect, the value ps sees is also modified, you can bet that Perl isn't querying that ps value to show you what it has in $0.

        i /do/ realize this, that's exactly why i've pointed out which Operating System i'm running ( Linux, kernel 2.4.21, distro Slackware ). I don't aim any portability at all, just a script that should be able to inform it's current state on the "ps" output of a linux machine.
      thanks !!! these two comments gave me the answer !!!
      ( or even different versions of the same operating system && Any halfway secure operating system won't let you )
      the script won't work on Slackware, but runs fine on Mandrake Linux ( the target system is RedHat, so another test is needed, but i'm confident it's not "halfway secure" as Slack )
      again, thank you !!!!
        I didn't see anyone mention this. 5.8.0 had a bug under some OSes where setting $0 just didn't work. Linux was one of these affected. This was fixed in some later release, but I don't know which 5.8.x that was.

        I got trapped by this and other bits, needing to wait for a post-5.8.0 release, and then getting hit with "but now the system is too important to risk upgrading." But somehow arranging for the backup second system hasn't been important ...

      But what if I want to hide what I'm running from other people? Not being able to change $^X is insecure!
      excuse me, but where did this quote came from ? not from anywhere in my original post...

        excuse me, but where did this quote came from ? not from anywhere in my original post...

        It was from a hypothetical, stereotypical user who doesn't exist except in my twisted mind. :) Think of it as answering an unasked question before it was asked.

Re: (perlvar) changing program name
by theorbtwo (Prior) on Sep 11, 2004 at 20:21 UTC

    Try using plain "ps", not "ps xww".


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      "plain ps" behaves the same way...
      ps PID TTY TIME CMD 687 pts/5 00:00:00 bash 5632 pts/5 00:00:00 ps_info.pl 5637 pts/5 00:00:00 ps