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!


In reply to Catching Kill Process by Jabox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.