I have a program which created 10 different threads. Now, when a user press ctrl+c on this script I have written an interrupt handler in this $SIG{INT} = 'INT_HANDLER' which calls the subroutine 'INT_HANDLER'.
But when threads are running, the INterrupt handler is not triggered.
Just want to check if Threads have something to do with interrupt handler signals?
This is my Program:
use strict;
use threads;
my @threadsArr;
$SIG{INT} = 'INT_HANDLER';
for (my $ii = 0; $ii < 10; $ii++) {
my $Thread = threads->new( "Thread_SUB", $arg1, $arg2 );
push (@ThreadsArr, $Thread);
}
foreach (@ThreadsArr) {
$_->join();
}
sub INT_HANDLER {
print "Received Interrupt, Stopping the Program.\n";
}
sub Thread_SUB {
my $arg1 = shift;
my $arg2 = shift;
print "$arg1 - $arg2\n";
sleep 200;
}
When this code is executing and Thread_SUB is sleeping and I press CTRL+C, the SIG{INT} is not triggered and thus the Print line in "INT_HANDLER' is not printed.