1

This post:

Empty or "flush" a file descriptor without read()?

, says that it is possible to do a lseek() on a fd you don't want to read from, thereby avoiding unnecessary copying, but this does not apply to fds I create with timerfd_create(). Why is this so and does there exist a workaround (except to use read(), which works).

I try to do lseek() like this:

lseek(fd, 0, SEEK_END);

And strerror() returned Illegal seek. Again, read(fd, buffer, 8) works.

Community
  • 1
  • 1
user1095108
  • 14,119
  • 9
  • 58
  • 116

1 Answers1

1

timer_fds are not seekable. Not every fd is. Use read to read the relevant bytes.

Note that contrary to the POSIX tag, these calls are Linux specific. From the man page:

CONFORMING TO
       These system calls are Linux-specific.
abligh
  • 24,573
  • 4
  • 47
  • 84
  • Well I know, but a timer fd is not a fifo, nor a pipe. Where do the posix specs say that I can't do `lseek` on a timer fd? Workaround? – user1095108 Mar 05 '14 at 19:50
  • They don't because `timer_fd` is Linux specific, and does not form part of the POSIX standard. The spec is thus the Linux kernel source. – abligh Mar 05 '14 at 19:51
  • Linux does not support seeking of `timer_fd`. I have told you the workaround, which is to use `read` to read the relevant bytes. – abligh Mar 05 '14 at 21:21
  • Yeah, but is this the only way? I don't want to lose even a nanosecond on a pointless ``read()`. – user1095108 Mar 05 '14 at 23:02
  • You could patch the kernel to make it seekable :-) – abligh Mar 06 '14 at 00:21