Did you try running my example above? It produces all the information you require.

Learn to use Data::Dumper to inspect anything you do not understand. It is verbose, but clearly displays the structures involved.

See also Tye's References quick reference for the syntax required to use them.

Anyhow, here's an annotated version that should be reasonable to follow, though you will have to get up to speed on Perl's datasteuctures quite quickly as W::P::I makes heavy use of them.

#! perl -slw use strict; use Data::Dumper; use Win32::Process::Info; ## Get an array of hashes for every process in the system my @info = Win32::Process::Info->new ->GetProcInfo({no_user_info=>1}); ## The hashes contain all the information you will ever need! ## This displays the fields available for one of the processes print Dumper $info[ 0 ]; my @notepads; ## A place to hold the hashes that match the name for my $procRef ( @info ) { ## Scan them all ## Extract the Name, ProcessId KernelModeTime & UserModeTime value +s ## Using a hash slice my( $name, $pid, $kcpu, $ucpu ) = @{ $procRef }{ qw[Name ProcessId KernelModeTime UserModeTime ] + }; if( $name =~ m/notepad/i ) { ## If it matches the name you are loo +king for ## Add an anon. array containing the PID and the combined Kern +elMode ## & UserMode time to the array push @notepads, [ $pid, $kcpu + $ucpu ]; } } die 'There are no notepads runnning' unless @notpads; ## Sort the @notepads Array of Arrays (AoA) by cpu utilisation, descen +ding. @notepads = sort{ $b->[ 1 ] <=> $a->[ 1 ] } @notepads; ## The first element (PID) of the first @notepads element ## has the highest cpu utilisation, so kill it. ## On win32, any signal other than 0, 2, & 21 seems to be fatal. ## There may be other non-fatal signals, but it is boring testing for +them. kill 1, $notepads[ 0 ][ 0 ];

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.

In reply to Re^3: Win32: Multiple processes with the same name by BrowserUk
in thread Win32: Multiple processes with the same name by n8wood

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.