Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Determining Process Information of Win process

by bit.surfer (Initiate)
on Jun 15, 2015 at 02:49 UTC ( #1130411=perlquestion: print w/replies, xml ) Need Help??

bit.surfer has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have a perl script which repeatedly calls an application I have written. Each time I pass different arguments to my application (i.e. number of threads to use or different input parameters). I'm trying to figure out how to capture the process information such as the number of I/O read /write bytes and other information that is available in the task manager. Loosely, my script is as follows (I've edited to abbreviate it - such as my command construction and some post-processing).

I've tried to use the Win32::Process::Info module - but just don't seem to be able to make it work. In the code below I want to determine the process information of the command executed by "system" at the point it is finishing (i.e. I want the final values). Any pointers?
Thx.

#!/usr/bin/perl use Win32::Process::Info; use strict; use warnings; my @models = { "model1", "model2"}; my @cpus = ( 2, 4); foreach my $model (@models) { foreach my $cpu (@cpus) { my $cmdstring = "\"myapp.exe\""; $cmdstring .= " NPROCESSORS=$cpu"; $cmdstring .= " $model"; $cmdstring .= " > nul"; system($cmdstring); } }

Replies are listed 'Best First'.
Re: Determining Process Information of Win process
by salva (Canon) on Jun 15, 2015 at 06:25 UTC
    You would probably be able to use Win32::API to access the OS functions providing that information. You would have to use OpenProcess to get a handle to the process from its PID and then, the functions detailed here to read its information. Finally, you would have to release the handle using CloseHandle.

    I have some code doing something similar here.

    BTW, my knowledge of Windows is quite limited. Take my advice with care!

      You would probably be able to use Win32::API to access the OS functions providing that information.

      That's exactly what Win32::Process::Info does.

      If that module is not working for him, it probably comes down to a problem with Win32::API, not working on his system.

      And the most likely cause of that is a mismatch between the version of Win32::API and the perl he is using. Eg, One built with MSVC and the other with MinGW.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
      In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
Re: Determining Process Information of Win process
by Anonymous Monk on Jun 15, 2015 at 03:12 UTC

    I've tried to use the Win32::Process::Info module - but just don't seem to be able to make it work

    This isn't reflected in your program :/

    ? why not ask taskman for this info, or pslist.exe or procexp.exe ?

      I've tried to use the Win32::Process::Info module - but just don't seem to be able to make it work

      This isn't reflected in your program :/

      I didn't want to start a conversation on something that wasn't working. I'd rather not prejudice any response around my bad attempt.

      I will take a look at taskman, pslist.exe and procexp.exe also. I'm a relative newbie to Windows so I wasn't aware of these. Much happier doing this in Linux. I want the information so I can store it in a file for later usage.
      Thx.
Re: Determining Process Information of Win process (a simpler solution)
by Discipulus (Abbot) on Jun 15, 2015 at 15:33 UTC
    Maybe there is a simple solution to this. Add END{ system qq(tasklist /v /fo LIST /fi "PID eq $$") } to your child code and you'll have some useful info. If you want the whole mess of infos add instead END{ system qq(wmic  PROCESS where "processid=$$" get * /FORMAT:LIST) }
    #cat child.pl use strict; use warnings; print "I'm the child with PID $$\n"; sleep 3; print "Exit now.." and exit 0; #END{ system qq(tasklist /v /fo LIST /fi "PID eq $$") } END{ system qq(wmic PROCESS where "processid=$$" get * /FORMAT:LIST) +} # call it from a oneliner perl -e "system ($^X, qq(child.pl))" I'm the child with PID 298184 Exit now.. Caption=perl.exe CommandLine=C:\Perl\bin\perl.exe child.pl [...] ProcessId=298184 [...]

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Determining Process Information of Win process
by Bloodnok (Vicar) on Jun 15, 2015 at 15:41 UTC
    Not quite answering your question, but I've always found the following 2 books authored by Dave Roth to be more than very useful where Windoze is concerned...
    • "Win32 Perl Scripting The Administrator's Handbook", ISBN: 1-57870-215-1
    • "Win32 Perl Programming The Standard Extensions", ISBN: 1-57870-216-X

    A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2022-05-23 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?