I need to get all process ids which have memory usage greater or lower than predifined number. For example get id where memory (rss) usage grater than 10MB and then using this id kill each process. Thanks
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This following command will help I think,
ps aux --sort -rss
Try it.
回答2:
That's not a good idea. You will certainly kill processes you should not and might render your system damaged in the process. But anyway, here's what does the trick:
ps -eo rss=,pid=,user=,comm= k -rss |
while read size pid user comm
do
[ "$user" = "alfe" ] || continue # adjust user name here
if [ "$size" -gt 10000 ]
then
echo "kill $pid # $size $user $comm"
else
break
fi
done
You might want to replace the echo
line by a line using kill
directly, but as I said, this will probably kill processes you should not kill.
The line with the continue
is meant to skip all processes which are not of a specific user; I just assumed that; if you intend to run this as root
, feel free to remove that line.