Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Uses pslist from the open source pstools suite from to produce a hash containing current process data.

Takes a set of key,value pairs. Currently accepts 'process' and 'machine' keys. Will extend with additional pslist options at a later date. NOTE, leading \\ on machine name is optional, and process name should not have an extension.

There probably is a better way to do this, but this tool works on local and remote machines and its really easy to use...


Or maybe that isnt the best excuse?

use strict; use warnings; use constant Process_EXE => 'pslist.exe'; sub process_hash { my %params=@_; my $find_process=quotemeta($params{process}||""); my $machine =($params{machine}||""); $machine="\\\\".$machine if $machine && $machine!~/^\\\\/; open my $process,"pslist.exe $machine |" or die " Cant open pstool +s!"; my %processes; my @field_names=("Name","Pid","Pri","Thd","Hnd","Mem","User Time", +"Kernel Time","Elapsed Time"); while (<$process>) { chomp; my @process_data=split/\s+/; next unless @process_data==9; if ($process_data[1]=~/pid/i) { next } else { my %process; @process{@field_names}=@process_data; $processes{$process_data[0]}=\%process; return \%process if $process_data[0]=~/^$find_process$/i; } } return $find_process ? undef : \%processes; } use Data::Dumper; # All processes on local machine print Dumper(process_hash()); # Process info about explorer print Dumper(process_hash(process=>'explorer')); # Process list from a remote machine print Dumper(process_hash(machine=>'brahma'));

In reply to Win32 Process Info by demerphq

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-14 08:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found