1834324 Members
3134 Online
110066 Solutions
New Discussion

SIG management in PERL

 
SOLVED
Go to solution
Enrico Venturi
Super Advisor

SIG management in PERL

Hello colleagues,
my 1st PERL program is almost completed ;-)

I'd like to set up a signal handler for SIGCHLD exception;
I knew that the hash SIG array should be initialized in such a way:
$SIG(CHLD) = \& my_handler;

The question is:
what have I to do / declare / include to let my program know the SIG hash?? (It's a global hash variable)

thanks
enrico
5 REPLIES 5
H.Merijn Brand (procura
Honored Contributor
Solution

Re: SIG management in PERL

Simple answer: nothing. It's an internal global (magic) hash :)

$SIG{CHLD} = sub { print STDERR "Got sig CHLD\n" };

note that you used the wrong parens. %SIG is a hash, so you will have to use braces.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
A. Clay Stephenson
Acclaimed Contributor

Re: SIG management in PERL

All you have to do is treat it as a hash.

$SIG{CHLD} = \&my_handler;

another example to ignore hangup's:
$SIG{HUP} = 'IGNORE';
If it ain't broke, I can fix that.
Enrico Venturi
Super Advisor

Re: SIG management in PERL

Ok, thanks a lot!
Now I'm receiving continuously signals about children unknown who die .....
Why????? ;-)
A. Clay Stephenson
Acclaimed Contributor

Re: SIG management in PERL

I'm going to go way out on a limb here and tell you "because you have child processes that dying". For example, if you spawn an external command a SIGCHLD is sent when it terminates. Bear in mind, the default behavior for SIGCHLD is to ignore it. It's more typical to choose another signal with which to communicate with a parent process.
If it ain't broke, I can fix that.
H.Merijn Brand (procura
Honored Contributor

Re: SIG management in PERL

Are you using system (), qx//, open "|-", or open "-|" ?

All these cause child processes to be started

# man perlipc

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn