zoukankan      html  css  js  c++  java
  • memory_usage.sh

    #!/bin/bash
    # Destription: testing memory usage
    # Example:	sh memory_usage.sh 500M | sh memory_usage.sh 1G | sh memory_usage.sh release
    
    FILE_NAME=`basename $0`
    memsize=$2
    function usage(){
    	echo "Usage:$FILE_NAME consume memory_size|release ------ the value of memory_size like 100M 2G and etc"
    	echo "Example: $FILE_NAME consume 1G"
    	echo "	       $FILE_NAME release"	
    }
    function consume(){
    	if [ -d /tmp/memory ]; then
    		echo "/tmp/memory already exists"
    	else
    		mkdir /tmp/memory
    	fi
    	mount -t tmpfs -o size=$1 tmpfs /tmp/memory
    	dd if=/dev/zero of=/tmp/memory/block
    }
    function release(){
    	rm /tmp/memory/block;ret=$?
    	if [ $ret != 0 ]; then
    		echo "remove memory data failed"
    		return $ret
    	fi
    
    	umount /tmp/memory;ret=$?
    	if [ $ret != 0 ]; then
    		echo "umount memory filedir failed"
    		return $ret
    	fi
    
    	rmdir /tmp/memory;ret=$?
    	if [ $ret != 0 ]; then
    		echo "remove memory filedir failed"
    		return $ret
    	fi
    }
    function main(){
    	case "$1" in
    		consume) consume $memsize;;
    		release) release;;
    		      *) usage;exit 1;;
    	esac
    }
    main $*
    
    
  • 相关阅读:
    hutool工具
    lombok
    混入
    postMan
    jsr303常用注解
    网页兼容性
    C/C++ 一点笔记(1)
    VS2010 灵活运用快捷操作功能(新手必看)
    HTML中meta作用
    C/C++ 一点笔记(2)
  • 原文地址:https://www.cnblogs.com/wesson2019-blog/p/15338578.html
Copyright © 2011-2022 走看看