How do I change the priority of a process via Ruby
When I exec a Ruby process, 开发者_StackOverflow中文版how can I have that process lower it's priority? I've looked at the documentation for Process.setpriority but I just don't get it. Does anyone have an example of how a Ruby process would lower it's own priority?
Chris
The second argument in setpriority (and getpriority) indicates the process you want to change; using 0 will specify the current process.
If you look at the ruby source for Process.setpriority all this call is doing is calling the underlying OS setpriority call. On unix the priority can be between -20 and 20 where -20 is the most favorable and 20 is the least favorable for scheduling. So if you want to boost the current process as high as it can go you would do:
Process.setpriority(Process::PRIO_PROCESS, 0, -20)
精彩评论