The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

I've got a program that I want to daemonize by i_am_pi2002-11-01 10:02:54
  Which part do you need? by Avium 2002-11-01 10:20:24
fork() is relatively simple. It returns twice. Once in the parent process and once in the child process. If it returns 0 you're in the child, >0 and you're in the parent.
if ((child_pid = fork()) > 0)
{
  /* This is the parent process.
   * child_pid contains the pid for the child. */
}
else
{
  /* This is the child process in here. */
}
As for redirecting stdin, stdout, and stderr you need to look at the dup2() function. The file descriptors for the standard input, outpu and error are:
  • stdin = 0
  • stdout = 1
  • stderr = 2
Just remember that you will have to make sure the program has some other way of receiving input, like sockets.
[ Reply ]
    well it's just a program that loops infinitely by i_am_pi2002-11-01 10:24:24
      Basically. Yes. by Avium2002-11-01 10:32:26

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)