|
Home > Archive > Unix Programming > December 2004 > processing rotating log files
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
processing rotating log files
|
|
| karres@uiuc.edu 2004-12-16, 7:45 pm |
| Earlier I had a question about doing a read() on a system log file that
always grows and is rotated once a month. I learned that using
select() with the read() will not block since having read() hit EOF
does not throw an exception.
Pk. I'll change the question then, what is the best way to process a
text file and then, when EOF is reached, sleep for some period or until
input becomes available?
Opening the file with O_ASYNC will not help as the man page says: "This
feature is only available for terminals, pseudo-terminals, and
sockets".
I have seen some possibilities in the fcntl() man page but F_SETSIG and
F_NOTIFY may be Linux specific.
I mean, how does "tail -f file" do what it does? Is it just spinning
on an open FD when it hits the bottom of the file it is "following"?
Dean...K...
| |
| Måns Rullgård 2004-12-16, 7:45 pm |
| karres@uiuc.edu writes:
> I mean, how does "tail -f file" do what it does? Is it just spinning
> on an open FD when it hits the bottom of the file it is "following"?
strace is your friend:
$ strace tail -f /dev/null
[...]
open("/dev/null", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
read(3, "", 8192) = 0
fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
clock_gettime(CLOCK_REALTIME, {1103223584, 392427000}) = 0
nanosleep({1, 0}, NULL) = 0
fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
clock_gettime(CLOCK_REALTIME, {1103223585, 406426000}) = 0
nanosleep({1, 0}, NULL) = 0
fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
clock_gettime(CLOCK_REALTIME, {1103223586, 412817000}) = 0
nanosleep({1, 0}, NULL) = 0
fstat64(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
....and so on.
--
Måns Rullgård
mru@inprovide.com
|
|
|
|
|