Creating a Linux Daemon

michael scott frank msfrank at u.washington.edu
Sat Dec 8 00:45:29 PST 2001



Heres my two cents, take it for what its worth since i don't know your
exact situation. I'm assuming that all requests to the server are gonna
be local, and the data is easily passed through a socket, so i would use
unix domain sockets. domain sockets are fairly straightforward (if you
are familiar with sockets or even just normal file i/o with read() and
write(), then you'll be at home) and they are pretty fast too (x window
system uses domain sockets). domain sockets have the same basic semantics
of normal INET sockets, the only real difference is the server creates a
file of type socket somewhere in the fs (usually in /tmp), and the client
'opens' this file. This is kind of a poor description, but i hope it
helps.

As for reading material, already mentioned was advanced programming in the
unix environment by WRS, which i heartily recommend too. Unix Network
Programming Vol. 1, also by WRS, is another bible. APUE has a brief
mention of domain sockets, UNPv1 has a whole chapter devoted to it.

hope that all helps. feel free to email me off-list if you wanna talk
more about details.

good luck,

Michael


------------------------- .~.
Michael Frank /v\
msfrank at u.washington.edu // \\
------------------------ /( )\
^`~'^

On Fri, 7 Dec 2001, John Porter Simons wrote:


> Hello Linxuers,

> (Sorry if this got posted twice, not sure if I was successfully subscribed

> to the list the first time...)

>

> I've got a question that maybe someone could help me with. Say I've got a

> simple C program that takes some data, processes it, and returns a result.

> And I want to use this program in a server-side web script, but I don't

> want to instantiate the program everytime it's needed, because it

> maintains large data structures and it may be executed frequently. What I

> want to do is load the program on startup like a daemon, and have it stay

> in memory. The processing it does is pretty simple, so I don't think it

> needs to fork worker threads, it could have a single process which loops

> through any requests.

>

> But I have no idea how to do this. I wouldn't know whether to use pipes or

> FIFOs or signals or what... Does anyone know of a good book or web

> resource that provides an example of how to do this? I'm guessing that on

> startup, the program would write its process ID to a file somewhere, but I

> don't know how, from PHP for example, I could send data to the process at

> that ID, and how the program would know where to send the result.

>

> Any help would be appreciated...

>

> Thanks,

>

> John Simons

> sport at cs.washington.edu

>

>

>




More information about the Linux mailing list