Is there a way to set the OOM killer adjustment value right when a daemon process (Apache in my case) starts? I would like to give the Apache processes a higher likelihood of being killed and make it virtually impossible for some more vital services to bet killed by the OOM killer.

BTW: if anyone could create a tag for oom or oom-killer that would be nice.

up vote 4 down vote accepted

I think you best bet would be to add a separate script as part of your init.d. In it, you will want to do something like this

echo 15 > /proc/`pidof APP_NAME`/oom_adj

The pidof APP_NAME will retrieve the process ID of the app with that name. Writing 15 to /proc/{pid}/oom_adj ups the "badness" of process {pid}, making it more likely to be killed by OOM killer.

The article Taming the OOM killer from also hints at some other ideas that were suggested to allow specification of an "oom_victim", but I am not sure any of them are actually in the kernel.

BTW: The best solution would be to avoid having to use the OOM Killer in the first place. Remember Micro$oft's unwritten motto: There's no problem more RAM can't fix.

[Note: If there could be more than one of these processes, you may want to revise the code a bit.]

  • Thanks for the answer. Yes, it would be nice if I could add RAM, but there is a limit. And the situation occurs rarely, but I see it more often with Apache than on other machines with lighttpd. So I'll switch long term. Thanks also for the link to the LWN article. Concerning your note at the end I'll simply go for something like for pid in $(pgrep APP_NAME); do echo ...; done – 0xC0000022L Jun 30 '11 at 16:43

For ubuntu 15.04, this has changed.

The correct way to set the oom setting for a pid is

echo 42 > /proc/666/oom_score_adj

instead of /proc/666/oom_adj

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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