LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Programming Linux Daemon (https://www.linuxquestions.org/questions/programming-9/programming-linux-daemon-526454/)

jvff 02-07-2007 12:49 PM

Programming Linux Daemon
 
Hi,

I am trying to code a program that runs in the background and monitors access on my local files. If an access is requested to a file that doesn't exist, it should download it from the fileserver. I assume the best approach for doing so is by coding a daemon. Are there any tutorials on the internet for doing so? From what I have read, a daemon is a normal process, but has redirected stdin, stdout and stderr file descriptors and has init as it's parent process. But I'm pretty sure there must be more to coding a daemon. Also I'm not sure if it's possible to monitor other processes file requests. Anyone know if possible and how to do it? If it's not possible, the alternative is to force the other processes to request data from the daemon (ie. rewrite the other apps, breaking compatibility with 3rd party apps). Thanks,

JVFF

wjevans_7d1@yahoo.co 02-07-2007 02:22 PM

I can't give you all the answers you need, but I can give you two of them.

=== answer one ===

If you decide to use a daemon, there are several non-obvious things you should do. They are listed here:

http://en.wikipedia.org/wiki/Daemon_(computer_software)

(Scroll down to the section "Types of daemons".)

Sample code for creating a daemon can be found here:

http://www.csfalcon.com/index.jsp?topic=UNIX%20Daemon



A discussion of mistakes to avoid when coding a daemon can be found here:

http://homepages.tesco.net/J.deBoyne...-to-avoid.html

I'm not sure whether I agree with everything they say, but it's still worth reading.

=== answer two

It's not easy to monitor other processes' open()ing of files. The best you can do is modify the code when you have the source available. The next best thing is to hope that software for which you do not have the packages uses shared libraries. Then you need to modify the open() (or maybe __open()) calls to hook up to your daemon if the file does not exist.

This is only a start. You have much more to learn; I'm glad I don't have to!

Hope this helps.


All times are GMT -5. The time now is 11:05 PM.