[vox-tech] signal in perl not being caught

Jeff Newmiller vox-tech@lists.lugod.org
Tue, 14 May 2002 11:20:40 -0700 (PDT)


On Tue, 14 May 2002, Peter Jay Salzman wrote:

> i'd like to catch a control-c to stop this wrapper program to a grinding
> halt.   for some reason it's not catching control-c.
> 
> what's wrong with this code snippet?

hmm...

> pete
> 
> 
> #!/usr/bin/perl -w
> use strict;
> use diagnostics;
> 
> # Basic Variables

No, that would be "Dim T As Single : Let T = 4.0" :)

> my $T = 4.0;
> my $runs = 25;
> 
> # Other Variables, tests and misc
> my $result_file = "results";
> my $program =  "./ising2-pbc";
> my ($temp, $i);
> if (-r $result_file) { unlink($result_file); };
> if (! -r $program  ) { system("make");       };
> $SIG{INT} = sub { die("caught sigint.  aborting."); };

detail: should have newline in die string to avoid cancelling the process
before the message gets flushed out to the terminal.

> 
> for ($i=0; $i<$runs; ++$i)
> {
>    print("Run $i/$runs, T: $T\n");
>    system("$program $T > $result_file");

The use of "system" involves handing over the terminal to the program,
thereafter directing signal handling to that program.

Perhaps you want to use backticks so you can keep control of the
terminal?

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------