Perl FAQ 5.23: Is there a way to hide perl's command line from programs such as "ps"?

Perl FAQ 5.23

Is there a way to hide perl's command line from programs such as "ps"?

Generally speaking, if you need to do this you're either using poor programming practices or are far too paranoid for your own good. If you need to do this to hide a password being entered on the command line, recode the program to read the password from a file or to prompt for it. (see question 4.24) Typing a password on the command line is inherently insecure as anyone can look over your shoulder to see it.

If you feel you really must overwrite the command line and hide it, you can assign to the variable ``$0''. For example:

    #!/usr/local/bin/perl
    $0 = "Hidden from prying eyes";

    open(PS, "ps |") || die "Can't PS: $!";
    while () {
        next unless m/$$/;
        print
    }

It should be noted that some OSes, like Solaris 2.X, read directly from the kernel information, instead of from the program's stack, and hence don't allow you to change the command line.


Other resources at this site: