最后一秒的中断次数(Bash)

时间:2014-02-22 00:55:06

标签: bash interrupt

我正在使用Bash进行编程,而我正试图找出最后一秒发生了多少中断。

我已经搜索并尝试查找总共有多少中断,因此我可以使用睡眠1并计算差异,但没有成功。

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

这个答案是similar to your other question。再一次,vmstat(8)将是我们的朋友。

示例输出:

$ vmstat 1 2
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0    752 135436  31276 392252    0    0     2     1   40  101  0  0 99  0
 0  0    752 138404  31396 392816    0    0     0     0   68  188  1  1 98  0

第一行是重启后的平均值,第二行是最后一行的采样值。

从联系手册:

   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.

我们可以使用awk(1)来解析输出:

ints=$(vmstat 1 2 | tail -1 | awk '{print $11}')

这适用于Linux,FreeBSD,可能还适用于MacOSX。

答案 1 :(得分:0)

只是一种思考的食物你可以做这样的事情

观看“cat / proc / interrupts | awk'{print \ $ 1,\ $ 2}'”

通过将-n传递给watch命令,您不需要睡眠选项,您可以决定何时获得输出

-n, - interval