2

I wish to have a customized device to echo a specific value like /dev/zero or /dev/random. But /dev/zero always outputs 0, /dev/random outputs a random number.

The specific value may be configured, for example --- 0x1234, 0x4321, 0xF6, or some ASCII streams Yes and No.

How do I create such a device?

  • 1
    And as for "/dev/random outputs a random number": No, it doesn't. It outputs random bits. – muru Sep 27 '15 at 6:57
4

Quoting from How is /dev/zero created and how can I make variants like /dev/one? (on SuperUser):

There are device drivers that implement interaction with actual devices, and there are device drivers that just react to read-write requests in useful ways. If you want to you can sit down and write a driver that returns the lyrics of the Star Spangeled Banner. But it's a matter of coding ...

Unless you really need a device file, just use the yes command, which repeats its arguments ad infinitum (or y, if no argument is given):

$ yes Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
...

Also see:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.