in reply to Perl Threads

I don't believe threads can be killed (sanely), so I'd recommend using child processes instead of threads.

Scenario 1: The child processes interface with the database directly and don't tell the parent when they're done.
Solution: You could use wait with a calculated timeout imposed by alarm.

Scenario 2: The child processes let the parent know when they're done, possibly sending the data to the parent instead of interfacing with the database.
Solution: You could use select with a calculated timeout.

Replies are listed 'Best First'.
Re^2: Perl Threads
by jpk236 (Monk) on Nov 06, 2007 at 22:26 UTC
    Thanks for the suggestions. I've looked into alarm, and after looking at a multitude of resources have come up with this working example:

    #!/usr/bin/perl -w use strict; my ($output); eval { local $SIG{ALRM} = sub {die "SSH timeout\n"}; alarm 15; $output = `/usr/bin/ssh -o ConnectTimeout=10 host.domain.com`; alarm 0; }; if ($@) { print "SSH timed out\n"; } else { print "SSH didn't time out\n"; }

    Are there any problems with what I'm doing here?

    - Justin

      It won't work in Windows, and don't use it in threads. Otherwise, it's fine.