How to write a daemon program to monitor symbolic links?

Falcolas garrickp at gmail.com
Fri Oct 23 15:43:07 EDT 2009


On Oct 23, 1:38 pm, Falcolas <garri... at gmail.com> wrote:
> On Oct 23, 1:25 pm, Peng Yu <pengyu... at gmail.com> wrote:
>
>
>
> > As far as I know, linux doesn't support a system level way to figure
> > out all the symbolic links point to a give file. I could do a system
> > wide search to look for any symbolic link that point to the file that
> > I am interested in. But this will be too slow when there are many
> > files in the systems.
>
> > I'm thinking of writing a daemon program which will build a database
> > on all the symbolic links that point to any files. Later on, whenever
> > I change or remove any file or symbolic link, I'll will notify the
> > daemon process the changes. By keeping this daemon process running, I
> > can quickly figure out what symbolic links are pointing to any give
> > file.
>
> > But I have never make a daemon program like this in python. Could
> > somebody point me what packages I need in order to make a daemon
> > process like this? Thank you!
>
> I would recommend looking into some articles on creating well behaved
> daemons and review python recipes for creating daemonic processes.
> From there, it's mostly a matter of writing code which is fairly self
> reliant. The ability to write to the system logs (Python module
> syslog) helps quite a bit.
>
> http://www.google.com/search?q=writing+daemonshttp://code.activestate.com/recipes/278731/
>
> I typically write a program which will run from the command line well,
> then add a switch to make it a daemon. That way, you have direct
> control over it while writing the daemon, but can then daemonize it
> (using the activestate recipe) without making changes to the code.
>
> Garrick

One other note - sorry for the double post - if you look at other
programs which maintain a DB of files, such as unix' slocate program,
update the DB as a daily cron job. You may want to also consider this
route.

Garrick



More information about the Python-list mailing list