Logo  

CS471/571 - Operating Systems

Displaying exercises/e4/solution/iostat.c

#include "types.h"
#include "stat.h"
#include "user.h"

int main(int argc, char *argv[])
{
  int ticks = 0, rcount, wcount;

  // Note that if you provide ticks, then this program will never exit.
  // We need to implement signals (later) so we can have Ctrl-C to break it.
  if (argc > 1) ticks = atoi(argv[1]) * 100;

  printf(1, "Reads\tWrites\n");

  do {
    iostat(&rcount, &wcount);
    printf(1,"%d\t%d\n", rcount, wcount);

    if (ticks) sleep(ticks);
  } while (ticks > 0);

  exit();
}