В принципе можно даже использовать
strace.
Беда лишь в том, что fopen/fprintf не являются непосредственно системными вызовами (fopen() вызывает в свою очередь open(), а fprintf() вызывает
write(), кажется).
Но, зная этот факт, можно сделать так:
strace -p <pid> -e trace=open,write
где <pid> - номер исследуемого процесса.
Quote:
P.S. I am already looking through coreutils sources (to find out how 'tail -f' is implemented).
|
Читаем мануал по
tail:
.......................................
With --follow (-f), tail defaults to following the file descriptor,
which means that even if a tail'ed file is renamed, tail will continue
to track its end. This default behavior is not desirable when you
really want to track the actual name of the file, not the file descrip-
tor (e.g., log rotation). Use --follow=name in that case. That causes
tail to track the named file by reopening it periodically to see if it
has been removed and recreated by some other program.
.........................................
Короче говоря:
tail использует механизм тайм-аутов, и проверяет статус файла через определенный период времени. Просто и эффективно. И
tail не attach-ается к какому-либо процессу (как деляет
strace), и не лезет в ядро. Так что перехватывать вызовы чтобы понять, как устроен tail - нет резона.