![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to write a daemon in Unix? | sbasak | Shell Programming and Scripting | 11 | 04-23-2008 02:56 AM |
| Daemon 101 | Miller_K | Shell Programming and Scripting | 3 | 05-17-2007 05:53 PM |
| Daemon | santosh123 | High Level Programming | 2 | 02-19-2007 04:42 AM |
| log daemon | Esaia | High Level Programming | 0 | 09-11-2002 01:15 PM |
| daemon | bat_oyu | High Level Programming | 1 | 10-16-2001 07:57 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi ,
I want to know how to write a daemon process. I also want to know the concept behind daemon processes. Any material or sample program will be great Thanks in advance -sg |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
These links should get you started - Unix Daemon Server Programming and this - Linux Daemon Writing HOWTO
vino |
|
#3
|
||||
|
||||
|
I guess that either technique presented in those links is good enough, but I have to say that there is some room for improvement. Both of these techniques are relying on the parent to not make strange mistakes prior to invoking the daemon. We can do a better job of protecting ourself from a insane or hostile parent. By using two forks separated by a setsid() we can create a process that is guaranteed to not have a controlling terminal or even have the ability to accidentally acquire one. I kinda like the idea of closing all possible fd's, but using gettablesize sabotages the idea. gettablesize is basicly a getrlimit(RLIMIT_NOFILE) and is returning the soft limit. You can open a file and then set the soft limit lower...the file won't close or anything. And if the total number of open file is low, you can still open new files. Using sysconf() can avoid that.
Here is a link that gets all of this right 1.7 How do I get my program to act like a daemon? This link is from the Usenet comp.unix.programmer FAQ. From the same FAQ, also see Daemon utility functions. In fact, see the entire FAQ. The whole thing is excellent, despite being a little dated. |
||||
| Google The UNIX and Linux Forums |