M
Mark Seger
I have a script that tails a file and on a SIGTERM I want it to exit.
Sounds simple enough. It traps the signal, executes an 'exit', and then
hangs! The real odd thing is one of the modules I'm 'using' is
Time::Local. If I comment it out the script exits on SIGTERM and if it
leave it in it doesn't. The only way I was able to figure this out was
methodically removing pieces of code until it worked correctly and as
you might guess, the last thing I thought of was removing some of the
'use' statements. Anyhow this leads to a few questions:
- does anyone have a clue what this is breaking things?
- how would you have tracked down this problem with the Time module
- how can I make this work correctly AND use Time?
Anyhow, here's a pretty small piece of code that fails! Just comment
out the 'use Time' and it works...
#!/usr/bin/perl -w
use strict;
use Time::Local;
print "PID: $$\n";
$SIG{"TERM"}=\&sigTerm; # default kill command
while(1) {
open TAIL, "tail -f /var/log/aggregate|" or die;
while (my $line=<TAIL>) {
my $x=1;
}
}
sub sigTerm {
print "SIGTERM\n";
exit(1);
}
here's what I see when I execute a 'kill' from another window:
[root@cag-dl380-01 tmp]# ./test9.pl
PID: 13796
SIGTERM
and it's hung... Now if I comment out Time:
[root@cag-dl380-01 tmp]# ./test9.pl
PID: 13799
SIGTERM
[root@cag-dl380-01 tmp]#
-mark
Sounds simple enough. It traps the signal, executes an 'exit', and then
hangs! The real odd thing is one of the modules I'm 'using' is
Time::Local. If I comment it out the script exits on SIGTERM and if it
leave it in it doesn't. The only way I was able to figure this out was
methodically removing pieces of code until it worked correctly and as
you might guess, the last thing I thought of was removing some of the
'use' statements. Anyhow this leads to a few questions:
- does anyone have a clue what this is breaking things?
- how would you have tracked down this problem with the Time module
- how can I make this work correctly AND use Time?
Anyhow, here's a pretty small piece of code that fails! Just comment
out the 'use Time' and it works...
#!/usr/bin/perl -w
use strict;
use Time::Local;
print "PID: $$\n";
$SIG{"TERM"}=\&sigTerm; # default kill command
while(1) {
open TAIL, "tail -f /var/log/aggregate|" or die;
while (my $line=<TAIL>) {
my $x=1;
}
}
sub sigTerm {
print "SIGTERM\n";
exit(1);
}
here's what I see when I execute a 'kill' from another window:
[root@cag-dl380-01 tmp]# ./test9.pl
PID: 13796
SIGTERM
and it's hung... Now if I comment out Time:
[root@cag-dl380-01 tmp]# ./test9.pl
PID: 13799
SIGTERM
[root@cag-dl380-01 tmp]#
-mark