Jabox has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks!
I need assistance with a program to catch a kill process, finish the command, and then end script without just getting cut off halfway and not finish. I will try my best to explain
Files : Perl Program, Custom Module.
Perl Program - Asks for "command, Interval, Location"
What I wanted it to do:
Perl Program calls Functions in Custom Module. Module runs "mpstat 5 ." forever.
When using Kill command "Control+C", mpstat will stop, continue to the rest of the code in the module which Creates .html and .png graph files with what ever result mpstat has made.
Finishes.
What it does :
Closes while mpstat is still running, doesn't create files or graphs.
Some code examples:
IN PERL PROGRAM
my $objstat = new CustomModule; $objstat->mpstat('mpstat',$interval,$path) `mv mpstat*.html html/folder`; `mv mpstat*.png png/folder`;
IN MODULE
my $cmd = shift; my $interval = shift; my $path = shift; my $obj = new CustomModule2; `$cmd -P ALL $interval >> $path`; ## uses the command output information and assigns them into arrays## my @pngnames = ( $obj->createGraph($path, $numsamples.. etc etc) ); $obj->writeHTML($path,$numsamples,@pngnames);
So I want the program to just get the information, calls function in module where command is ran until process is killed, then moves the files to designated location
I want to make it where it kills only the 'mpstat' commands if I use the "control+c", the code still continues and does the part where the output information are assigned to arrays and made into html and png files
What I've tried:
my $cmd = shift; my $interval = shift; my $path = shift; my $obj = new CustomModule2; `$cmd -P ALL $interval >> $path`; $SIG{INT} = \&signal_handler; $SIG{TERM} = \&signal_handler; sub signal_handler { ## uses the command output information and assigns them into arra +ys## my @pngnames = ( $obj->createGraph($path, $numsamples.. etc etc) ); $obj->writeHTML($path,$numsamples,@pngnames); }
I gave it a guess to see if it works since I don't understand it and it doesn't work...
Anyone know how to do this or know where I can read up on it? I've been searching around the web and some pages just prints "caught signal" but doesn't really tell me how to make it do what I wanted it to do
Thank you in advance and if it doesn't make sense or need more information let me know please!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Catching Kill Process
by zentara (Cardinal) on Jun 24, 2014 at 16:24 UTC | |
|
Re: Catching Kill Process
by Anonymous Monk on Jun 25, 2014 at 05:02 UTC | |
by Jabox (Sexton) on Jun 25, 2014 at 14:14 UTC | |
by Jabox (Sexton) on Jun 25, 2014 at 15:03 UTC | |
|
Re: Catching Kill Process
by Anonymous Monk on Jun 25, 2014 at 04:02 UTC |