D daemon & GC?

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 31 05:51:18 PDT 2014


On Sunday, 31 August 2014 at 09:02:55 UTC, JD wrote:
>>
>> Last snippet works for me, dots get printed to the logfile as 
>> expected.
>
> Ok, it works now. Using the recommended _Exit() function with 
> DMD 2.066 on Linux.
> Thanks you all for your help!
>
> Best regards,
> Jeroen

On a side note, i've created daemons like this before but then i 
found a rather nice posix system call to do it all for me:

extern (C)
{
	/**
	 * The daemon() function is for programs wishing to detach 
themselves
	 * from the controlling terminal and run in the background as 
system
	 * daemons.
	 *
	 * (This function forks, and if the fork(2) succeeds, the parent 
calls
	 * _exit(2), so that further errors are seen by the child only.) 
  On
	 * success daemon() returns zero. If an error occurs, daemon() 
returns
	 * -1 and sets errno to any of the errors specified for the 
fork(2) and
	 * setsid(2).
	 *
	 * Params:
	 *     nochdir = If nochdir is zero, daemon() changes the 
calling process's
	 *     current working directory to the root directory ("/"); 
otherwise,
	 *     the current working directory is left unchanged.
	 *     noclose = If noclose is zero, daemon() redirects standard 
input,
	 *     standard output and standard error to /dev/null; 
otherwise, no
	 *     changes are made to these file descriptors.
	 */
	int daemon(int nochdir, int noclose);
}

This is a lot easier to use. :)


More information about the Digitalmars-d-learn mailing list