Hacker News new | past | comments | ask | show | jobs | submit login

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.




> 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.


If you want reliable timeouts, that is your tradeoff. There are too many awful failure scenarios to resolve with threads.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: