日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

linux 占用内存 脚本,linux内存测试(占用)脚本

發(fā)布時(shí)間:2024/10/12 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 占用内存 脚本,linux内存测试(占用)脚本 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

內(nèi)存測(cè)試腳本,有bug,繼續(xù)更新中...

#!/bin/bash

################################################################

# mem used script

# eg. ./mem.sh 60G 3600(unit: s) to start testing

# eg. ./mem.sh stop to stop testing and clear env

# update: 2019-1-22 pansaky

################################################################

num=$1

tm=$2

start()

{

sudo mkdir /tmp/memory

sudo mount -t tmpfs -o size=$num tmpfs /tmp/memory

dd if=/dev/zero of=/tmp/memory/block

sleep $tm

}

stop()

{

pid=`ps -ef |grep "mem.sh"|grep -v grep|awk '{print $2}'`

if [ -n "$pid" ];then

kill -9 $pid

fi

sudo rm -rf /tmp/memory/block

sudo umount /tmp/memory

sudo rmdir /tmp/memory

}

main()

{

if [ $num == 'stop' ];then

stop

else

start > mem.log 2>&1

fi

}

if [ $# = 2 -o $# = 1 ];then

main

#elif [ -z $1 -a -z $2 ];then

else

echo 'Usage: ./mem.sh 60G 3600(unit: s) or ./mem.sh stop'

fi

更新后腳本,第一個(gè)留著鄙視自己哈~

#!/bin/bash

################################################################

# mem used script

# eg. ./mem.sh 60G & to start testing

# eg. ./mem.sh stop to stop testing and clear env

# update: 2019-1-22 pansaky

################################################################

num=$1

user=`whoami`

start()

{

if [ -d /tmp/memory ];then

echo "the dir "/tmp/memory" is already exist!, use it." >> mem.log

else

sudo mkdir /tmp/memory

mount -t tmpfs -o size=$num tmpfs /tmp/memory

fi

dd if=/dev/zero of=/tmp/memory/block >> mem.log 2>&1

}

stop()

{

rm -rf /tmp/memory/block

umount /tmp/memory

rmdir /tmp/memory

if [ -d /tmp/memory ];then

echo "Do not remove the dir \"/tmp/memory\", please check "

else

echo "clear env is done!"

fi

}

main()

{

if [ $num == 'stop' ];then

stop

elif [ $user != "root" ];then

echo "please use the \"root\" excute script!"

exit 1

else

start

fi

}

if [ $# = 2 -o $# = 1 ];then

main

else

echo 'Usage: to start or to clear env'

fi

看到別人寫的c腳本 拉過來用一哈

/*usage: cc mem.c -o mem.out 后 使用./mem.out 100 & 消耗對(duì)應(yīng)數(shù)字MB單位的內(nèi)存,釋放時(shí)殺掉對(duì)應(yīng)進(jìn)程即可*/

#include #include #include #define UNIT (1024*1024)

int main(int argc, char *argv[])

{

long long i = 0;

int size = 0;

if (argc != 2) {

printf(" === argc must 2\n");

return 1;

}

size = strtoull(argv[1], NULL, 10);

if (size == 0) {

printf(" argv[1]=%s not good\n", argv[1]);

return 1;

}

char *buff = (char *) malloc(size * UNIT);

if (buff)

printf(" we malloced %d Mb\n", size);

buff[0] = 1;

for (i = 1; i < (size * UNIT); i++) {

if (i%1024 == 0)

buff[i] = buff[i-1]/8;

else

buff[i] = i/2;

}

pause();

}

總結(jié)

以上是生活随笔為你收集整理的linux 占用内存 脚本,linux内存测试(占用)脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。