Block vs Character: Cage Match

In the last post, we looked at the contents of the file /proc/devices and saw a list of character devices and a list of block devices.  But what’s the difference between a block and a character?  And if there is a difference, when do we use a block vs character device?

Well, we know these are blocks:

Blocks

Blocks

And we know Ironman is certainly a character:

Ironman

Ironman

But that’s not what our devices do.  That would be silly if that’s what they did, right?  Our Linux® box isn’t Ironman and it isn’t a pile of blocks, it’s a computer that does things.

The difference between a block device and a character device is all in how your system communicates with it.  A character device is talked to one character at a time.  It doesn’t seem like it, but the terminal screen you type on is a character device.  One character at a time goes from your keyboard and to the screen (when you type) and one character at a time (although very quickly) goes from the output of the command you type and to the screen.

A block device sends its communications in blocks of data.  If you write information to a disk, like your USB drive or a hard drive, it goes in chunks of data.  For example, copying your file that contains all the Pokemons you’ve ever caught goes one big chunk at a time rather than P i k a c h u it sends it all together as Pikachu.

Now when we use Linux© we don’t care about block vs character.  We just care that what we type gets shown on the screen or what I copy to my USB drive goes to the drive.  How it really gets there isn’t important.

The people that really care about block vs character are the ones that have to write the code that makes the devices run.  That’s their job, but it is useful to know that there’s more than one type!

 

Leave a Reply

Your email address will not be published. Required fields are marked *