Question

I'm programming in Bash and I'm trying to find out how many interrupts that happend the last second.

I've searched and tried to find how many interrupts total, so I could use sleep 1 and calculate the difference, but with no success.

Thanks for your help.

Était-ce utile?

La solution

This answer is similar to your other question. Once again, vmstat(8) will be our friend.

Example output:

$ 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

The first line is the average since reboot, the second line is a sampling of the last second.

From the manpage:

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

We can use awk(1) to parse the output:

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

This should work on Linux, FreeBSD, and probably MacOSX.

Autres conseils

Just a food for thought you can do something like this

watch "cat /proc/interrupts |awk '{print \$1,\$2}'"

By passing -n to watch command you dont need sleep option and you can have decide when you get an output

-n, --interval

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top