Jump to content
Sign in to follow this  
roleeks

Linux high usage proccess killer

Recommended Posts

Rakņājoties pa veciem failiem atradu skriptu, kas kill'o processus, kam ir lielāks usage par X norādīto.

#!/bin/bash
while true;
do
  #echo "Checking..."
  ps -A -o comm,pmem,pid | grep -v EXCLUDE_PATTERN1 | grep -v EXCLUDE_PATTERN2 | grep -v EXCLUDE_PATTERN_ETC | while read line;
  do
  ps -A -o comm,pmem,pid | while read line;
  do
	 if [ $(echo "$line" | awk '{printf int($2)}') -gt 50 ];then
	    kill -9 `echo $line | awk '{printf $3}'`
	    echo -n "Killed: ";echo $line | awk '{printf $1}'
	 fi
  done
  # check every 1 seconds
  sleep 1
  done
done

Lietošana: -gt 50 => 50 nozīmē, ka attiecīgais process ēd vairak par 50% no kāda kodola vai total usage. Izveidojam kādu cpu.sh failu un ieliek crontabā!

Testēts agrāk uz gentoo, varbūt kādam noderēs

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.