/dev/random does not block
Your program is reading 100 bytes from /dev/random
. If you restart it with some manual action (e.g. typing the command, or simply the arrow-up key for bash), that manual action (sequence of keypresses) is feeding the entropy pool of random(4)
. So you would never be in the blocking case.
And the semantics of the read(2) syscall applied to /dev/random
is that it will try to read some bytes. If at least one byte has been read, the read(2)
syscall succeeds and does not block.
Also, as I commented, recent enough hardware and recent enough kernel has a good enough random source which might maje random(4)
never block.