Super User is a question and answer site for computer enthusiasts and power users. 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

When my server runs into out-of-memory, it usually kills several applications. How can i prevent from killing SSH? Because usually, when this out-of-memory error happens, my SSH is broken like this:

I connect to ssh server.
Enter username
Enter password

and then i wait

i wait

and wait...

and waaaaaaaaaait..

and then:

Connection timed out.

Is there any way to prevent this? How can i increase priority of process?

share|improve this question

migrated from May 15 '11 at 18:48

This question came from our site for professional and enthusiast programmers.

up vote 7 down vote accepted

Run the following command as root. You probably want to add this into an init script somewhere.

echo -17 > /proc/`pidof sshd`/oom_adj


To ensure that the main daemon process is the one being adjusted, you can use this command. The above will probably fail if you have any SSH sessions open, so not such a great choice :(

echo -17 > /proc/`cat /var/run/`/oom_adj

-17 is the current value for OOM_DISABLE in /usr/include/linux/oom.h. You can read more about the Linux OOM killer here.

share|improve this answer
Thanks, but, "root@*****:~# pidof sshd" returns into 30330 24682 19633 19582 516 so i guess it will fail. – Riki137 May 17 '11 at 18:13
Yes, it would fail. You can replace with pidof -s to only return one pid. See my updated answer for better option. – Michael Mior May 17 '11 at 21:00
i hope you will get more vote-ups :) – Riki137 May 18 '11 at 18:50
@Riki137 Thanks! Glad I could help :) – Michael Mior May 18 '11 at 20:08
At which time should it be run on startup? >"You probably want to add this into an init script somewhere." – Sarge Borsch Sep 2 '15 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .