Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the priority of a process via Ruby

Tags:

ruby

When I exec a Ruby process, 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

like image 611
Chris McCauley Avatar asked Dec 18 '22 04:12

Chris McCauley


1 Answers

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)
like image 104
carson Avatar answered Dec 31 '22 07:12

carson