这是我一直在研究的,但一直不成功
if [ "$memUsage" -gt "30500" ];
then
transUsage=$(pmap 3097 | tail -n 1 | awk '/[0-9]/{print $2}')
transUsage=$transUsage | awk '/[0-9]/{print $2}' #This was my attempt at removing the extra K
if [ "$transUsage" -gt "10500" ];
then
echo "Terminated this and this"
fi
# Print the usage
echo "Memory Usage: $memUsage KB"
fi
我需要变量中PID 3097的内存使用情况,以便使用if命令。当前它输出,
xxxxK, where x is memory usage size. Due to K being part of size, it's not being being recognized as numeric value.
如何解决这个问题?非常感谢您的帮助。问候!
1条答案
按热度按时间9rbhqvlz1#
您可以使用以下更好的代码:
((...))
是一个算术命令,如果表达式为非零,则返回退出状态0;如果表达式为零,则返回退出状态1。如果需要副作用(赋值),则也用作“let”的同义词。请参阅http://mywiki.wooledge.org/ArithmeticExpression。