* daemons
@ 2004-02-15 4:14 ameer armaly
2004-02-15 7:55 ` daemons Glynn Clements
2004-02-15 10:06 ` daemons Alphex K.
0 siblings, 2 replies; 3+ messages in thread
From: ameer armaly @ 2004-02-15 4:14 UTC (permalink / raw)
To: linux-c-programming
Hi all.
What do I need to do to have a program invoke as a daemon; i.e sit and ait
for a particular event to happen, and then do something, all in the
background?
Thanks,
Ameer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: daemons
2004-02-15 4:14 daemons ameer armaly
@ 2004-02-15 7:55 ` Glynn Clements
2004-02-15 10:06 ` daemons Alphex K.
1 sibling, 0 replies; 3+ messages in thread
From: Glynn Clements @ 2004-02-15 7:55 UTC (permalink / raw)
To: ameer armaly; +Cc: linux-c-programming
ameer armaly wrote:
> What do I need to do to have a program invoke as a daemon; i.e sit and ait
> for a particular event to happen, and then do something, all in the
> background?
The topic of daemon processes gets its own chapter in Stevens[1], but
the short version is:
1. Call fork(), and have the parent exit.
2. Call setsid() to create a new session and disconnect from the
controlling terminal.
3. Call chdir() to change the current directory to the daemon's
working directory, or the root directory if it doesn't have one.
4. Call umask(0) to reset the file permissions mask.
5. Close all unused file descriptors.
[1] Advanced Programming in the Unix(R) Environment
W Richard Stevens
Addison-Wesley
Depending upon what the daemon does, other useful steps may include:
6. Reset the environment to a fixed set of values.
7. Set up descriptors 0, 1 and 2 (use /dev/null if nothing else is
appropriate).
8. Reset other aspects of the process' environment which will have
been inherited, e.g. resource limits.
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: daemons
2004-02-15 4:14 daemons ameer armaly
2004-02-15 7:55 ` daemons Glynn Clements
@ 2004-02-15 10:06 ` Alphex K.
1 sibling, 0 replies; 3+ messages in thread
From: Alphex K. @ 2004-02-15 10:06 UTC (permalink / raw)
To: ameer armaly; +Cc: linux-c-programming
On Sat, 14 Feb 2004 23:14:45 -0500 (EST)
ameer armaly <ameer@charter.net> wrote:
So, You can do it =)
You must call the fork(),close all enviroment and so all =)
some like this
//closing the enviroment
int pid;
if((pid=fork())==0)
{
for(;;)
{
// something useful
}
}
so, it's all
---===---
Alphex Kaanoken
Senior developer of Crew IT research labs
web: http://crew.org.ru
mailto:Alphex@Crew.Org.RU
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-02-15 10:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-15 4:14 daemons ameer armaly
2004-02-15 7:55 ` daemons Glynn Clements
2004-02-15 10:06 ` daemons Alphex K.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).