Re: read on socket shows EOF... but only when app is running in background

From: Nils Weller (me_at_privacy.net)
Date: 08/19/04


Date: 19 Aug 2004 15:07:03 GMT

In article <41244972$1@aurora.telecom.tno.nl>, Ruud Schramp wrote:
> Does anybody know other reasons a TCP Socket will read eof besides being
> closed localy or receiving a FIN packet?

No.

> My multi threaded server application doesn't work when run in the
> background.

The fact that you call fork() in a multithreaded application may be your
first problem already. Do you create your threads before calling fork()
or afterwards, and does the parent process perform any other actions
related to multithreading before it exits (such as acquiring mutexes)?

> The application is intended to run as a daemon so I want to create a
> commandline option that puts it in the background. It does work when
> run in the foreground, even when started with a "&" option, but not
> when an internal fork is used.

I recommend that you call the setsid() function after performing the
fork(). Also, the parent should exit by calling _exit(), not exit() (a
return from main() will call exit().)

But from the information you have supplied, it's hard to guess what's
wrong. This certainly does not seem like a common programming problem
to me, or at least it's not one I have experienced myself. What else
have you tried on the server side? Is the server structured in such a
way that you can constantly monitor the socket for its validity?

-- 
My real email address is ``nils<at>sipoc<dot>de''


Relevant Pages

  • Forking in windows. Possible?
    ... I know under mac/*nix it's possible to fork the proccess to the ... background and exit the parent process. ...
    (comp.lang.python)
  • Re: Perl Stops Processing
    ... the parent process waits for the child process to complete. ... The return value is the exit status of the program as returned by the wait call. ... You want to first fork and run the command in its own thread. ...
    (perl.beginners)
  • SIGBUS in exit?
    ... The fork call is successfull. ... During the exit call the parent process ...
    (comp.unix.programmer)
  • Re: RFC: implement daemon() in the kernel
    ... Except some special cases, fork() ... The child process is created and suspended, the parent continues to run ... until it calls exec() or _exit. ... You do have to look out for any applications that fork and do not either exit or exec, but that is so much better than having to modify so many things just to get them to run. ...
    (Linux-Kernel)
  • thread death callback to be called after fork
    ... t = Thread.new{sleep} ... fork{t.join; exit} and Process.wait ... definining a finalizer is one way to trigger notification of thread death on ...
    (comp.lang.ruby)