/dev/primes is what I want without writing C code just python which I have known and easily written the program.
The device file should be similar to /dev/urandom that outputs primes instead of random stream!!
I am excited if linux could do it!
Character devices are provided by Linux kernel modules.
Linux kernel modules are written in C.
You can, in theory, use a programming language other than C. But your program needs to be compiled into a binary that can be loaded into the kernel. In particular, you need to define an initialization handler, an exit handler, as well as the functions dev_open
, dev_read
, dev_release
with well-defined signatures.
You cannot do this in Python (truly exotic approaches may exist, but I do not know of any).
For more information on how to write a Linux kernel module in C, confer to any guide (contents not inserted here due to copyright) you like.
/dev/urandom
in that you could use something like a pipe (seemkfifo
) and write a Python program that continuously writes primes to this pipe. It will block until the pipe is full. Consuming from a/dev/primes
pipe would be similar to consuming/dev/urandom
./dev/urandom
to get entropy to generate primes!/dev/urandom
and outputs only primes, so I felt no urge to explain how to do it. … (Cont’d)/dev/randomprime
or something similar? … (Cont’d)/dev/random
that outputs primes, you are saying that you want a new device. (7) You say “I never said I wanted a new device ... I could use a device file instead.” … Well, “In Unix, everything is a file.” We often say “device” when we mean “device file” or “pseudo-device”. Did you believe that I was talking about a piece of hardware?