tags:

views:

66

answers:

2

Hi,

This might be an often repeated question, sorry for bringing it back again. I was unable to find a solution :( . I am writing a VM monitoring code in C in Linux. I want to get the read and write count of all the VM's every 10 seconds. Is there any C library that provides this feature(timer alone), blocking/non-blocking timer doesn't matter. Thanks !!

Regards, Sethu

+1  A: 
sleep(10);

will make the thread sleep for 10 seconds in a unix system. Use it in a loop with the code for monitoring, and you are good to go. If you're using windows as the host for monitoring, then sleep function will accept in milliseconds.

Also, as multithreading/multiprocessing is required, implementations will vary based on os/platform.

lalli
+2  A: 

For a non-blocking timer (on POSIX systems), use alarm:

int main(void) {
  signal(SIGALRM, monitor);
  monitor(0);
  /* ... */
}

void monitor(int signal) {
  /* ... */
  alarm(10);
}

But for a blocking timer, use sleep as described by lalli.

You