Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote a quick program that takes one argument, how many <code>A</code> characters to print to standard output per second (negative argument means no rate limiting). Hope this helps! :-) (On GNU libc, you will need to link your program with <code>-lrt</code>.)</p> <p>Edit: revised to print dot by default, unless a second argument is specified, in which case the first character of that is used. (And that means, if you want to print the NUL character, just specify an empty string as the second argument. :-))</p> <pre><code>#include &lt;math.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; #include &lt;unistd.h&gt; int sleeptill(const struct timespec *when) { struct timespec now, diff; clock_gettime(CLOCK_REALTIME, &amp;now); diff.tv_sec = when-&gt;tv_sec - now.tv_sec; diff.tv_nsec = when-&gt;tv_nsec - now.tv_nsec; while (diff.tv_nsec &lt; 0) { diff.tv_nsec += 1000000000; --diff.tv_sec; } if (diff.tv_sec &lt; 0) return 0; return nanosleep(&amp;diff, 0); } int main(int argc, char **argv) { double rate = 0.0; char *endp; struct timespec start; double offset; if (argc &gt;= 2) { rate = strtod(argv[1], &amp;endp); if (endp == argv[1] || *endp) rate = 0.0; else rate = 1 / rate; if (!argv[2]) argv[2] = "."; } if (!rate) { fprintf(stderr, "usage: %s rate [char]\n", argv[0]); return 1; } clock_gettime(CLOCK_REALTIME, &amp;start); offset = start.tv_nsec / 1000000000.0; while (1) { struct timespec till = start; double frac; double whole; frac = modf(offset += rate, &amp;whole); till.tv_sec += whole; till.tv_nsec = frac * 1000000000.0; sleeptill(&amp;till); write(STDOUT_FILENO, argv[2], 1); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload