How do I daemonize a process?

Maxime Henrion mux at FreeBSD.org
Mon Jul 23 09:15:28 UTC 2007


Garrett Cooper wrote:
>    As the subject suggests I'm trying to determine how I can daemonize 
> a C process, outside of using the rc infrastructure, so that it won't 
> exit when the TTY exists. Does anyone know any quick references or examples?
> Thanks,
> -Garrett

The proper way to do this is to use the setsid() function.  If it
is somehow not available on one of your target system, some people
use a hack which consists in calling fork() two times to daemonize
the process; that is supposed to work too.

Cheers,
Maxime


More information about the freebsd-hackers mailing list