23

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.

21

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.

  • 1
    Platform is CentOS 6.6. Man page states: "[-n <seconds>] 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
11

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.

10

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.