[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Daemon Programming

Hans-Georg Bork:   I have already tried the S99my_serverd change, but
it doesnt work.

J.A. Bezemer: I have tried the ./yourprog </dev/null >/dev/null
2>/dev/null  and the program dies, I cant see with a ps ax

Clare Jarvis: The program should listen to a port, and a client
program will send a string, and this string will be used by an
external program. The program is made in C.

Here is the code: http://rafb.net/paste/results/vkgCRD46.html

and here too: http://mezcal.fi-p.unam.mx/~sergio/programas/say_serverd.c

The daemonize function is from a tutorial of how to make a daemon. 
(http://www.enderunix.org/docs/eng/daemon.php )

Thanks for your help


Sergio Cuéllar Valdés

On Thu, 13 Jan 2005 19:08:27 -0600 (CST), Clare Jarvis
<jarvis@jarviscomputer.com> wrote:
> You have not describe the "real action", nor told us the language
> you are using.
> to have a successfull daemon you have to fork() twice.   Once to
> disassociate your program from the terminial and another to disassociate
> from the process group.   I suspect that you are doing this okay.
> To act as a "server" when monitoring a port you must
> bindi() the port
> ithe do a listen()
> enter a loop that does the
> select()
> tests to see if it is a connection request.   If so the accept the
> connection
> tests to see if data is coming from a connected client and if so
> then take "real action"   remember that you might have to fflush()
> continue the loop
> Does you program fork() to do its real action?
> Thats about all for now.
> Sincerely,
> Clare Jarvis
> > Hi,
> > I hope you can help me. I have made a program that will be listening
> > to a port. I want to start the program every time the machine boots,
> > so I created the script to use in init.d and Ive also created the
> > symlinks.
> >
> > The machine boots, and the programs starts. I use ps ax and I can see
> > that the program is running, I use netstat -an, and I can see the port
> > is open. When I use a client program, the server doesnt answer. I use
> > strace -p  <PID_of_SERVER>, and I see that the server is receiving the
> > data, the program also saves the data in a log file. But the real
> > action is not performed.
> >
> > If I restart the program by hand, /etc/init.d/my_serverd restart, and
> > I use again the client program, the server works fine. I really dont
> > have any idea, what´s happening.
> >
> >
> > Does anyone have any idea why this would occur?
> >
> > Thanks,
> >
> > Sergio Cuéllar Valdés
> >
> > --
> > "Meine Hoffnung soll mich leiten
> > Durch die Tage ohne Dich
> > Und die Liebe soll mich tragen
> > Wenn der Schmerz die Hoffnung bricht"
> >
> >
> Clare Jarvis
> President, Jarvis Computer Software
> PO Box 1264
> Winona MN 55987
> (507) 454 2575

"Meine Hoffnung soll mich leiten
Durch die Tage ohne Dich
Und die Liebe soll mich tragen
Wenn der Schmerz die Hoffnung bricht"

Reply to: