in reply to Catching processes stuck in an apparent loop
Use an alarm. If you need timeouts accurate to a millisecond then I'd suggest ualarm from Time::HiRes but that's probably overkill here.