[uClinux-dev] Daemonize a process

Stuart MacDonald stuartm at connecttech.com
Thu Mar 13 12:33:50 EST 2003


From: "Robert Daniels" <robertd at vantagecontrols.com>
> Yeah, I never submitted my "fixes" to this since what is there works.
> I'll just attach my version of smbmount.c and you can check it out.
> This version has my own version of daemonize which seems to work fine
> for smbmount, and could maybe be adapted to your use.  It is dependant
> on the /proc file system which might not be good, and it seems that it
> could use argv[0] instead of a hardcoded "/smbmount" or "smbmount".
> Since this is based on vfork, it's tough to just put it anywhere in your
> code since it runs your program again starting from the beginning,
> but... better than nothing maybe.

Nifty. I'd thought of writing the daemon as a recursive app but I'd
been thinking the stopping condition would be passed as argv[1]; the
/proc snooping is an interesting twist.

Fortunately for me the code that wants to be forked is already fairly
separated out; it's faster and easier for me to chop up the daemon
into a few smaller apps and use vfork(); execve(); instead.

..Stu





More information about the uClinux-dev mailing list