cancel
Showing results for 
Search instead for 
Did you mean: 

Perl daemon question

Josef Forman
Frequent Advisor

Perl daemon question

Hi,
i wrote small useful (only for me :) perl daemon, but I can't adjust its behaviour for signal HUP. I know i can ignore signal by setting...
$SIG{HUP} = 'IGNORE'
, but I need execute my procedure. If i set...
$SIG{HUP} = \&catch_signal
then the procedure is executed, but then it is finished with...
Interrupted system call at ./x.pl line...

Is there any possibility to "mask" the signal a nd execute my procedure only?

Thanks for any help
PF
6 REPLIES
Muthukumar_5
Honored Contributor

Re: Perl daemon question

You can try as,

sub catch_signal {
print("Got HUP signal!\n");
}

$SIG{HUP} = 'catch_signal'
for ($x = 0; $x < 10; $x++) {
print("$x\n");
sleep 1;
}

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Perl daemon question

Just put ; after $SIG{HUP} = 'catch_signal' ;)

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Perl daemon question

My try as,

#!/usr/contrib/bin/perl
sub INT_handler {
print("Don't Interrupt!\n");
}

$SIG{HUP} = 'INT_handler';
for ($x = 0; $x < 10; $x++) {
print("$x\n");
sleep 10;
}

# ./tst.pl &
[1] 26431
# 0

# kill -1 26431
Don't Interrupt!
1

hth
Easy to suggest when don't know about the problem!
Josef Forman
Frequent Advisor

Re: Perl daemon question

I have ; at the end :)
You can check torso of my script...
Muthukumar_5
Honored Contributor

Re: Perl daemon question

Ok. Keep continuing with this flow. Get back if you have any problem.

Note: Post this scripting related in hp-ux so that you will more really faster responses.

hth.
Easy to suggest when don't know about the problem!
Ralph Grothe
Honored Contributor

Re: Perl daemon question

Hi Josef,

have you had a look at "perldoc perlipc" yet?

There are plenty of short signal handler sample codes.

Also regard the warning note in perlipc about not re-entrant system libraries.
At least prior to Perl 5.8 signal handlers should implement as little (clean-up) action as possible.

Btw. it's better to stick to your usage of sub refs (i.e. the \& form) than the use of symbolic refs of Muthu
(although if you didn't use strict 'refs', and stayed in the same package scope you probably wouldn't notice a difference).

Madness, thy name is system administration