http://qs1969.pair.com?node_id=92625

deprecated has asked for the wisdom of the Perl Monks concerning the following question:

Hiya, Monks!

I have a bunch of perl scripts that have runtimes that extend past 24 hours. Mostly I am reading tape drives and passing hundreds of gigs through thumbnailing and conversion utilities. Usually I just run these out of my terminal window. However, my laptop is prone to crashing while our servers (ultra 10s) are not. So I run them nohup and watch the output.

There is no TTY input requested (<> for example), but some of my jobs are dying with SIGTTIN. The ever helpful manpage for signal(5) has this to say:

SIGTTIN 26 Stop Stopped (tty input) (see termio(7I))
Now, my feeling here is that the machine thinks my program is asking for input and there is no controlling tty so it is dying.

If his highness tilly doesn't mind, i'd like to have a discussion about signals in perl. And japhy has something to contribute here too because of a discussion we had on fun with perl a few months ago.

$SIG{TTIN} = \&amp;amp;next;
This seems strange. Youre executing next outside of a loop? Well, as I understand it, you can use last to get out of a loop like this:
$SIG{INT} = sub { last };
and in fact, Randal recommended this and said he uses it frequently on a program that may be having a problem in a loop so he can ^C out of the loop -- but not the program. People scorned the "solution", but I think it has a certain elegance to it.

This is all fine and good, but even the perl documentation (I forget which doc at the moment) mentions that Solaris is among the unixen with hopelessly b0rked signals. And, I've been bitten by this before.

So what I'd like to do is catch this SIGTTIN and skip whatever my code is doing that is pissing solaris off.

Comments? Ideas?

brother dep.

--
Laziness, Impatience, Hubris, and Generosity.

Replies are listed 'Best First'.
Re: Signal (SIGTTIN) in Solaris 8. (code)
by japhy (Canon) on Jun 29, 2001 at 18:49 UTC
    The "nicer" solution was to do:
    eval { local $SIG{EVILSIG} = sub { die "EVILSIG\n" }; # ... }; die $@ if $@ and $@ ne "EVILSIG\n";


    japhy -- Perl and Regex Hacker
Re (tilly) 1: Signal (SIGTTIN) in Solaris 8. (code)
by tilly (Archbishop) on Jun 29, 2001 at 18:57 UTC
    Loop control statements can be used in functions called from loops and it works. It is documented as not supported (the behaviour may change) but it does work.

    However signals are a different story. I don't know the status of Perl and safe signals in the development branch. Most assuredly the production version doesn't have them. So adding signal handlers, well you may reduce your problem but won't solve it.

    Personally my solutions to the needed input issue are to try tying STDIN to an implementation that will confess away to give you an idea where in your program you are asking for input but shouldn't be. There is a good chance that that won't work though. Alternately I would just pipe /dev/null into your program. I have done that before, mainly to handle system calls to code outside of my control that might try to interact.