2 ms·
Depends heavily how trusted/untrusted the process is. If you trust the process won't actively try to circumvent you, just fork and call alarm() as the first thi
by vidarh 2y ago
Depends heavily how trusted/untrusted the process is. If you trust the process won't actively try to circumvent you, just fork and call alarm() as the first thing is often enough. You can cancel it, so it's not a precaution against malice.
If you can't trust the process, fork, wait in the parent, and kill the child if it hasn't terminated.
I don't think alarm() is exposed in Ruby, unless it's been added recently, but it's easy enough to add. However since fork + kill is more reliable anyway, it's often a better choice.
- dragonwriter 2y ago> Depends heavily how trusted/untrusted the process is. Timeout is for threads not processes, and not everything that would be done on a thread can be conveniently rewritten to be a separate process.
- vidarh 2y agoIf you want reliable timeouts, that is your tradeoff. There are too many awful failure scenarios to resolve with threads.