A script to monitor the running programs in the server

Recently, the server has been crashed frequently for programs costing most of the memories. To avoid this, two suggestions are prosed.

  • One is more flexible by changing the maximum memory usage for one user locally or globally. Here I suggest users set this variable locally in case they want to run programs need lots of memories by adding ulimit -v 30000000 to .bash_profiles (30,000,000 means maximum 30G is allowed). If one want to run programs cost larger than 30G RAM, just change this value and re-login.

  • Another is running the following program serverWatchman to kill programs cost more than 90% memories.

#!/bin/bash

#84G is the maximally allowed total memory usage.
maxmem=84

while true
do
	mem=`free -g | grep -- '^-' | awk '{print $3}'`
	echo ${mem}
	echo ${maxmem}
	if [ ${mem} -gt ${maxmem} ]; then
		info=`ps aux | sort -k4nr | head -n 1`
		id=`echo ${info} | awk '{print $2}'`
		#echo $id
		echo ${info} | wall
		kill -9 $id
		# Be merciful, grieve the death of the process
		sleep 60s
		#exit 1
		#maxmem=10000
	fi
	sleep 5s
done
CHENTONG
版权声明:本文为博主原创文章,转载请注明出处。
alipay.png

CHENTONG

CHENTONG
积微,月不胜日,时不胜月,岁不胜时。凡人好敖慢小事,大事至,然后兴之务之。如是,则常不胜夫敦比于小事者矣!何也?小事之至也数,其悬日也博,其为积也大。大事之至也希,其悬日也浅,其为积也小。故善日者王,善时者霸,补漏者危,大荒者亡!故,王者敬日,霸者敬时,仅存之国危而后戚之。亡国至亡而后知亡,至死而后知死,亡国之祸败,不可胜悔也。霸者之善著也,可以时托也。王者之功名,不可胜日志也。财物货宝以大为重,政教功名者反是,能积微者速成。诗曰:德如毛,民鲜能克举之。此之谓也。

R 学习

R语言是比较常用的统计分析和绘图语言,拥有强大的统计库、绘图库和生信分析的Bioconductor库,是学习生物信息分析的必备语言之一。Rstudio是编辑、运行R语言的最为理想的工具之一,支持纯R脚本、Rmarkdown (脚本文档混排)、Bookdown (脚本文档混排...… Continue reading

本地使用Rfam 12.0+

Published on June 16, 2017

Linux学习(一)- 文件和目录

Published on June 08, 2017