linux 循环脚本如何停止

jeky_zhang2013 2014-08-26 10:45:00
最近在测试linux在低内存下的表现,在网上找了如下简单的方式:
脚本 usemem.sh : 内容如下
echo "unlimited recursive call..."
sleep 0.5
usemem.sh
我让上述脚本自动运行,在内存达到限值时,停止该脚本,过5秒再执行,现在的情况是脚本运行10S左右就死机了,请问如何停止该脚本运行,是通过程序,不是人工ctrl+C操作。
我在linux进程信息中看到到大量的/system/bin/sh进程,杀掉父进程,子进程也不会全部停掉。
...全文
622 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzyd_ 2014-08-27
  • 打赏
  • 举报
回复
killall
  • 打赏
  • 举报
回复
why do recursive call? why don't u use loop while 1 if condition meets oops, out of memory. I will take care of it else sleep for couple seconds if you want to exit the script through an elegant way, you could put a signal handling method there so the script can do cleanup before exit...
  • 打赏
  • 举报
回复
引用 2 楼 jeky198306 的回复:
[quote=引用 1 楼 micropentium6 的回复:] why do recursive call? why don't u use loop while 1 if condition meets oops, out of memory. I will take care of it else sleep for couple seconds if you want to exit the script through an elegant way, you could put a signal handling method there so the script can do cleanup before exit...
多谢回复,请问等待一段时间能消耗内存么? 我试了循环只消耗cpu多些,对内存的影响不大[/quote] Not too much on CPU either if the waking up does not occur too often.
jeky_zhang2013 2014-08-26
  • 打赏
  • 举报
回复
引用 1 楼 micropentium6 的回复:
why do recursive call? why don't u use loop while 1 if condition meets oops, out of memory. I will take care of it else sleep for couple seconds if you want to exit the script through an elegant way, you could put a signal handling method there so the script can do cleanup before exit...
多谢回复,请问等待一段时间能消耗内存么? 我试了循环只消耗cpu多些,对内存的影响不大

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧