Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
File Hooks - possible ?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
SouthOfHeaven
Tux's lil' helper
Tux's lil' helper


Joined: 05 Apr 2003
Posts: 128

PostPosted: Wed Feb 16, 2005 2:03 am    Post subject: File Hooks - possible ? Reply with quote

I am just curious if its possible to make a program (c/c++ whatever language) to "listen" to a specific file on the system. So if someone does "ls" and the file is listed the hook would be triggered, or if the file is edited opened etc.

Any information would be appreciated.
Back to top
View user's profile Send private message
lookinin
Guru
Guru


Joined: 21 Jan 2005
Posts: 486

PostPosted: Wed Feb 16, 2005 2:10 am    Post subject: Reply with quote

I think what you want is a named pipe, then you can read that file just as you would any other file:

Code:
# mkfifo mypipe
# ls -l > mypipe
(leave it running, and from another prompt)
# cat mypipe


My example works in Bash, I'm sure you could do something similar easily in C.
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9521
Location: beyond the rim

PostPosted: Wed Feb 16, 2005 2:32 am    Post subject: Reply with quote

I think fam/inotify/dnotify is what you want.
Back to top
View user's profile Send private message
lookinin
Guru
Guru


Joined: 21 Jan 2005
Posts: 486

PostPosted: Wed Feb 16, 2005 4:35 am    Post subject: Reply with quote

On second glance, I see that you're right, Genone. I misread (as usual), and thought he wanted to send the output of `ls` to a file, but I see now that he wanted it to trigger when someone actually ls'd the file itself.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum