PDA

View Full Version : Monitoring fopen()/fprintf()


Boyov
Nov 29, 2004, 13:15
Question to GURUs :

How to monitor fopen()/fprintf().

OS - RedHat 7.3 (2.4.20-18.7.cern)

Give some hints, please.


P.S. I am already looking through coreutils sources (to find out how 'tail -f' is implemented). :)

Pascal
Nov 29, 2004, 13:23
lsof - pomozhet dlya fopen - a.

Reckon_
Nov 29, 2004, 18:15
В принципе можно даже использовать strace.

Беда лишь в том, что fopen/fprintf не являются непосредственно системными вызовами (fopen() вызывает в свою очередь open(), а fprintf() вызывает
write(), кажется).

Но, зная этот факт, можно сделать так:

strace -p <pid> -e trace=open,write

где <pid> - номер исследуемого процесса.



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 - нет резона. :)

Boyov
Nov 30, 2004, 12:47
2 Pascal: Spasibo ;)


2 Reckon_: Tebe toje spasibo :spin:


Так что перехватывать вызовы чтобы понять, как устроен tail - нет резона. :)

Ya i ne sobiralsya perxvativat' vizov dlya togo chtobi ponyat' kak tail rabotatet. Mne isxodniki ego bili nujni dlya togo chtob ponyat' kak on sam rabotatet.