-2

cat /dev/zero | pv > /dev/null

What exactly happens here and what determines the speed of this process.

Even on low end hardware you get a couple of GB/s transfer speeds like this.

Flatron
  • 318
  • 2
  • 5
  • 19
  • What do you think happens? Where does your knowledge/understanding fail? –  Jan 24 '17 at 13:57
  • what basically happens is clear, I move zeros from one virtual device into the "void". But I am more interested in what happens behind the curtains, where do the zero's basically come from e.b. "What is /dev/zero" and what is "/dev/null". What is the limiting factor regarding the transfer speed? CPU bus line speed? CPU frequency? RAM speed? That the whole process itself is pointless is clear. – Flatron Jan 24 '17 at 14:46

1 Answers1

2

cat /dev/zero gives you a stream of zero-characters. When you open it and read from it you're using the kernel. The kernel implements /dev/zero in drivers/char/mem.c.

As far as cat or pv is concerned this is nothing special. Choosing to use /dev/zero is no different from reading /etc/passwd. The only difference is that you're reading a virtual file, not a real file. So the work the kernel does is different - i.e. It doesn't have to do things with the filesystem ,etc.

Writing to /dev/null is pretty much the same. pv doesn't care about the target (well in this case it is your shell, due to redirection) and so again the only difference is that the write is thrown away, because that's what the kernel-driver for /dev/null does, again in drivers/char/mem.c.

The speed of this process will depend on the system I/O load and the processor, as much as anything else.