Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: monitor iperf from perl

by ig (Vicar)
on Nov 15, 2013 at 01:10 UTC ( [id://1062674]=note: print w/replies, xml ) Need Help??


in reply to monitor iperf from perl

You might be able to use Win32::Process.

Here is an example of finding a process (Notepad) by executable name then monitoring it and taking action when it terminates:

use strict; use warnings; use Data::Dumper::Concise; use Win32::Process::List; use Win32::Process; my $p = Win32::Process::List->new(); my %list = $p->GetProcesses(); foreach my $pid (keys %list) { if($list{$pid} eq 'notepad.exe') { my ($obj, $iflags); Win32::Process::Open($obj, $pid, $iflags) or die "Win32::Process::Open failed"; $obj->Wait(INFINITE); print "Done waiting\n"; exit(0); } } print "Notepad process not found\n";

And here is an example of starting Notepad from Perl, and restarting it when it exits:

use strict; use warnings; use Data::Dumper::Concise; use Win32::Process; my $obj; while(1) { Win32::Process::Create($obj, "C:\\windows\\system32\\notepad.exe", "notepad", 0, NORMAL_PRIORITY_CLASS, ".") or die "Failed to start notepad"; $obj->Wait(INFINITE); print "Notepad exited - restarting\n"; }

If you want to do something while the process continues to run, you can do that too:

use strict; use warnings; use Data::Dumper::Concise; use Win32::Process; my $obj; while(1) { Win32::Process::Create($obj, "C:\\windows\\system32\\notepad.exe", "notepad", 0, NORMAL_PRIORITY_CLASS, ".") or die "Failed to start notepad"; while(1) { $obj->Wait(10000); my $exit_code; $obj->GetExitCode($exit_code); if($exit_code == Win32::Process::STILL_ACTIVE()) { print localtime() . ": Do something while notepad runs\n"; } else { print localtime() . ": Do something when notepad terminate +s\n"; last; } } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found