Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Perl process names on Windows

by monktim (Friar)
on Feb 05, 2004 at 15:15 UTC ( [id://326773]=perlquestion: print w/replies, xml ) Need Help??

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

I don't know why I haven't posted this in SoPW before. It has been bothering me for a long time and I've always accepted it as "just the way things are".

When I look at the Windows NT Task Manager or issue a pslist command I see a nice list of processes named perl.exe and perl respectively. They have their associated PIDs listed along with other information. This all makes sense because the system is running perl.exe and not I can tell which Perl processes are which (or at least which ones are mine) because I log the PID. It would be nice if I could view the Task Manager or pslist and just see my scripts by name (or some other identifying information) instead of looking at the log for the PID and then looking for the PID in the Task Manager. Can this be done without a major hack?

Update: I should have been more specific. The scripts are running in the BACKGROUND. So changing the title on the Window doesn't cut the mustard. Also, I'd like to view the processes using the Task Manager and/or pslist. This is necessary so anyone can view it using "conventional" methods. Thanks again.

Thanks in advance.


Replies are listed 'Best First'.
Re: Perl process names on Windows
by MADuran (Beadle) on Feb 05, 2004 at 16:35 UTC
    The issue is what Microsoft considers a process.
    To Quote MS:

    * A script is not equivalent to a process. Instead, each script runs in an instance of the scripting host process; each time you run a VBScript script, an instance of either Wscript.exe or Cscript.exe is started. If you start five scripts, the Task Manager lists five instances of Wscript.exe. It does not list the names of the individual scripts running in each of these processes.

    End Quote

    I know this is an issue with Java as well and I do believe there is a hack for java. (I think you end up recompling the JRE to get around this, by adding renaming code to the JRE, But I am not certain)

    So your choices are a Major hack or doing as the frist responce said.

    Who needs a spiffy sig
Re: Perl process names on Windows
by boat73 (Scribe) on Feb 05, 2004 at 16:23 UTC
    I have seen how to do that in the past but stopped using it when I found Shipping standalone perl apps on Win32.
    Works great and lets you run your scripts on servers that don't have perl installed eliminating the need to keep all the modules on all servers. This would also show your process as yourperlscript.exe in tlist. Not exactly what you were asking for but thought it might help.

    Edited by BazB: fixed link.

      How does it allow you to run scripts on servers that don't have perl? The page you addressed (put the address in square brackets to make it a link) has caveats that suggest that it merely packs up the script with any required modules and DLLs.

      The PerlMonk tr/// Advocate
Re: Perl process names on Windows
by jbware (Chaplain) on Feb 05, 2004 at 17:26 UTC
    One potential solution: Use the format from the commandline: start "my title" perl, then use tlist (from the reskit) to view a listing, you can see the title you specified. Frankly its cumbersome, but you didn't define how "major" is a "major hack" :)

    - jbWare
Re: Perl process names on Windows
by PodMaster (Abbot) on Feb 06, 2004 at 08:24 UTC
Re: Perl process names on Windows
by Albannach (Monsignor) on Feb 05, 2004 at 17:13 UTC
    I'm lead to believe from what I've read that changing the actual Win32 process name would require a kernel-level driver hack, however if all you want is a nicer name in Task Manager, this works for me:
    use Win32::Console; my $CONSOLE = new Win32::Console(); $CONSOLE->Title($0);
    You might want to take the path off the $0 for a neater result however.

    Update: Silly me, I was thinking of the "Applications" tab of Task Manager, which the above does affect, but of course you want the "Processes" tab to change for background processes, so I fall back on the first statement that there doesn't appear to be a way to do that. Even Microsoft gives examples of making multiple copies of EXE fles with different names in order to help organize the Processes tab information. Hmm, I guess you could have your script look for its own name in the process list, and if it doesn't exist, make a copy of PERL.EXE with its own name, and then re-run itself. Ugly.

    I'd like to be able to assign to an luser

      That didn't change the name in my Task Manager (Win 2K). It did change the title on the window that runs in the foreground. That can also be accomplished with the Windows title command. I'm running the scripts as background processes.

      Update: Thanks Albannach.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://326773]
Approved by neuroball
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-05-22 06:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found