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

Does anyone know how to get the handlecount of a win32 process using Perl.. I cannot seem to find a Win32 API for it..

Replies are listed 'Best First'.
Re: handlecount of win32 process
by BrowserUk (Patriarch) on Jul 30, 2005 at 00:44 UTC
    #! perl -slw use strict; use Win32::API; Win32::API->Import( 'Kernel32', 'HANDLE GetCurrentProcess( )' ); Win32::API->Import( 'Kernel32', 'BOOL GetProcessHandleCount(HANDLE h, LPDWORD c)' ); my $hProcess = GetCurrentProcess(); my $count = 0; GetProcessHandleCount( $hProcess, $count ) or die $^E; printf "This process is using %d handles\n", $count; __END__ P:\test>479539 This process is using 16 handles

    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".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      Thanks a bunch! I even asked a bunch of windows programmers at work and no one could tell me how. DotNet programmers seem to only know the interface, not the underlying language anymore...
      Here is my implimentation of the same code..
      #! perl -slw use strict; use Win32::API; my $hProcess = getCurrentProcess(); my $cnt=getProcessHandleCount($hProcess); print "handle count=$cnt\n"; ############### sub getCurrentProcess{ my $GetCurrentProcess = new Win32::API("Kernel32", "GetCurrentProc +ess", [], 'N') || return $^E; my $hProcess=$GetCurrentProcess->Call(); return $hProcess; } ############### sub getProcessHandleCount{ my $hProcess = shift; print "hProcess=$hProcess\n"; my $GetProcessHandleCount = new Win32::API("Kernel32", "GetProcess +HandleCount", ['N','P'], 'N') || return $^E; my $rtn=' 'x12; my $ok=$GetProcessHandleCount->Call( $hProcess,$rtn); my $count=unpack("II", $rtn); return $count; }