免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1385 | 回复: 2

<抄书> file descriptor 的一个例子 [复制链接]

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
发表于 2003-11-21 09:30 |显示全部楼层
  1. #!/bin/ksh
  2. interget  tot=0 ave=0
  3. set -A  line                   # Variable 'line' is an array

  4. date > stats                # Put date in stats file
  5. vmstat 2 5 >> stats    # Put vmstat output in stats file,
  6.                                    # repeats every 2 seconds, does it 5 times

  7. exec 3< stats             # open access to stats on file descriptor 3
  8. exec 4> summary       # open write access to summary file on fd 4

  9. read -u3 line               # Read date into variable line
  10. print -u4 $line             # Write contents of line to fd 4

  11. read -u3; read -u3; read -u3; read -u3   # Eliminate  header lines

  12. while read -A -ue line  # Read second vmstat line in array
  13. do
  14. tot=tot+${line[12]}     # Access interrupt count in field 12
  15. done                          

  16. ave=tot/4                     # Calculate average
  17. print "Average number of interrupts during the last 10 seconds is $ave ."                         # To stdout
  18. print  -u4 "Average number of interrupts during the last 10 seconds is $ave ."

  19. exit
复制代码

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
发表于 2003-11-21 09:32 |显示全部楼层

<抄书> file descriptor 的一个例子

想要验证,跑一下这个脚本,再cat summary, cat stats比较一下每个输出

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
发表于 2003-11-21 09:42 |显示全部楼层

<抄书> file descriptor 的一个例子

书记又回来了?
最近可好?忙什么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP