LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-05-2005, 04:04 AM   #1
rajsun
Member
 
Registered: Mar 2005
Posts: 61

Rep: Reputation: 15
Daemon Server Programming.... HELP


Hi all,
Do any body has any idea how to write code for DAEMON SERVER.. N what is the diffrence between DEAMON and PROCESS...?
If any body knows some link in net then plz let me know .... so that
i can go for DEAMON SERVER programming....

Thanking u.....

With Regard
Rajesh.
 
Old 04-05-2005, 04:26 AM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
a daemon is a process that has init (the father of all processes) as direct father . So it runs in the background and is not attouched to a terminal. Most servers are daemons, they don't use a terminal.

when you execute a program from a console, look at how the "family tree" goes

init ------> console ------->your_program.
what you want is this:
init------->your program.
So what you need is your program to have the init as father and not the console.
How do you archive this. Simple. Your program should doublicate itself (create a child):
init------->console-------->your_program------->your_program
And then the father should kill himself. The child will remain orphan and his new father will be init
you duplicate a program with fork system call.
Code:
man fork
for more info.

If you write in C, in main() after you declare the variables, put this:
Code:
if ( fork())
{
     exit(0);
}
fork will duplicate the the program, and only the father will enter in the body of if, because fork returns the pid of the child to the father > 0 and 0 to the child.
If you do this, when you execute the program, the prompt in the console will be regained immediately and the program will run in the background.

Last edited by perfect_circle; 04-05-2005 at 04:30 AM.
 
Old 04-05-2005, 04:28 AM   #3
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
****Soory , wrong edit****************

Last edited by perfect_circle; 04-05-2005 at 04:30 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Daemon programming.... Help rajsun Programming 7 02-02-2006 12:23 AM
Daemon programming..... rajsun Programming 11 07-01-2005 07:12 AM
Can't get DigiChat Server to start as a daemon hydra_76 Linux - Newbie 1 01-01-2004 05:47 PM
Dedicated server running as a daemon? Guitarzan Linux - General 1 02-09-2003 01:07 AM
start server as a daemon champ Programming 5 01-27-2003 06:40 PM


All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration