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

Greetings to you all wise Perl Monks,

ii it possible to change the name of a running perl process to the name of the script that is executed, rather than the name perl. I have some problems identifying several perl processes and it would be handy to know which perl scripts are executed.

Regards,

Andre

20060826 Janitored by Corion: Removed PRE tags, added formatting as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: Changing process name
by BrowserUk (Patriarch) on Aug 26, 2006 at 00:11 UTC

    You haven't identified which OS your running on and the answer will be different on each platform.

    If you're on Win32, then this recent thread may help. If not, you'll probably get good answers from others once you identify the platform.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      The changing of process names should work under Linux and/or 
      Win32, cause these are my target OS. I thought that it may not
      be possible to do such a change, but I was just curious. 
      Futhermore I use wxPerl (wxWidgets) to start subprocesses, so 
      I can't use exec or system.
      
        I use wxPerl (wxWidgets) to start subprocesses, so I can't use exec or system.

        Then how do you "start subprocesses"?

        The probablility is that under Win32, you could system 1, 'perl.exe script.pl'; as this does an asynchronous spawn. Ie. It returns immediately and so does not upset GUI message loops.

        Similarly, you could probably use system 'perl script &'; under Linux to achieve the same end.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Changing process name
by Fletch (Bishop) on Aug 26, 2006 at 00:09 UTC

    For from within the particular process itself see perlvar for $0, but be aware that this doesn't work on all OSen.

    If you have control over what's starting the processes, the block form of exec will let you set the argv[0] the OS sets. However again depending on the OS this might not work the way you want either.

Re: Changing process name
by polettix (Vicar) on Aug 26, 2006 at 00:10 UTC
    Linux 2.6.x and Perl 5.8.8, don't know anything about other OS/Perl version combinations:
    #!/usr/bin/perl # # start as: # # shell$ perl changename.pl use strict; use warnings; print "ok, let me start...\n"; system "ps afx | grep ^$$"; # Assign to $0 and the magic's done! $0 = 'changed!'; print "it should have changed so far...\n"; system "ps afx | grep ^$$"; __END__ poletti@PolettiX:~/sviluppo/perl$ perl changename.pl ok, let me start... 21058 pts/4 S+ 0:00 | \_ perl changename.pl it should have changed so far... 21058 pts/4 S+ 0:00 | \_ changed!

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.