Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a filter which I could use to rate-limit a pipe on linux? If this exists, let call it rate-limit, I want to be able to type in a terminal something like

cat /dev/urandom | rate-limit 3 -k | foo

in order to send a a stream of random bytes to foo's standard input at a rate (lower than) 3 kbytes/s.

share|improve this question

migrated from Jan 31 '11 at 10:51

This question came from our site for professional and enthusiast programmers.

I asked here because I want to use it in a programme, not for troubleshooting. But it's my very first question here so I apologize if I made an error. – Frédéric Grosshans Mar 17 '10 at 17:54
BTW, the above is an unnecessary use of cat, you could do rate-limit 3k < /dev/urandom | foo. – dmckee Mar 17 '10 at 18:15
up vote 55 down vote accepted

Pipe Viewer has this feature.

cat /dev/urandom | pv -L 3k | foo
share|improve this answer
Thanks for your answer ! – Frédéric Grosshans Mar 17 '10 at 17:59

I'd say that Juliano has got the right answer if you have that tool, but I'd also suggest that this is a neat little K&R style exercise: just write a specialized version of cat that reads one character at a time from stdin, outputs each to stdout and then usleeps before moving on. Be sure to unbuffer the standard output, or this will run rather jerkily.

I called this slowcat.c:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char**argv){
  int c;
  useconds_t stime=10000; // defaults to 100 Hz

  if (argc>1) { // Argument is interperted as Hz


  while ((c=fgetc(stdin)) != EOF){

  return 0;

Compile it and try with

$ ./slowcat 10 < slowcat.c
share|improve this answer
Now I'm feeling the horrible temptation to add a "clack" noise to each character an set the default speed to 40 CPS, with an extra delay for newlines. – dmckee Mar 17 '10 at 19:19

Quick and dirty, all shell all the time (I have CentOS and pv doesn't come with it by default):

hexdump -c /dev/urandom | while true; do head -1; sleep 1; done | \
your_program_that_reads_stdin  -your_argument_list

...dirty because although it's rate limited, it's bursty at a rate that I can't tell you :-) . But it's handy when you just need to send data from one place to the other (I was doing some socat tests) and you don't want to swamp your screen with garbage.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .