[uClinux-dev] Daemonize a process

Robert Daniels robertd at vantagecontrols.com
Wed Mar 12 18:44:25 EST 2003


You might want to check the code for smbmount for an example of an
application that does the daemonize thing.  It's under
user/samba/source/client/smbmount.c.  It was modified to not call its
own daemonize function and instead, it will go into a loop where it will
kill its parent (most likely your shell) and keep running.  It's a
little annoying if you do this from a telnet session, but if you do it
from the default console, it just restarts the main shell.  I don't know
if this will work in your situation or not.  I modified this code to use
a goofy version of daemonize in which I use vfork and execv to spawn off
a daemon process.  The trick here is to make sure you don't recursively
daemonize, which I accomplished by snooping the /proc filesystem.

Robert

-----Original Message-----
From: uclinux-dev-admin at uclinux.org
[mailto:uclinux-dev-admin at uclinux.org] On Behalf Of David McCullough
Sent: Wednesday, March 12, 2003 4:02 PM
To: uclinux-dev at uclinux.org
Subject: Re: [uClinux-dev] Daemonize a process


Jivin Stuart MacDonald lays it down ...
> The classic sequence of:
> 
> fork();
> setsid();
> fork();
> 
> doesn't work in uClinux because vfork blocks the parent until an _exit
> or execve().
> 
> What I end up with is two D state processes (zombies) and the final
> child still parented by its real parent instead of init.
> 
> I've checked a number of /user apps, but haven't found one that wants
> to do the same thing, so no example code to follow.


There are a couple of ways to achieve this:

* have init start your daemon

* have your daemon exec itself with a special option to become a daemon.


> Am I missing a simple solution, or is this just not possible until
> uClinux gets fork()? If so, what's required to get fork working? The
> comment in arch/m68knommu/kernel/process.c states that it almost
> works, but doesn't specify which bit is failing.

fork on uClinux is not possible.  It gives a short term impression of
working, before your system dies horribly.  It cannot be fixed in any
practical way and you can find all the reasons why in the uClinux-dev
archives :-)

Cheers,
Davidm

-- 
David McCullough:    Ph: +61 7 3435 2815  http://www.SnapGear.com
davidm at snapgear.com  Fx: +61 7 3891 3630  Custom Embedded Solutions +
Security
_______________________________________________
uClinux-dev mailing list
uClinux-dev at uclinux.org
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by uclinux-dev at uclinux.org




More information about the uClinux-dev mailing list