[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: server problem
Peter Peres <plp@actcom.co.il> writes:
>
> Hello,
>
> I have a small programming question:
>
> I have a server written in C that is supposed to run on linux and on a
> sun. It is a normal forking server. Everything works ok but:
>
> On Linux 1.2.13 the forking (fork() call) does not always start a child. I
> do not understand why this is so. The Sun behaves itself.
>
> Since every time a connection arrives the server forks, and there is no
> child to handle the connection, an unserviced connection (socket) appears in
> the netstat output. The socket appears as state TIME_WAIT. The number of
> sockets created in this way grows to 24 after which they all close. No
> errors occur. I have extensive logging turned on and in the (simplified)
> server code:
>
> while(keep_forking)
> {
> get_connection()
>
> switch(fork())
> {
> case 0: /* child */
> log_this1()
> exit
>
> case -1: /* die */
> die()
>
> default: /* father */
> log_this2();
> }
> }
>
> log_this2() gets called after every fork() but log_this1() only the first,
> the third, fourth ... (n+1)th call. Now this is weird. I have tried various
> things and the problem might be in the kernel. httpd running on the same
> machine runs ok when from inetd but has the same problem when run
> standalone. There are no errors, just a netstat table full of TIME_WAIT
> sockets.
>
> I would appreciate any help or ideas,
> TIA, Peter (plp@actcom.co.il)
>
> Here I append an extempt from the log:
>
> NOTES:
What about your log_*() routines. You sure you don't have I/O race
conditions, CLOSE_ON_EXEC descriptors or whatever? You'd better open a
special file in each child (using tmpnam()) and write info to it.
--
-Alexander
==============================================================================
Alexander L. Belikoff abel@bfr.co.il
Berger Financial Research Ltd.
=============================================================================
References: