Well, do you know what causes them to "dangle"? Are they all waiting on a lock? If so,
's node should provide a good solution to your problem; i.e., using LOCK_NB and retrying.
Alternatively, you can use alarm(). Signal handling is pretty reliable if you're careful; i.e., instead of dumping loads of potentially non-reentrant code into the handler itself, just set a flag and handle the condition in your main program.