用python消耗linux内存方法
# -*- coding: utf-8 -*-
import sys
import re
import time
def print_help():
print 'Usage: '
print ' python mem.py 100MB'
print ' python mem.py 1GB'
if __name__ == "__main__":
if len(sys.argv) == 2:
pattern = re.compile('^(\d*)([M|G]B)$')
match = pattern.match(sys.argv[1].upper())
if match:
num = int(match.group(1))
unit = match.group(2)
if unit == 'MB':
s = ' ' * (num * 1024 * 1024)
else:
s = ' ' * (num * 1024 * 1024 * 1024)
time.sleep(10000)
else:
print_help()
else:
print_help()
本文介绍了一个使用Python编写的简单脚本,该脚本能够指定消耗Linux系统的内存大小,单位可以是MB或GB。通过创建大量的字符串来实现内存占用。
393

被折叠的 条评论
为什么被折叠?



