Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 07 Apr 1999 17:59:08 -0400
From:      "Daniel M. Eischen" <eischen@vigrid.com>
To:        davidc@colnta.acns.ab.ca
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Closing file descriptors with cc -pthread
Message-ID:  <370BD52C.C07E5170@vigrid.com>

next in thread | raw e-mail | index | archive | help
> I have been porting a threaded server from Solaris to
> FreeBSD, and I noticed that on FreeBSD the server uses
> 100% of the processor even when it is "idle".  top shows
> it climb to the top of the list and eventually take
> up 99.8% on a fairly idle system.
> 
> truss shows that the process is calling select() and
> gettimeofday() over and over...
> 
> I tracked the problem to an init_daemon() call
> (much like daemon(), only a little more complete), and
> within that I found it was a loop that closed all open
> descriptors and dup2()'d 0,1,2 -> /dev/null that was causing
> the problem.
> 
> In a seperate test I was able to duplicate the problem, but
> I am not sure what I am seeing or why.  Is this a bug, or
> am I missing something?  Also, why are descriptors 3 and 4
> open when the program starts?
> 
> If this code is compiled with 
>         cc -o testfd testfd.c 
> it will run as expected.  If it is compiled with 
>         cc -pthread -o testfd testfd.c
> then it seems to loop out of control.
> 
> If I do not close 3 and 4 the code will run normally both
> with -pthread and without.  Again, what are they for?
> 
> Not closing all open descriptors, and dup2()'ing 0,1, and 2 like
> daemon() does solves my problem, but I do not understand why.
> 
> Any information would be appreciated.

File descriptors 3 and 4 are probably for the pipe that
the uthread kernel uses when the scheduling signal occurs.
The scheduling signal handler writes to the pipe to wake
the uthread kernel up when it's blocked in select.

Since you closed the file descriptors, the uthread kernel
is probably looping continuously with select returning -1.

Don't close file descriptors 3 and 4 :-)

Dan Eischen
eischen@vigrid.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?370BD52C.C07E5170>