Hi,

for the OpenBSD version, see kevent(2) and grep the source for kevent,
kqueue, and EV_SET.

BSD 4.4 used select(2) because it was faster than sleep (you can find
the sources e.g. on github).

Best regards
Robert

 On Fri, 17 Feb 2023 08:23:13 +0300
Maksim Rodin <a23s4a2...@yandex.ru> wrote:

> Hello,
> Sorry if I chose the wrong place to ask such a question.
> I have been learning C for a couple of months and along with reading
> "C Primer Plus" by Stephen Prata and doing some exercises from it I
> took a hard (for me) task to replicate a tail program in its simplest
> form. I was able to reproduce watching for new data and truncation of
> the file using kqueue but I do not quite understand how the original
> tail watches when the file appears again after deletion or renaming.
> By reading the original tail sources downloaded from OpenBSD mirror I
> see that this is done by calling tfreopen function which seems to use
> a "for" loop to (continuously?) stat(2) the file name till stat(2)
> successfully returns and it does not seem to load a CPU as a simple
> continuous "for" loop would do.
> Can someone explain how it is done?
> May be there is a better way to watch for the file to appear
> correctly? Is inserting a sleep(3) in a loop an appropriate way?


Reply via email to