The supposed bug can be easily shown with strace
$ echo|strace ./proggy;
[...]
select(1, [0], NULL, NULL, NULL) = 1 (in [0])
read(0, "\n", 1) = 1
select(1, [0], NULL, NULL, NULL) = 1 (in [0])
read(0, "", 1) = 0
select(1, [0], NULL, NULL, NULL) = 1 (in [0])
read(0, "", 1) = 0
select(1, [0], NULL, NULL, NULL) = 1 (in [0])
read(0, "", 1) = 0
[...]
How can it be? select() returns 1 (as if fd 0 had
some data pending, but read() returns 0 and doesn't
read any byte)
At the same time the process use almost 100% of
the CPU time (as shown by 'top').
This 'bug' however doesn't happen if I run
$ strace ./proggy
Here is a little proggy to reproduce it:
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
void main() {
for(;;) {
char c;
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(0, &fdset);
select(1, &fdset, NULL, NULL, NULL);
read(0, &c, 1);
} }
Can someone explain the reason of this?
(I am using libc6 and Linux 2.1.131)
-Michele