写消耗的内存一定量的用户定义的时间bash shell脚本
问题说明
我想写消耗了用户定义的时间嵌入式设备上的内存量高一个bash shell脚本。我该怎么做它没有使用数组?
I am trying to write a bash shell script that consumes a high amount of RAM on an embedded device for a user defined time. How do I do it without using arrays ?
正确答案
即使传统猛砸阵列不支持,它仍然有可能创建使用内置在特定的壳评估
命令类似数组变量。
Even if traditional Bash arrays are not supported, it may still be possible to create array-like variables using the eval
command built into the particular shell.
以下示例脚本是基于一些脚本我在一个嵌入式Linux项目使用 BusyBox的什么时候。 BusyBox的使用 Almquist外壳 (也称为外壳,灰,SH),它不支持数组。
The following example script is based on some scripting I did when using BusyBox in an embedded Linux project. BusyBox uses the Almquist shell (also known as A Shell, ash, and sh), which does not support arrays.
#!/bin/ash
for index in 1 2 3 4 5; do
value=$(($index * 1024))
eval array$index=\"array[$index]: $value\"
done
for i in 1 3 5; do
eval echo \$array$i
done
<子>注意使用评估
!
的输出:的
array[1]: 1024
array[3]: 3072
array[5]: 5120
根据特定的情况下,类似于以下就足够了脚本。
Depending on your particular scenario, a script similar to the following may suffice.
#!/bin/ash
echo "Provide sleep time in the form of NUMBER[SUFFIX]"
echo " SUFFIX may be 's' for seconds (default), 'm' for minutes,"
echo " 'h' for hours, or 'd' for days."
read -p "> " delay
echo "begin allocating memory..."
for index in $(seq 1000); do
value=$(seq -w -s '' $index $(($index 100000)))
eval array$index=$value
done
echo "...end allocating memory"
echo "sleeping for $delay"
sleep $delay
在我简短的测试,这个脚本消耗〜570M到575M〜物理内存 * 进行5分钟的指定时间段。
In my brief testing, this script consumed ~570M to ~575M physical memory* for the specified time period of 5 minutes.
*在不同的测试中使用监控顶部和memprof节目
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcckekk
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22