Jump to page: 1 2
Thread overview
Daemon app in D
Jun 07, 2005
Geert
Jun 07, 2005
Dejan Lekic
Jun 07, 2005
Geert
Jun 07, 2005
James Dunne
Jun 07, 2005
Geert
Jun 07, 2005
Dejan Lekic
Jun 07, 2005
Geert
Jun 07, 2005
SeeSchloss
Jun 07, 2005
SeeSchloss
Jun 07, 2005
Geert
Jun 07, 2005
SeeSchloss
Jun 07, 2005
Dejan Lekic
Jun 07, 2005
James Dunne
Jun 08, 2005
James Dunne
Jun 08, 2005
Geert
June 07, 2005
Is it possible to create a (linux) daemon in D? And if; how?

Thnx
June 07, 2005
Read samples in DMD distribution - there is one example there I think.

-- 
...........
Dejan Lekic
  http://dejan.lekic.org

June 07, 2005
No, it is a windows server or something..
I need a real daemon that disconnects from the shell.

Dejan Lekic wrote:
> Read samples in DMD distribution - there is one example there I think.
> 
June 07, 2005
In article <d840t0$2881$1@digitaldaemon.com>, Geert says...
>
>No, it is a windows server or something..
>I need a real daemon that disconnects from the shell.
>
>Dejan Lekic wrote:
>> Read samples in DMD distribution - there is one example there I think.
>> 

I've done this before, and it needs to be done with linux system calls.  There's no real nice D way to do it.  I can't dig up an example of mine for you right now, but I'll get one for you later.

Regards,
James Dunne
June 07, 2005
Thanks, that would be great...

James Dunne wrote:
> In article <d840t0$2881$1@digitaldaemon.com>, Geert says...
> 
>>No, it is a windows server or something..
>>I need a real daemon that disconnects from the shell.
>>
>>Dejan Lekic wrote:
>>
>>>Read samples in DMD distribution - there is one example there I think.
>>>
> 
> 
> I've done this before, and it needs to be done with linux system calls.  There's
> no real nice D way to do it.  I can't dig up an example of mine for you right
> now, but I'll get one for you later.
> 
> Regards,
> James Dunne
June 07, 2005
So you cannot write an simple D application that reads stdin, writes to stdout, uses inetd and you run it via "myprog [params] &" ?

-- 
...........
Dejan Lekic
  http://dejan.lekic.org

June 07, 2005
It doesn't really detach the app from the shell.. Try for instance typing Ctrl-Z and then fg, it will bring back the app to the foreground.

Dejan Lekic wrote:
> So you cannot write an simple D application that reads stdin, writes to
> stdout, uses inetd and you run it via "myprog [params] &" ?
> 
June 07, 2005
On Tue, 07 Jun 2005 12:56:22 +0200, Geert wrote:

> Is it possible to create a (linux) daemon in D? And if; how?
> 
> Thnx

An

extern (C) fork ();

somewhere, and then

if (fork ()) exit (0);

at the place you want your daemon to daemonize should be enough (since the point is that processes of which the parents are dead are adopted by init, and therefore become deamons).

That's what my server uses, and that's the standard way to do it afaict.


SeeSchloss.
June 07, 2005
On Tue, 07 Jun 2005 18:42:36 +0200, SeeSchloss wrote:

> extern (C) fork ();

or rather "extern (C) int fork ();", sorry
June 07, 2005
Thanks, but the program will continue to be connected to the shell try this for instance:

extern (C) int fork ();
void main()
{
	// fork returns -1 on failure
	// 0 to childprocess, and the pid
	// number of the child process to the parent
	if(fork()) exit(0);

	while(1)
		printf("You will see this output.\n");
}

SeeSchloss wrote:
> On Tue, 07 Jun 2005 18:42:36 +0200, SeeSchloss wrote:
> 
> 
>>extern (C) fork ();
> 
> 
> or rather "extern (C) int fork ();", sorry
« First   ‹ Prev
1 2