On Jan 5, 2008, at 11:41 AM, thefed wrote:

>
> On Jan 5, 2008, at 10:29 AM, Gary Wright wrote:
>
>> Perhaps something like Process::setrlimit is something the OP  
>> could use?
>>
>
> I looked at setrlimit, but it seems to quit the process if it  
> violates the conditions. Will it actually prevent ruby from going  
> over 15% without killing it?

I don't know if setrlimit is appropriate for your use or the OP's use
but it works like...

For RLIMIT_CPU, the limit is the maximum number of CPU seconds.
When the process gets to the (lower) soft limit the OS will send
the SIGXCPU signal, which the process can catch and then do something
(like shutdown).  If the (higher) hard limit is reached, the OS
will terminate the process.  I just tried the following code
on Mac OS X and it worked just fine.  Your milage may vary depending
on how well your OS supports hard/soft resource limits.

soft, hard = *Process.getrlimit(Process::RLIMIT_CPU)
Process.setrlimit(Process::RLIMIT_CPU, 10, hard)

trap ("SIGXCPU") { puts 'received XCPU, shutting down'; exit }

loop {}