Perl alarm signal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl alarm signal
# 1  
Old 01-13-2006
Perl alarm signal

I am trying to write a signal to exit when a process times out. What I have come up with from poking around the web is this.

#!/usr/bin/perl

eval {
local $SIG{ALRM} = sub { die "alarm clock restart" };
alarm 10;

open(DSMADMC, "dsmadmc -se=tsmpc1 -id=XXXXX -pass=XXXXX -commadelimited
<<EOF
select * from summary where schedule_name=\'WEEKLY_ARCHIVE_11PM\' |") or
die "exec: $!\n";
EOF
;
alarm 0;
};
if ($@ and $@ !~ /alarm clock restart/) { die }

while ($line=<DSMADMC>) {
chomp($line);
print ("$line\n");
} #end while

What I am trying to do is that whenver

open(DSMADMC, "dsmadmc -se=tsmpc1 -id=XXXXX -pass=XXXXX -commadelimited
<<EOF
select * from summary where schedule_name=\'WEEKLY_ARCHIVE_11PM\' |") or
die "exec: $!\n";
EOF
;
times out the exit occurs. So far when I set the alarm to 0 to test nothing happens. Can someone set me straight as to what I need to do?
# 2  
Old 01-13-2006
Signal handling is absolutely fine, I don't find any problem with timeout...

Could you please check whether there is any error after the eval block...

eval {
local $SIG{ALRM} = sub { die "alarm clock restart" };
alarm 10;

open(DSMADMC, "dsmadmc -se=tsmpc1 -id=XXXXX -pass=XXXXX -commadelimited
<<EOF
select * from summary where schedule_name=\'WEEKLY_ARCHIVE_11PM\' |") or
die "exec: $!\n";
EOF
;
alarm 0;
};

Add a print statement for $@ after the above block... there could be an error and you are doing die simply without printing it...

Also could you please tell me what is happening when you run this program, it died without any error message ?? or is it printing the lines and time out is not happening ??

I think you are missing "|" in the following command

open(DSMADMC, "| dsmadmc -se=tsmpc1 -id=XXXXX -pass=XXXXX -commadelimited

Last edited by mahendramahendr; 01-13-2006 at 06:55 PM..
# 3  
Old 01-15-2006
Thanks for the reply.

I added a print statement for $@ and shows blank "".

The program does print the expected output, but what I am trying to test is the alarm. I use open(DSMADMC, "dsmadmc -se=tsmpc1 -id=XXXXX -pass=XXXXX -commadelimited
<<EOF
select * from summary where schedule_name=\'WEEKLY_ARCHIVE_11PM\' |") or
die "exec: $!\n";
EOF
;
in a cgi script and send the output to a web page. Sometimes the web page doesn't load and creates a "nobody" process. I was thinking that if I put an alarm on the process to exit if it doesn't return after a certain number of seconds I could avoid creating the "nobody" processed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl: trap signal 'exit': why I am not able to have it work??

First time trying to work with signals in Perl. Reviewing example I try it, but not able to get it work for 'exit'. I hope, I am correct, assuming, that the ending any code by exit $return_code; the $SIG{EXIT} should be de-referenced and processed?! So, I have such code, that, I assume,... (5 Replies)
Discussion started by: alex_5161
5 Replies

2. Shell Programming and Scripting

Scripting an alarm

Hi All, I am monitoring batch Processes running in UNIX environment. I use PuTTy to monitor the process running. I have to continuously monitor and look on the screen if some error has come or not. If an error comes FAILURE word is displayed instead of SUCCESS as shown below on the... (2 Replies)
Discussion started by: sampandey31
2 Replies

3. Shell Programming and Scripting

Perl Signal Handler

I was working on some Perl code that does signal handling and I came across this one liner and wasn't sure what it was doing. local $SIG{__DIE__} = sub {$! = 2; die $_;}; I think the first part of the anonymous subroutine is setting $! to 2, but I am not sure what the second part is doing. ... (1 Reply)
Discussion started by: SFNYC
1 Replies

4. Solaris

Sysedge alarm threshold

Hello, how can we determine alarm threshold from sysedge in a solaris box? can anybody please help me? Thanks, (1 Reply)
Discussion started by: Pouchie1
1 Replies

5. Shell Programming and Scripting

Perl - Problems with Signal Handler

I have a problem with signal handlers not working. I have a long 1000 line code and somehow this code for signal handling is not working: $SIG{INT} = \&interrupt; sub interrupt { print STDERR "Caught a control c!\n"; exit; # or just about anything else you'd want to do } Any... (2 Replies)
Discussion started by: som.nitk
2 Replies

6. Programming

alarm signal processing

I'm writing a function right now, and I want to set an alarm to avoid a timeout, here's the general idea of my code: int amt = -2; alarm(10); amt = read(fd, &t->buf, TASKBUFSIZ - tailpos); //do a read when the alarm goes off, i want to check the value of "amt" ... (1 Reply)
Discussion started by: liaobert
1 Replies

7. Shell Programming and Scripting

Signal handling in Perl

Guys, I'm doing signal handling in Perl. I'm trying to catch ^C signal inside the script. There two scripts : one shell script and one perl script. The shell script calls the perl script. For e.g. shell script a.sh and perl scipt sig.pl. Shell script a.sh looks something like this :... (6 Replies)
Discussion started by: obelix
6 Replies

8. Programming

Basic signal and alarm usage

I am trying to write a program that will; 1) Show the message "Snoozing now...zzzz" on the screen for 5 seconds 2) Then in the same position show the message "The ALARM is going off now!" for 5 seconds 3) Repeat 1) then 2) infinitely until user presses Ctrl C I can't make it work. Any hints... (17 Replies)
Discussion started by: enuenu
17 Replies

9. UNIX for Dummies Questions & Answers

alarm

Hello I have a server HP ES40 with unix 5.1B, and if i open from Start-Programs-IN Tools-GUI/pfmalarm/Alarm-start monitoring , I receive this error message "IOR : STRING IS TOO LONG ! MAXIMUM SIZE = 1024" Anybody heard about this error? Thanks Alin (0 Replies)
Discussion started by: tomaalin
0 Replies

10. UNIX for Dummies Questions & Answers

Alarm signal

Hi, when I execute a script on unix AIX, I've got an error message: "Execution: 85328 Signal d'alarme". If I edit this file with "vi", I ve got the same error after a while (about 1 minute). If I try with another user I still have the problem. But if I rename this file, no problem. My... (5 Replies)
Discussion started by: cgsteph
5 Replies
Login or Register to Ask a Question