package ProcessCleaner ;
# Purpose :
# This class takes as argument the list of processes from the settings.txt file
# specified in the HANGING part checks the current running processes on the agent
# and ends those processes, which match with the list
# This class uses the external executable called Process for more info
# http://www.beyondlogic.org/solutions/processutil/processutil.htm
use QARundefs ;
use QALogger ;
use Win32::Process ;
use Win32 ;
use ProcWatcher ;
our $varHolder = {} ;
sub killProc {
my $self = shift ;
my $procToLookFor = shift ;
$w = new ProcWatcher() ;
my @allProcs = @{$w->getProcs()};
for ( $i= 0 ; $i <$#allProcs; $i++)
{
$current = "$allProcs[$i]";
if ( $_ =~m/$current/i )
{
Win32::Process::KillProcess($allProcs[$i+1] , 1) ; #kill the process by its name
$logger->display("killed only $allProcs[$i] with pid $allProcs[$i+1] \n " );
}
else {;} #do nothing just processId
} #eof for
$logger->debug(" Cleaning processes done !!!") ;
} #eof sub killProc
sub killProcesses {
my @procsToLookFor = split(/ / , $varHolder->{'HANGING'}); #get the names of the hanging apps to check
$w = new ProcWatcher() ;
my @allProcs = @{$w->getProcs()};
for ( $i= 0 ; $i <$#allProcs; $i++)
{
# print "the current proc from all procs is " . $allProcs[$i] . " \n " ;
foreach (@procsToLookFor)
{ $current = "$allProcs[$i]";
if ( "$_" eq "$current" )
{
Win32::Process::KillProcess($allProcs[$i+1] , 1) ;
$logger->display("killed $allProcs[$i] with $allProcs[$i+1] \n " );
}
else {;} #do nothing just processId
} #eof foreach
} #eof for
#
$logger->debug(" Cleaning processes done !!!") ;
} #eof sub killProcesses
sub killMySelf
{
my $self = shift ;
my @MyProcs = qw(SC DayCycle CycleScriptRun MyTest ProcFilter ScriptLoopInv SleepBetweenCycles SleepBetweenScripts); #get the names of the hanging apps to check
$w = new ProcWatcher() ;
my @allProcs = @{$w->getProcs()};
for ( $i= 0 ; $i <$#allProcs; $i++)
{
# print "the current proc from all procs is " . $allProcs[$i] . " \n " ;
foreach (@MyProcs)
{ $current = "$allProcs[$i]";
if ( "$_" eq "$current" )
{
Win32::Process::KillProcess($allProcs[$i+1] , 1) ;
$logger->display("killed $allProcs[$i] with pid $allProcs[$i+1] ") ;
}
else {;} #do nothing just processId
} #eof foreach
} #eof for
#OVERINSURANCE
my $cmd = "process -k SC.exe" ;
`$cmd` ;
$logger->debug(" Cleaning processes done !!!") ;
}
sub killCertainProcesses {
my $self = shift ;
my @procsToLookFor = shift ;
$w = new ProcWatcher() ;
my @allProcs = @{$w->getProcs()};
for ( $i= 0 ; $i <$#allProcs; $i++)
{
# print "the current proc from all procs is " . $allProcs[$i] . " \n " ;
foreach (@procsToLookFor)
{ $current = "$allProcs[$i]";
if ( $_ =~m/$current/i )
{
Win32::Process::KillProcess($allProcs[$i+1] , 1) ;
print "killed $allProcs[$i] with $allProcs[$i+1] pid \n " ;
}
else {;} #do nothing just processId
} #eof foreach
} #eof for
#
$logger->debug(" Cleaning processes done !!!") ;
} #eof sub killCertainProcesses
#purpose to clean the processes as soon as we create the object
#could be called new ProcessCleaner ( \$varHolder ) ;
sub new
{
my $package=shift;
$varHolder = ${ shift @_} ; #get the has containing all the settings
$logger = new QALogger (\$varHolder ) ;
$logger->debug(" Start cleaning processes !!!") ;
killProcesses();
return bless({}, $package);
}
1;
__END__
#######################################################################NEW FILE STARTS
package ProcWatcher ;
use Win32::PerfLib;
our @allProcs = ();
sub new {
my $invocant= shift ;
my $class = ref ($invocant ) || $invocant ; #could be called as object cloning method
my $self = {} ;
bless $self , $class ;
return $self ;
}
sub get
{
shift;
my $name_l = shift;
return $self->{$name_l};
}
sub set
{
shift;
my $name_l = shift;
my $value_l = shift;
$self->{$name_l}=$value_l;
}
sub checkProcs
{
my $self = shift ;
@allProcs = ();
my $server = "";
my $procHolder = {
#holds the flags for each process
SC => 0 ,
DayCycle => 0,
CycleScriptRun => 0 ,
SleepBetweenCycles => 0 ,
SleepBetweenScripts => 0,
ScriptLoopInv => 0,
MyTest => 0 ,
};
Win32::PerfLib::GetCounterNames($server, \%counter);
%r_counter = map { $counter{$_} => $_ } keys %counter;
# retrieve the id for process object
$process_obj = $r_counter{Process};
# retrieve the id for the process ID counter
$process_id = $r_counter{'ID Process'};
# create connection to $server
$perflib = new Win32::PerfLib($server);
$proc_ref = {};
# get the performance data for the process object
$perflib->GetObjectList($process_obj, $proc_ref);
$perflib->Close();
$instance_ref = $proc_ref->{Objects}->{$process_obj}->{Instances};
foreach $p (sort keys %{$instance_ref})
{
$counter_ref = $instance_ref->{$p}->{Counters};
foreach $i (keys %{$counter_ref})
{ if($counter_ref->{$i}->{CounterNameTitleIndex} == $process_id)
{ foreach $key (keys %$procHolder)
{ if ( $instance_ref->{$p}->{Name}=~m/$key/i )
{
printf STDERR ( "% 6d %s\n", $counter_ref->{$i}->{Counter},
$instance_ref->{$p}->{Name} );
$procHolder->{$key}=1 ;
}
else { ; } ; #do nothing
} #eof foreach key
} #eof if($counter_ref...
} #eof foreach $i
} #eof foreach $p
return $procHolder->{'SC'} , $procHolder->{'DayCycle'} ,
$procHolder->{'CycleScriptRun'} , $procHolder->{'SleepBetweenCycles'} ,
$procHolder->{'SleepBetweenScripts'} , $procHolder->{'ScriptLoopInv'} ,
$procHolder->{'MyTest'} ;
} #eof checkProcs
sub getProcs
{
@allProcs = ();
my $self = shift ;
my $server = "";
my $procHolder = {
#holds the flags for each process
SC => 0 ,
DayCycle => 0,
CycleScriptRun => 0 ,
SleepBetweenCycles => 0 ,
SleepBetweenScripts => 0,
ScriptLoopInv => 0,
MyTest => 0 ,
};
Win32::PerfLib::GetCounterNames($server, \%counter);
%r_counter = map { $counter{$_} => $_ } keys %counter;
# retrieve the id for process object
$process_obj = $r_counter{Process};
# retrieve the id for the process ID counter
$process_id = $r_counter{'ID Process'};
# create connection to $server
$perflib = new Win32::PerfLib($server);
$proc_ref = {};
# get the performance data for the process object
$perflib->GetObjectList($process_obj, $proc_ref);
$perflib->Close();
$instance_ref = $proc_ref->{Objects}->{$process_obj}->{Instances};
foreach $p (sort keys %{$instance_ref})
{
$counter_ref = $instance_ref->{$p}->{Counters};
foreach $i (keys %{$counter_ref})
{ if($counter_ref->{$i}->{CounterNameTitleIndex} == $process_id)
{
# printf( "% 6d %s\n", $counter_ref->{$i}->{Counter},
# $instance_ref->{$p}->{Name} );
push(@allProcs , $instance_ref->{$p}->{Name} , $counter_ref->{$i}->{Counter} );
} #eof if($counter_ref...
} #eof foreach $i
} #eof foreach $p
return \@allProcs;
} #eof checkProcs
1;
__END__
#######################################################################NEW FILE ENDS
Getting the Current TabItem when the Tab is not selected in WPF
-
[image: Banner]
This is a quick reminder to self on how to retrieve a TabItem from a WPF
TabControl *when the tab is not currently selected* because I ru...
1 month ago
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!