processing rotating log files
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > processing rotating log files




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    processing rotating log files  
karres@uiuc.edu


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

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...






[ Post a follow-up to this message ]



    Re: processing rotating log files  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:01 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register