[comp.lang.perl] catching the suspend signal

pfeif@hastings.eecs.umich.edu (Stephen G Pfeiffer) (06/29/91)

Hello perl programmers and hacks.

Can someone help me out with a suspend signal catching subroutine.
What I want is to be able to catch the ^Z or suspend signal from the
shell, perform a subroutine and then perform the actual suspend.

I have some code below.  The problem seems to be that even after I set
the SIG{'TSTP'}= 'DEFAULT'; and kill the pid of the script, the 
subroutine has to return or fall off the end, before the actual suspend 
will occur.  This means that I cannot reset the $SIG variable to 
my suspend handler.  I would like to be able to suspend and 
bring-to-the-forground as many times as necessary while still 
handling the suspend signal.  Presently, I am only able to do 
it once (remove the last SIG statement to get this effect).


#!/usr/local/bin/perl

$SIG{'TSTP'} = 'sushandler';

# SOME code, who cares what.
# .
# .
# .
# .
# .

# This is what I want, but it doesn't work quite right.  The subroutine
# finishes, before the suspend is done.
sub sushandler
{
print "Hey, I caught a suspend signal......\n";
$SIG{'TSTP'} = 'DEFAULT';
kill 'TSTP', $$;
$SIG{'TSTP'} = 'sushandler';
}


Thanks for any help.

-pfeif-  (Stephen G. Pfeiffer @ Departmental Computing Organization UofM)

e-mail:    pfeif@hastings.eecs.umich.edu