ShutDown 100% processes - Automaticly

I am wondering, If some process is runing on 100% and jamming server for long time, is there a way that i could automaticly shut them down if for example more than 5 minutes they occupy 100% of server.

14 Replies

100% of what?

ulimit is probably the standard way to impose resource limits (see also limits.conf), although its CPU limits are cumulative: something using 100% CPU for 1 minute and something using 1% CPU for 100 minutes will "look the same" as far as limits are concerned. The memory and process limits are somewhat more useful.

Monit can do this, but it has to be configured to manage the service. It can't just hunt down and kill off random processes.

A process consuming 100% CPU can't jam your server, because you've got four processors, giving you an aggregate of 400% CPU.

A process that locks up and hangs at 100% is indicative of a more serious issue that you need to look into. The proper thing to do is fix or remove the offending process, rather than trying to kill it when it happens.

Sorry for not being more clear on this.

I got message form linode

"Your Linode, linode-1, has exceeded the notification threshold (90) for CPU Usage by averaging 104.0% for the last 2 hours. "

then i login and check "top" and find out a process that is taking 100% of CPU and time of it is 250 minutes.

So obviously this process is "jammed" somehow and will not terminate by itself. Ok I killed it there and not it's gone.

My idea would be that after 10 minutes or so this kind of processes is killed, data of it logged to my log file and then i check later what it was. Is this correct idea how to solve it and also can it be done this way or some othe way would be better?

What was the name of the process? Apache? PHP? MySQL?

It's relatively easy to write a shell script that runs from cron every few minutes, check the CPU usage, and email you a list of currently running processes if the CPU usage is above a certain threshold. Then you can ask around what might be causing Program X to use so much CPU.

It would be more difficult to automatically terminate the offending process without damaging whatever it was originally meant to be working on. You don't want a rogue script going off on a killing rampage and corrupting your database while doing so.

@marko_roi:

I killed it there and not it's gone.

If you have not done so yet, instead of "kill process" try "kill -9 process".

James

@zunzun:

@marko_roi:

I killed it there and not it's gone.
If you have not done so yet, instead of "kill process" try "kill -9 process".
I think he was trying to write "now it's gone", not "it's not gone".

Yes, I killed it :-) it was "now" What is kill -9 doing instead of plain kill?

To hybinet, Apache was name of process. I think it would be safe to assume if someting is runing more than 10 minutes that it wouldnt work and should be shutdown. I can kill process manually but i am not always by computer and ready to kill it if its making problems, and then server stops working and I have a real problem and i dont even know as i might be on vacation or just off somewhere. Would like to have some trigger for this kind of events, but ok I can take your advice if all of you think its not a way to go.

In layman's terms

kill - sends the message "hey proc, it's time for you to shut down"

kill -9 - forces proc to stop immediately, removes all resources, etc

If it was Apache, it was probably a PHP process gone rogue. That happens from time to time with certain combinations of PHP extensions – the quality of the PHP codebase is very uneven.

What's MaxRequestsPerChild in your Apache configuration? Setting this to a low value (like 500) might help prevent PHP from going belly up, by forcing Apache processes to kill themselves every now and then. Of course this is a stupid band-aid solution, but you sometimes need stupid band-aid solutions if you want to use PHP. Also make sure that maxexecutiontime in php.ini is set to a reasonable value, like 15 seconds. This is another band-aid solution that might or might not work, but it's better than nothing. Google " apache cpu 100%" or something like that to see if anyone else has found a better answer.

BTW, kill -9 is merciless. Try regular kill first. Resort to kill -9 only if regular kill doesn't work.

@marko_roi:

I am wondering, If some process is runing on 100% and jamming server for long time, is there a way that i could automaticly shut them down if for example more than 5 minutes they occupy 100% of server.

No way, not unless you had the permissions set that way on purpose. Is that a possibility?

Mmmm… spammy necropost, with the spam in the quote. Are you a bot, or just stupid?

Damn, sharp ass fangs! I thought it would be cleaner. I am new at this and I can't stand spam. So, i figured on no one reading the quotes and that being a good place to put it.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct