1

When I do this, $ cat ssd/file1 > hdd/file1 and read from ssd is faster than writing in hdd, what happens to the data that cat is reading? Is there any communication between input and output, which tells cat to slow down?

1 Answer 1

1

Consider what cat (on its own) does: it reads from its input, into a buffer in memory (whose size is determined by cat), and writes to its standard output. The reads and writes it performs are blocking: until they reach the end of the input, reads will stop and wait for data if necessary, and likewise, writes will stop and wait for the data to be written if necessary. This provides some sort of communication between output and input; if the input can provide data faster than the output can absorb it, writes will block, and cat will thus stop reading until it can write again.

Operating system caches complicate the picture a little, but they don’t change the behaviour significantly. Particularly for writes, instead of waiting for the target to store the data, the operating system will typically store the written data in a cache, and flush it later on. From cat’s perspective, this allows more data to be written (as long as there’s input data on the other side) before cat has to stop. The underlying principle doesn’t change though, and when writes are slower than reads, the operating system will eventually decide to block writes (e.g. because there’s too much data in cache waiting to be written, or because it’s been waiting too long).

You must log in to answer this question.

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