Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

access handle from @info using win32 process info

by grashoper (Monk)
on Apr 24, 2009 at 19:44 UTC ( [id://759905]=perlquestion: print w/replies, xml ) Need Help??

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

I have a need to retrieve the handle, (processid) from win32processinfo for vugen.exe, I am not sure how to get it out of the array, this is so i can pass it to another module for monitoring a process. update ..doh a cpan search yields win32 processlist..I can probably use this for the task..
use Win32::Process::Info; use Data::Dumper; $pi = Win32::Process::Info->new (); $pi->Set (elapsed_in_seconds => 0); # In clunks, not seconds. @pids = $pi->ListPids (); # Get all known PIDs @info = $pi->GetProcInfo (); # Get the max %subs = $pi->Subprocesses (); # Figure out subprocess relationships. @info = grep {$_->{Name} =~ m/vugen/} $pi->GetProcInfo (); # All processes with 'vugen' in name. #print $info; #print $pi; #my $href=\%subs; #print Dumper $href; print Dumper @info; #print Dumper @pids;

Replies are listed 'Best First'.
Re: access handle from @info using win32 process info
by cdarke (Prior) on Apr 25, 2009 at 10:53 UTC
    have a need to retrieve the handle, (processid)

    I'm not wishing to be pedantic, but a handle to a process and the PID (process id) are not the same thing, and I would not wish you to be mislead into thinking they are interchangeable.
    A PID is a system-wide number which uniquely identifies a process - nothing more. A Handle is process-specific (like a file descriptor on UNIX), and gives the owner security permissions to do something with or to the object to which it refers. For example, synchronize (WaitForSingleObject). A handle can only be obtained after a security check and by specifying the actions required. Anyone can get a PID, but you can't do much with it.
    What's more, a process (or thread) will not die until all handles open to it are closed. Failure to close a process handle results in a so-called zombie process (on Windows these are difficult to detect). So if you are getting handles, make sure you close them as soon as you can, although they will be closed when you exit. Win32::Proc::Create is an example where a process handle is obtained.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-29 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found