计算程序在1秒内输出的行数

时间:2013-07-14 04:31:44

标签: unix

我正在尝试使用fs_usage计算计算机上一秒钟内发生的文件系统磁盘调用次数。理想情况下,我想将fs_usage传递给像head之类的东西,除了从函数输出1秒钟而不是给定数量的行。有谁知道怎么做?

1 个答案:

答案 0 :(得分:4)

这样的东西?

#!/bin/bash
# run fs_usage, piping the output into the output file
fs_usage > output &
pid=$! # get the pid of fs_usage
# sleep for 1 second
sleep 1s
kill $pid # kill fs_usage
wc -l output
rm output # optional, but I like to clean up after myself

不保证它会立即起作用,我现在不在* nix盒子上。

这个想法是你把fs_usage分到后台,然后在杀死之前在脚本中等一下。