41

What is the smallest interval for the watch command?

The man page and Google searches do not indicate what the smallest interval lower limit is. I found through experimentation it can be smaller than 1 second.

To test, I ran this command run on a firewall:

watch -n 0.1 cat /sys/class/net/eth1/statistics/rx_bytes

It clearly updates faster than one second, but it is not clear if it is really doing 100ms updates.

gen_Eric
  • 493
Kyle
  • 513

3 Answers3

46

What platform are you on?

On my Linux (Ubuntu 14.10) the man page says:

 -n, --interval seconds
          Specify  update  interval. The  command will not allow quicker
          than 0.1 second interval, in which the smaller values  are  con‐
          verted.

I just tested this with a script calling a C-program that prints the timestamp with microseconds and it works.

muru
  • 72,889
nlu
  • 731
  • 1
    Platform is CentOS 6.6. Man page states: "[-n ] By default, the program is run every 2 seconds; use -n or --interval to specify a different interval." It doesn't specify what the lowest interval is. Thanks for the clarification. – Kyle Jan 20 '15 at 16:21
17

watch command is included in procps utilities.

The smallest value for -n option is 0.1, it's hardcoded in watch source (see line 171 - 172):

case 'n':
    {
        char *str;
        interval = strtod(optarg, &str);
        if (!*optarg || *str)
            do_usage();
        if(interval < 0.1)
            interval = 0.1;
        if(interval > ~0u/1000000)
            interval = ~0u/1000000;
    }
    break;
cuonglm
  • 153,898
16

Actually, you're at the limit. The man page does provide a minimal value (at least on my 2009, Linux version). Here it goes:

-n, --interval seconds
Specify update interval. The command will not allow quicker 
than 0.1 second interval, in which the smaller values are converted.

You can probably check that by using date through watch:

$ watch -n0.1 date +'%H:%M:%S:%N'

If you have a look at the first digit in the last field (nanoseconds), you'll see it quickly increments, meaning that for every watch iteration, ~100ms are added.

John WH Smith
  • 15,880
  • If you add a -p flag to your date example, then watch will try more carefully to be precise, and it will be very easy to judge from the second digit that this is indeed happening roughly every 100 ms. – Alex Jan 21 '20 at 13:01