Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Process mgmt on WinNT

by uncleben (Novice)
on Mar 12, 2002 at 22:11 UTC ( #151252=perlquestion: print w/replies, xml ) Need Help??

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

Greetings,

I've been tasked with writing a log rotation script for a process on some of our NT servers. What I need to do is make sure that the process stops prior to rotating the script. What I am wondering is whether or not there is a module for getting process lists on Win32 machines and/or stopping processes on the same. I'd like to accomplish this using as few system calls as possible. Thanks in advance.

Regards,
uncleben

Replies are listed 'Best First'.
Re: Process mgmt on WinNT
by Kanji (Parson) on Mar 12, 2002 at 23:35 UTC
Re: Process mgmt on WinNT
by Moonie (Friar) on Mar 12, 2002 at 22:37 UTC
Re: Process mgmt on WinNT
by Rex(Wrecks) (Curate) on Mar 13, 2002 at 00:12 UTC
    You might also want to have a look at the Active State site and Win32::Process and Proc::Background::Win32, this should give you something to go on, searching the mailing lists is a good idea too. tlist.exe from the ResKit is the easiest way I know to do this though, unfortunatly that would mean 1 system call, after that Win32::Process can handle the rest.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: Process mgmt on WinNT
by strat (Canon) on Mar 13, 2002 at 13:15 UTC
    I think, Win32::Process just helps you if you've started this Process with Win32::Process...

    For fetching Win32-Processes, there are several possibilities, e.g.

    #!perl -w use strict; use Win32::OLE qw(in); #Mode: Window Management Instrumentation (WMI) # processproperties my @properties = qw(Caption CreationClassName CreationDate CSCreationC +lassName CSName Description ExecutablePath ExecutionState Handle HandleCount InstallDate KernelModeTime MaximumWorkingSetSi +ze MinimumWorkingSetSize Name OSCreationClassName OSName OtherOperationCount OtherTransferCount PageFaults PageFile +Usage ParentProcessId PeakPageFileUsage PeakVirtualSize PeakWork +ingSetSize Priority PrivatePageCount ProcessId QuotaNonPagedPoolUsage QuotaPagedPoolUsage QuotaPeakNonPagedPoolUsage QuotaPeakPa +gedPoolUsage ReadOperationCount ReadTransferCount SessionId Status Term +inationDate ThreadCount UserModeTime VirtualSize WindowsVersion Workin +gSetSize WriteOperationCount WriteTransferCount); # processmethods my @methods = qw(Create Terminate GetOwner GetOwnerSid); my $server = ''; # local machine my $locatorObj = Win32::OLE->new('WbemScripting.SWbemLocator') or die ("Error in creating locator object: ".Win32::OLE->LastError +()."\n"); $locatorObj->{Security_}->{impersonationlevel} = 3; my $serverObj = $locatorObj->ConnectServer($server, 'root\cimv2') or die ("Error in creating server object: ".Win32::OLE->LastError( +)."\n"); my $procSchema = $serverObj->Get('Win32_Process'); #@properties = map{ $_->{Name} } (in $procSchema->{Properties_}); #@methods = map{ $_->{Name} } (in $procSchema->{Methods_}); foreach my $process (in $serverObj->InstancesOf("Win32_Process")){ foreach (@properties){ printf ("'%20s' => '%s'\n", $_, $process->{$_} || '' ); } print ("-----------------------------------------------\n"); }

    or use: tlist.exe or pstat.exe from WinNT-Reskit

    Best regards,
    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Re: Process mgmt on WinNT
by Anonymous Monk on Mar 13, 2002 at 03:23 UTC
    What I am wondering is whether or not there is a module for getting process lists on Win32 machines and/or stopping processes on the same.

    This question tells me you haven't read How To Read The Friendly Manual, so I'd like to ask you to please do so now (you'll thank me later).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2022-07-04 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?