Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com May 15 '11 at 18:48

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

    
Why did you randomly bold parts of your question? –  Matt Ball May 15 '11 at 18:46
2  
@Matt Ball it wasn't random. If you read only the bold part you still knew what i wanted to say. –  Riki137 May 15 '11 at 18:51
add comment

1 Answer

up vote 5 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

Update:

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/sshd.pid`/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
1  
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
1  
@Riki137 Thanks! Glad I could help :) –  Michael Mior May 18 '11 at 20:08
add comment

Your Answer

 
discard

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.