The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 11-17-2005
Registered User
 

Join Date: Sep 2005
Posts: 3
Smile How to write daemon?

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
Reply With Quote
Forum Sponsor
  #2  
Old 11-17-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
These links should get you started - Unix Daemon Server Programming and this - Linux Daemon Writing HOWTO

vino
Reply With Quote
  #3  
Old 11-17-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,616
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

« Vi editor | adduser »
Thread Tools
Display Modes




All times are GMT -7. The time now is 06:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0