Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an apache server that runs some binary CGI programs. Those programs behave nicely most of the time, but on rare occasions they gult up all the RAM, or run for a very long time, taking 100% cpu.

When that happens, it becomes very hard to SSH to that machine (it's CentOS, BTW) and manually fix things.

Is there a way to have apache execute the CGI binraries with "nice" priority ? I don't want to limit the RAM usage or the CPU resources.

It's my understanding the having a "nice" priority will allow me to SSH to the machine (since sshd will have higher priority), and also, if RAM becomes an issue, the OOM killer will kill the CGI binary first.

Any ideas ?


share|improve this question
up vote 0 down vote accepted

For each cgi script, you could write a wrapper script that adjusts its own niceness and then execs the cgi script.

renice -n 10 -p $$
exec /path/to/cgi/binary

However, I'm not sure how much effect this would have. Linus Torvalds himself calls nice broken. A better solution would be to set up cgroups to limit the share of the CPU or amount of memory Apache and its child processes can use. David Collier-Brown has written up some examples of this. I think you will need a newer kernel than the one that's included in CentOS 5. CentOS 6 will support cgroups; here is the documentation from Red Hat.

share|improve this answer
That Linus/LWN link is a great read, thanks. – cagenut Mar 1 '11 at 21:22
Don't agree with Linus. Nice does (though not aggressively enough) limit CPU where appropriate. That's great he's worried about compilation on his local machine, but we need a user-level hint to the scheduler on over-committed server machines. – Xepoch Apr 11 '12 at 15:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.