f1fc file monitoring without polling - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Base System > General

General General questions about the FreeBSD operating system. Ask here if your question does not fit elsewhere.

Reply
 
Thread Tools Display Modes
  #1  
Old October 23rd, 2009, 03:20
lokli lokli is offline
Junior Member
 
Join Date: Oct 2009
Posts: 5
Thanks: 7
Thanked 0 Times in 0 Posts
Default file monitoring without polling

Is there a way to monitor my filesystem without polling every second?
I'am lookling for a way to watch for new files under some directory and watch for file changes, and it should be a real-time solution.

It seems to me, that kqueue is the key to this, but I haven't found a program in ports that could do file monitoring this way.

Also a related question on tail. When tail is invoked like this
Code:
tail -f some_file
is it polling the file or is it using some other mechanism?
Reply With Quote
  #2  
Old October 23rd, 2009, 05:53
gordon@ gordon@ is offline
FreeBSD Developer
 
Join Date: Feb 2008
Location: San Diego, CA
Posts: 398
Thanks: 0
Thanked 80 Times in 70 Posts
Default

tail uses kqueue to do the job. Take a look at the code in usr.bin/tail/forward.c. Specifically look at the code in the follow and set_events subroutines.
Reply With Quote
The Following User Says Thank You to gordon@ For This Useful Post:
lokli (November 1st, 2009)
  #3  
Old October 23rd, 2009, 10:05
lokli lokli is offline
Junior Member
 
Join Date: Oct 2009
Posts: 5
Thanks: 7
Thanked 0 Times in 0 Posts
Default

thanks, it seems tail is what i really need.
i'am writing something like a wrapper to irc/ii for personal use

so, i'am trying to make tail read the "out" files
Code:
tail -F some_file [another_file]
this command cliams to show the file, even if it doesn't exist (it shows after creation) , quite a nice feature. But i can't find a way to use wildcards with it, like
Code:
tail -F */out
am I doning something wrong?
is there a way to add new files to a running instance of tail?

P.S. i'am still interested in directory monitoring using kqueue
Reply With Quote
  #4  
Old October 31st, 2009, 06:31
gordon@ gordon@ is offline
FreeBSD Developer
 
Join Date: Feb 2008
Location: San Diego, CA
Posts: 398
Thanks: 0
Thanked 80 Times in 70 Posts
Default

The problem is likely due to shell globbing. Assuming that */out doesn't match any files, the shell will pass it as is to the tail process. As a result, tail is attempting to open a file named "*/out" which is unlikely to work. I suppose an enhancement could be made to tail to do the globbing, but I would be concerned about the performance impact of such a change. I also don't know if kqueue/kevent would work with globs (I somehow doubt it).
Reply With Quote
  #5  
Old November 1st, 2009, 09:47
lokli lokli is offline
Junior Member
 
Join Date: Oct 2009
Posts: 5
Thanks: 7
Thanked 0 Times in 0 Posts
Default

"tail -F */out" find files, that already present.

my point is that i want to monitor files, that are not present yet.

for example i can issue
Code:
tail -F some_channel/out
while there is no file "some_channel/out".

Quote:
If the file being followed does not (yet) exist or if it is
removed, tail will keep looking and will display the file from
the beginning if and when it is created.
but these doesn't work with "*/out"

i haven't found a way to look for changes in real time, so i just look for them every 10 seconds via shell script.
Reply With Quote
  #6  
Old November 1st, 2009, 18:27
gordon@ gordon@ is offline
FreeBSD Developer
 
Join Date: Feb 2008
Location: San Diego, CA
Posts: 398
Thanks: 0
Thanked 80 Times in 70 Posts
Default

Quote:
Originally Posted by lokli View Post
"tail -F */out" find files, that already present.

my point is that i want to monitor files, that are not present yet.
Right, this is to be expected. When you put tail -F */out on the commandline, the shell expands the */out so the actual command being executed is more like:

Code:
tail -F foo/out bar/out
As a result, suppose at sometime in the future baz/out is created. Since the actual running command doesn't list baz/out in the arg list, it's not going to be detected by the currently running command.

To see what I'm talking about, try running tail -F */out and then run ps in another window. You should see the arguments expanded instead of */out.
Reply With Quote
The Following User Says Thank You to gordon@ For This Useful Post:
lokli (November 3rd, 2009)
  #7  
Old November 8th, 2009, 16:08
melifaro melifaro is offline
Junior Member
 
Join Date: Nov 2008
Posts: 3
Thanks: 0
Thanked 2 Times in 1 Post
Default

You can use sysutils/wait_on for monitoring directories/files.

Last edited by DutchDaemon; November 8th, 2009 at 18:48.
Reply With Quote
The Following 2 Users Say Thank You to melifaro For This Useful Post:
lokli (November 14th, 2009), MarS (June 25th, 2012)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Solved] Network monitoring tool wonslung Networking 9 December 16th, 2010 06:32
Monitoring Bandwidth atwinix Networking 4 October 14th, 2009 00:06
Free Space Monitoring Script naezdnik Userland Programming & Scripting 6 October 7th, 2009 12:14
Statistics Monitoring mikej83 General 2 August 16th, 2009 23:08
Serious network monitoring tool Mad_Dud Networking 2 April 25th, 2009 20:34


All times are GMT +1. The time now is 21:10.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0